import unittest from tudelft.utilities.immutablelist.ArrayListSet import ArrayListSet class ArrayListTest (unittest.TestCase) : def setUp(self): self.set = ArrayListSet[str]() self.setReverse = ArrayListSet[str]() self.set.append("a"); self.set.append("b"); self.setReverse.append("b"); self.setReverse.append("a"); def testContains(self): self.assertTrue("a" in self.set) self.assertFalse("c" in self.set) def testEquality(self): self.assertEqual(self.set, self.setReverse) def testHashCodeInsensitiveToOrder(self): self.assertEqual(hash(self.set), hash(self.setReverse)) def testAdd(self): self.assertEqual(2, len(self.set)) self.set.append("a") self.assertEqual(2, len(self.set)) self.set.append("c") self.assertEqual(3, len(self.set)) def testRemove(self) : self.assertEqual(2, len(self.set)) self.set.remove("a") self.assertEqual(1, len(self.set)) def testAddAt(self) : self.set.insert(1, "a"); # nothing happens, a already in set. self.assertEqual(2, len(self.set)) self.set.insert(1, "c"); self.assertEqual("c", self.set[1]) def testExtend(self): self.set.extend(['p','q']); self.assertEqual(4, len(self.set)) self.set.extend(['p','r']); self.assertEqual(5, len(self.set))