// This may look like C code, but it is really -*- C++ -*-

//
//  monopoly-template  --  Copyright (c) University of Aizu 1994
//
// [# Edit, Date, User, Module #]
#include <stream.h>
#include <Key.h>
#include <malloc.h>

void testKey()
{
  cerr << "Testing Key and memory leaks\n";
  struct mallinfo mem;
  int all, max = 0;

  for (int i = 0; i < 10; i++) {
    cerr << "Pass Nr. " << i << "\n";
    {
      Key* a = new Key;
      a->read();
      Key* b = new Key(*a);
      b->write();
      mem = mallinfo();
      cerr << " copy b from a " << mem.allocated << "\n";
      a->read();
      cout << "a == b ? " << (*a == *b ? "yes\n" : "no\n");
      *b = *a;
      b->write();
      mem = mallinfo();
      cerr << " assignment b=a " << mem.allocated << "\n";
      delete a;
      delete b;
      cerr << " deleted a and b...\n";
    }
    mem = mallinfo();
    cerr << " End of Loop : " << all << "\n";
    all = mem.allocated;
    if (max > 0 && max != all) cout << "MEMORY LEAK!!\n";
    max = all;
  }
}


// End of file
