source: utilitiespy/test/tools/IteratorTest.py@ 1343

Last change on this file since 1343 was 1310, checked in by wouter, 2 weeks ago

#407 added removeAll and remove to iterator - python does not have this functionality

File size: 854 bytes
Line 
1import unittest
2from tudelft.utilities.listener.DefaultListenable import DefaultListenable
3from tudelft.utilities.tools.Iterator import hasNext, remove, removeAll
4
5class IteratorTest(unittest.TestCase):
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))
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
Note: See TracBrowser for help on using the repository browser.