import unittest from tudelft.utilities.listener.DefaultListenable import DefaultListenable from tudelft.utilities.tools.Iterator import hasNext, remove, removeAll class IteratorTest(unittest.TestCase): def test_Iterator(self): it=iter([1,2,3]) result=[] while (t:=hasNext(it)) and (it:=t[1]) and t[0]: nxt=next(it) print(nxt) result.append(nxt) self.assertEqual(3, len(result)) def test_remove(self): l=[1,2,3,2,1] self.assertTrue(remove(l, 1)) self.assertEqual([2,3,2], l) self.assertFalse(remove(l, 1)) l=[1,2,3,2,1] self.assertTrue(remove(l, 2)) self.assertEqual([1,3,1], l) self.assertFalse(remove(l, 2)) def test_removeAll(self): l=[1,2,3,2,1,3,2,1,1,2,3] self.assertTrue(removeAll(l, [1,2])) self.assertEqual([3,3,3], l) self.assertFalse(removeAll(l, [1,2])) self.assertEqual([3,3,3], l)