[667] | 1 | import unittest
|
---|
| 2 | from tudelft.utilities.listener.DefaultListenable import DefaultListenable
|
---|
[1310] | 3 | from tudelft.utilities.tools.Iterator import hasNext, remove, removeAll
|
---|
[667] | 4 |
|
---|
[1176] | 5 | class IteratorTest(unittest.TestCase):
|
---|
[667] | 6 |
|
---|
| 7 | def test_Iterator(self):
|
---|
| 8 | it=iter([1,2,3])
|
---|
| 9 | result=[]
|
---|
| 10 | while (t:=hasNext(it)) and (it:=t[1]) and t[0]:
|
---|
| 11 | nxt=next(it)
|
---|
| 12 | print(nxt)
|
---|
| 13 | result.append(nxt)
|
---|
| 14 | self.assertEqual(3, len(result))
|
---|
[1310] | 15 |
|
---|
| 16 |
|
---|
| 17 | def test_remove(self):
|
---|
| 18 | l=[1,2,3,2,1]
|
---|
| 19 | self.assertTrue(remove(l, 1))
|
---|
| 20 | self.assertEqual([2,3,2], l)
|
---|
| 21 | self.assertFalse(remove(l, 1))
|
---|
| 22 |
|
---|
| 23 | l=[1,2,3,2,1]
|
---|
| 24 | self.assertTrue(remove(l, 2))
|
---|
| 25 | self.assertEqual([1,3,1], l)
|
---|
| 26 | self.assertFalse(remove(l, 2))
|
---|
| 27 |
|
---|
| 28 | def test_removeAll(self):
|
---|
| 29 | l=[1,2,3,2,1,3,2,1,1,2,3]
|
---|
| 30 | self.assertTrue(removeAll(l, [1,2]))
|
---|
| 31 | self.assertEqual([3,3,3], l)
|
---|
| 32 | self.assertFalse(removeAll(l, [1,2]))
|
---|
| 33 | self.assertEqual([3,3,3], l)
|
---|
| 34 |
|
---|
| 35 | |
---|