int main()
{
  // print my name and this assignment's title 
  cout << "LAB 6a: Write A Linked Array Class Template\n"; 
  cout << "Programmer: Jacky Chow\n"; 
  cout << "Editor(s) used: Notepad++\n"; 
  cout << "Compiler(s) used: Visual C++\n"; 
  cout << "File: " << __FILE__ << endl; 
  cout << "Complied: " << __DATE__ << " at " << __TIME__ << endl << endl;
  
  vector<int> k;
  LinkedArray<int> a;

  //Test capacity() and size()
  cout << "Capacity of a should be 10\nCapacity returns " << a.capacity() << endl;
  assert(10 == a.capacity());
  cout << "Size should be 0\nSize returns " << a.size() << endl; 
  assert(0 == a.size());

  //Test kes()  
  k = a.keys();
  int ksize = k.size();
  cout << "Keys of a in use: ";
  for(int i = 0; i < ksize; i++)
    cout << k[i] << " ";
  cout << endl << endl;  

  //Test operator[] setter and getter
  a[3] = 7;
  cout << "a[3] was set to 7\na[3] is returns " << a[3] << endl;
  assert(7 == a[3]);
  cout << "Size should be 1\nSize returns " << a.size() << endl; 
  assert(1 == a.size());  
  k = a.keys();
  cout << "Keys of a in use: ";
  ksize = k.size();
  for(int i = 0; i < ksize; i++)
    cout << k[i] << " ";
  cout << endl << endl; 

  a[5] = 20;
  cout << "a[5] was set to 20\na[5] is returns " << a[5] << endl;
  assert(20 == a[5]);
  a[7] = 15;
  cout << "a[7] was set to 15\na[7] is returns " << a[7] << endl;
  assert(15 == a[7]);
  a[9] = 3;
  cout << "a[9] was set to 3\na[9] is returns " << a[9] << endl;
  assert(3 == a[9]);  
  k = a.keys();
  cout << "Keys of a in use: ";
  ksize = k.size();
  for(int i = 0; i < ksize; i++)
    cout << k[i] << " ";
  cout << endl << endl; 

  //Test containsKey()
  cout << "\nKey 1 is currently not in use.\n";
  if(a.containsKey(1)) cout << "Error, a[1] is not is use\n";
  else 
    cout << "containsKey() on a[1] returned a false\n";
  assert(!(a.containsKey(1)));

  a[1] = 8;
  cout << "a[1] was set to 8\na[1] is returns " << a[1] << endl;
  assert(8 == a[1]);
  cout << "Key 1 is now in use.\n";
  cout << "Size should be 5\nSize returns " << a.size() << endl; 
  assert(5 == a.size());

  if(a.containsKey(1)) cout << "containsKey() on a[1] now returns true\n";
  else 
    cout << "Error! a[1] did not return a true\n";
  assert(a.containsKey(1));
  k = a.keys();
  cout << "Keys of a in use: ";
  ksize = k.size();
  for(int i = 0; i < ksize; i++)
    cout << k[i] << " ";
  cout << endl << endl; 

  //Test deleteKey()
  a.deleteKey(1);
  cout << "a[1] was deleted\n";
  cout << "Key 1 is again not in use.\n";
  if(a.containsKey(1)) cout << "Error, a[1] is not is use\n";
  else 
    cout << "a[1] returned a false\n";
  k = a.keys();
  cout << "Keys of a in use: ";
  ksize = k.size();
  for(int i = 0; i < ksize; i++)
    cout << k[i] << " ";
  cout << endl << endl; 
  cout << "Size should be 4\nSize returns " << a.size() << endl; 
  assert(4 == a.size());

  //Cout values in current inUse keys 
  ksize = k.size();  
  for(int i = 0; i < ksize; i++)
  {
    cout << "a[" << k[i] << "] = " << a[k[i]] << endl;
  }
  
  cout << "Testing incresing capacity of dynamic array\n";
  cout << "Adding value 13 to index position 14 in a\n\n";
  a[14] = 13;  
  k = a.keys();
  cout << "Keys of a in use: ";
  ksize = k.size();
  for(int i = 0; i < ksize; i++)
    cout << k[i] << " ";
  cout << endl << endl; 

  //Cout values in current inUse keys  
  ksize = k.size();  
  for(int i = 0; i < ksize; i++)
  {
    cout << "a[" << k[i] << "] = " << a[k[i]] << endl;
  }
  cout << "Size of a should now be 5.\nIt returns " << a.size() << endl;
  assert(5 == a.size());
  cout << "Capacity of a should now be 15.\nIt returns " << a.capacity() << endl;
  assert(15 == a.capacity());

  // object copy testing
  {
    const LinkedArray<int> copy = a; // a read-only copy
    cout << endl;
    k = copy.keys();
    ksize = k.size();
    for(int i = 0; i < ksize; i++)
    {
      cout << "copy1[" << k[i] << "] = " << copy[k[i]] << endl;
    }
    cout << endl;
    int copySize = copy.capacity();
    for (int i = 0; i < copySize; i++)
      cout << "copy1[" << i << "] = " << copy[i] << endl;
    cout << "Keys of a in use: ";
    ksize = k.size();
    for(int i = 0; i < ksize; i++)
      cout << k[i] << " ";
    cout << endl << endl; 
  }

  // object assignment testing
  {
    cout << endl;
    LinkedArray<int> copy(20); 
    cout << "Copy 2 should be capacity 20.\nIt returns " << copy.capacity() << endl;
    assert(20 == copy.capacity());
    cout << "Copying a to copy 2 should set capacity to 15\n";
    copy = a;
    cout << "It returns " << copy.capacity() << endl;
    assert(15 == copy.capacity());
    k = copy.keys();
    ksize = k.size();
    for(int i = 0; i < ksize; i++)
    {
      cout << "copy2[" << k[i] << "] = " << copy[k[i]] << endl;
    }
    cout << endl;
    int copySize = copy.capacity();
    for (int i = 0; i < copySize; i++)
      cout << "copy2[" << i << "] = " << copy[i] << endl;
    cout << "Keys of a in use: ";
    ksize = k.size();
    for(int i = 0; i < ksize; i++)
      cout << k[i] << " ";
    cout << endl << endl; 
  }  
  
  //Test clear()
  cout << "\nTestting clear() on a." << endl;
  a.clear();
  k = a.keys();
  cout << "Keys of a in use: ";
  ksize = k.size();
  for(int i = 0; i < ksize; i++)
    cout << k[i] << " ";
  cout << endl;   
  cout << "Size should be 0\nSize returns " << a.size() << endl; 
  assert(0 == a.size());
}
int main()
{
  // print my name and this assignment's title
  cout << "Lab 6a, The \"Write A Linked Array Class Template\" Program \n";
  cout << "Programmer: Licong Wang\n";
  cout << "Editor(s) used: Visual studio 2013\n";
  cout << "Compiler(s) used:  Microsoft c++ complier\n";
  cout << "File: " << __FILE__ << endl;
  cout << "Complied: " << __DATE__ << " at " << __TIME__ << endl << endl;

  cout << "Object a Testing, using default initial capacity, 0" << endl;
  LinkedArray<int> a;

  cout << "\nTest capacity and size" << endl;
  cout << "The expected capacity is 0, the acutal capacity is " << a.capacity() << endl;
  assert(a.capacity() == 0);
  cout << "The expected size is 0, the acutal size is " << a.size() << endl;
  assert(a.size() == 0);

  cout << "\nTest square bracket operator" << endl;
  cout << "assign values to first 10 elements, squared its index" << endl;
  for (int i = 0; i < 10; i++)
  {
    a[i] = i * i;
  }
  cout << "The values are" << endl;

  for (int i = 0; i < 10; i++)
  {
    cout << "expecting a[" << i << "] = " << i * i;
    cout << "  actual value: a[" << i << "] = " << a[i] << endl;
   // assert(a[i] == i * i);
  }

  cout << "\nTest capacity and size" << endl;
  cout << "The expected capacity is 10, the acutal capacity is " << a.capacity() << endl;
  assert(a.capacity() == 10);
  cout << "The expected size is 10, the acutal size is " << a.size() << endl;
  assert(a.size() == 10);

  cout << "\nTest delete" << endl;
  a.deleteKey(3);
  cout << "delete index 3, expect it to not be used" << endl;

  if (a.containsKey(3))
    cout << "Index 3 : used" << endl;
  else
    cout << "Index 3: not used" << endl;
  assert(!(a.containsKey(3)));

  cout << "\nTest the keys vector" << endl;
  cout << "expecting 0-2, 4-9 to be inused indexes, since 3 is already deleted" << endl;
  cout << "The acutal inused index and their values are:" << endl;
  vector<int> keys = a.keys();

  for (int i = 0; i < keys.size(); i++)
    cout << "a[" << keys[i] << "] = " << a[keys[i]] << endl;

  cout << "\nTest the size and capacity again" << endl;
  cout << "The expected capacity is 10, the acutal capacity is " << a.capacity() << endl;
  assert(a.capacity() == 10);
  cout << "The expected size is 9, the acutal size is " << a.size() << endl;
  assert(a.size() == 9);

  {
    cout << "\nObject Copy Testing" << endl;
    const LinkedArray<int> copy = a;

    cout << "\ncheck if their inUse results match, by checking containsKey" << endl;
    for (int i = 0; i < copy.capacity(); i++)
      assert(a.containsKey(i) == copy.containsKey(i));
    cout << "Their inUse conditions match" << endl;

    cout << "\ncheck if their key vectors match" << endl;
    vector<int> copykeys = copy.keys();

    cout << "inUsed Index: object a: ";
    for (int i = 0; i < keys.size(); i++)
    {
      cout << keys[i] << ", ";
    }

    cout << "\ninUsed Index: object copy: ";
    for (int i = 0; i < copykeys.size(); i++)
    {
      cout << copykeys[i] << ", ";
      assert(keys[i] == copykeys[i]);
    }

    if (keys == copykeys)
    {
      cout << "\nthe two vectors are are equal" << endl;

      cout << "\nthen check if their values match" << endl;
      for (int i = 0; i < copykeys.size(); i++)
        assert(a[copykeys[i]] == copy[copykeys[i]]);
      cout << "Their values match" << endl;
    }
    else
      cout << "the two vectors are not are equal" << endl;
    assert(keys == copykeys);

    cout << "\ncheck if their capacities match" << endl;
    cout << "Object a: " << a.capacity() << "  Object copy: " << copy.capacity() << endl;
    if (a.capacity() == copy.capacity())
      cout << "their capacities are equal" << endl;
    else
      cout << "their capacities are not equal" << endl;
    assert(a.capacity() == copy.capacity());

    cout << "\ncheck if their sizes match" << endl;
    cout << "Object a: " << a.size() << "  Object copy: " << copy.size() << endl;
    if (a.size() == copy.size())
      cout << "their sizes are equal" << endl;
    else
      cout << "their sizes are not equal" << endl;
    assert(a.size() == copy.size());
  }

  {
    cout << "\nObject Assignment Testing" << endl;
    LinkedArray<int> copy; copy = a;

    cout << "\ncheck if their inUse results match, by checking containsKey" << endl;
    for (int i = 0; i < copy.capacity(); i++)
      assert(a.containsKey(i) == copy.containsKey(i));
    cout << "Their inUse conditions match" << endl;

    cout << "\ncheck if their key vectors match" << endl;
    vector<int> copykeys = copy.keys();

    cout << "inUsed Index: object a: ";
    for (int i = 0; i < keys.size(); i++)
    {
      cout << keys[i] << ", ";
    }

    cout << "\ninUsed Index: object copy: ";
    for (int i = 0; i < copykeys.size(); i++)
    {
      cout << copykeys[i] << ", ";
      assert(keys[i] == copykeys[i]);
    }

    if (keys == copykeys)
    {
      cout << "\nthe two vectors are are equal" << endl;

      cout << "\nthen check if their values match" << endl;
      for (int i = 0; i < copykeys.size(); i++)
        assert(a[copykeys[i]] == copy[copykeys[i]]);
      cout << "Their values match" << endl;
    }
    else
      cout << "the two vectors are not are equal" << endl;
    assert(keys == copykeys);

    cout << "\ncheck if their capacities match" << endl;
    cout << "Object a: " << a.capacity() << "  Object copy: " << copy.capacity() << endl;
    if (a.capacity() == copy.capacity())
      cout << "their capacities are equal" << endl;
    else
      cout << "their capacities are not equal" << endl;
    assert(a.capacity() == copy.capacity());

    cout << "\ncheck if their sizes match" << endl;
    cout << "Object a: " << a.size() << "  Object copy: " << copy.size() << endl;
    if (a.size() == copy.size())
      cout << "their sizes are equal" << endl;
    else
      cout << "their sizes are not equal" << endl;
    assert(a.size() == copy.size());
  }

  cout << "\nBack to object a, Test its expandability, a[200] and a[-10]" << endl;
  a[200] = 200;
  a[-10] = -10;

  cout << "\nTest the size and capacity again" << endl;
  cout << "The expected capacity is 201, the acutal capacity is " << a.capacity() << endl;
  assert(a.capacity() == 201);
  cout << "The expected size is 10, the acutal size is " << a.size() << endl;
  assert(a.size() == 10);

  cout << "\nclear the object a" << endl;
  a.clear();

  cout << "\nTest the size and capacity again" << endl;
  cout << "The expected capacity is 201, the acutal capacity is " << a.capacity() << endl;
  assert(a.capacity() == 201);
  cout << "The expected size is 0, the acutal size is " << a.size() << endl;
  assert(a.size() == 0);

  cout << "\nObject b Testing, set its initial capacity to 15" << endl;
  LinkedArray<int> b(15);

  cout << "\nTest capacity and size" << endl;
  cout << "The expected capacity is 15, the acutal capacity is " << b.capacity() << endl;
  assert(b.capacity() == 15);
  cout << "The expected size is 0, the acutal size is " << b.size() << endl;
  assert(b.size() == 0);

  cout << "\nPress ENTER to continue..." << endl;
  cin.get();
}
int main()
{
  // print my name, this assignment's title, and file information
  cout << "Lab 6a, Write A Linked Array Class Template \n";
  cout << "Programmer: Sohaib Syed\n";
  cout << "Editor(s) used: Code::Blocks\n";
  cout << "Compiler(s) used: mingw32-g++\n";
  cout << "File: " << __FILE__ << endl;
  cout << "Complied: " << __DATE__ << " at " << __TIME__ << endl << endl;

  //declare values of the static array
  LinkedArray<int> a;
  LinkedArray<int> b(100);

  cout << "****************Constructor Testing***********************" << endl;
  for(int i = 0; i < a.capacity(); i++)
    if(a.containsKey(i) == false)
      cout << "a[" << i << "] = false" << endl;
  cout << "****************END OF Constructor Testing***********************" << endl;


  cout << endl << endl;
  cout << "****************[] Testing***********************" << endl;
  a[0] = 10;
  a[1] = 69;
  a[3] = 7;
  a[4] = 8;
  cout << a[0];
  for(int i = 0; i < a.capacity(); i++)
    if(a.containsKey(i))
      cout << "a[" << i << "] = " << a[i] << endl;
  cout << "****************END OF [] Testing***********************" << endl;
  cout << endl << endl;


    //object assignment testing
  cout << "**********************Object Assignment Testing**********************" << endl;
  cout << "Now testing if a[0] is set to 100." << endl;
  if(a[0] == 100)
    cout << "Test Result: They are equal! " << endl;
  else
    cout << "Test Result: They aren't equal..." << endl;
  cout << "******************End of Object Assignment Testing*******************" << endl;
  cout << endl << endl;

  // object copy testing with function from lab writeup
  cout << "**********************Object Copy Testing**********************" << endl;
  const LinkedArray<int> copy = a;
  for (int i = 0; i < copy.capacity(); i++)
    cout << "copy[" << i << "] = " << copy[i] << endl;
  cout << "*******************End of Object Copy Testing*******************" << endl;
  cout << endl << endl;

  cout << "******************Operator [] getter*******************" << endl;
  cout << "copy[0] is " << copy[0] << endl;
  cout << "****************** END OF Operator [] getter*******************" << endl;
  cout << endl << endl;

  cout << "*****************Testing the capacity array*********************" << endl;
  cout << "a.CAPACITY Should be 50. It is: " << a.capacity() << endl;
  assert(a.capacity() == 50);
  cout << "*****************End Testing the capacity array*****************" << endl;

  cout << endl << endl;

  cout << "*****************Now testing the size of the array*************" << endl;
  cout << "a.size() should be four. It actually is: " << a.size() << endl;
  assert(a.size() == 4);
  cout << "*****************EndNow testing the size of the array**********" << endl;

  cout << endl << endl;


  cout << "******************Testing the containsKey function*********" << endl;
  for(int i = 0; i < a.capacity(); i++)
  {
    if(a.containsKey(i) == true)
    {
       cout << "a[" << i << "] = true" << endl;
    }
  }
  assert((a.containsKey(0) && a.containsKey(1) && a.containsKey(3) && a.containsKey(4)) == true);
  cout << "******************End of the containsKey function**********" << endl;

  cout << endl << endl;

  cout << "******************Testing the deleteKey function***********" << endl;
  a.deleteKey(4);
  cout << "A.SIZE() should be three, is now: " << a.size() << endl;
  assert(a.size() == 3);
  cout << "******************End of the deleteKey test****************" << endl;

  cout << endl << endl;

  cout << "******************Testing the clear function***************" << endl;
  a.clear();
  cout << "A.SIZE() should be zero, is now: " << a.size() << endl;
  assert(a.size() == 0);
  cout << "******************End of the clear test********************" << endl;
  cout << endl << endl;

  cout << "******************Testing OPERATOR=***************" << endl;
  cout << "B.capacity is " << b.capacity() << endl;
  cout << "B.size is " << b.size() << endl;
  b = a;
  cout << "B.capacity now is " << b.capacity() << endl;
  cout << "B.size now is " << b.size() << endl;
  for(int i = 0; i < b.capacity(); i++)
    if(b.containsKey(i) == true)
      cout << "b[" << i << "] = " << b[i] << endl;
  cout << "******************End of operator=********************" << endl;
  cout << endl << endl;

  cout << "******************Testing expandibility***************" << endl;
  cout << "a[60] is wild, it is: " << a[60] << endl;
  a[60] = 699;
  cout << "new value of a[60] is: " << a[60] << endl;
  cout << "a.capacity now is: " << a.capacity() << endl;
  cout << "a.size now is: " << a.size() << endl;
  cout << "******************END OF Testing expandibility***************" << endl;


  cin.get();
}