import unittest from tudelft.utilities.immutablelist.FixedList import FixedList from tudelft.utilities.immutablelist.SubList import SubList class SubListTest(unittest.TestCase): list3 = FixedList[int]([1, 2, 3]); select0 = 0 select1 = 1 select6 = 6 def testSubList1(self): # element ONE means binary 001 means SubList contains only 1. l1 = SubList[int]( self.list3, self.select1) print(l1) self.assertEqual(1, l1.size()) self.assertEqual(1, l1.get(0)) def testSubList6(self): # SIX = 110 so element 2 and 3 selected l1 = SubList[int](self.list3, self.select6) print(l1) self.assertEqual(2, l1.size()) self.assertEqual(2, l1.get(0)) def testOutOfRangeIndex(self): # SIX = 110 so element 2 and 3 selected l1 = SubList[int](self.list3, self.select6) self.assertRaises(IndexError, lambda:l1.get(2)) def testEmptySubList(self): l1 = SubList[int](self.list3, self.select0) print(l1) self.assertEqual(0, l1.size()) def testComplement(self): l1 = SubList[int](self.list3, self.select1) l1 = l1.complement() self.assertEquals(2, l1.size()) print(l1)