source: utilitiespy/test/immutablelist/ArrayListSetTest.py

Last change on this file was 857, checked in by wouter, 5 months ago

#264 added check in utilitiespy to check hashcode of arraylistset and reverse set are equal

File size: 1.5 KB
Line 
1import unittest
2from tudelft.utilities.immutablelist.ArrayListSet import ArrayListSet
3
4class ArrayListTest (unittest.TestCase) :
5
6 def setUp(self):
7 self.set = ArrayListSet[str]()
8 self.setReverse = ArrayListSet[str]()
9
10 self.set.append("a");
11 self.set.append("b");
12 self.setReverse.append("b");
13 self.setReverse.append("a");
14
15 def testContains(self):
16 self.assertTrue("a" in self.set)
17 self.assertFalse("c" in self.set)
18
19 def testEquality(self):
20 self.assertEqual(self.set, self.setReverse)
21
22 def testHashCodeInsensitiveToOrder(self):
23 self.assertEqual(hash(self.set), hash(self.setReverse))
24
25 def testAdd(self):
26 self.assertEqual(2, len(self.set))
27 self.set.append("a")
28 self.assertEqual(2, len(self.set))
29 self.set.append("c")
30 self.assertEqual(3, len(self.set))
31
32
33 def testRemove(self) :
34 self.assertEqual(2, len(self.set))
35 self.set.remove("a")
36 self.assertEqual(1, len(self.set))
37
38 def testAddAt(self) :
39 self.set.insert(1, "a"); # nothing happens, a already in set.
40 self.assertEqual(2, len(self.set))
41 self.set.insert(1, "c");
42 self.assertEqual("c", self.set[1])
43
44 def testExtend(self):
45 self.set.extend(['p','q']);
46 self.assertEqual(4, len(self.set))
47 self.set.extend(['p','r']);
48 self.assertEqual(5, len(self.set))
49
50 def testHash(self):
51 self.assertEqual(hash(self.set), hash(self.setReverse))
Note: See TracBrowser for help on using the repository browser.