source: utilitiespy/test/immutablelist/RangeTest.py@ 1269

Last change on this file since 1269 was 962, checked in by wouter, 5 months ago

#329 AbstractImmutableList iterator implement iter

File size: 2.1 KB
Line 
1from decimal import Decimal
2from tudelft.utilities.immutablelist.Range import Range
3import unittest
4
5
6class RangeTest (unittest.TestCase) :
7 r=Range(Decimal(900),Decimal(1800),Decimal(300))
8 r1=Range(Decimal(900),Decimal(1800),Decimal(300))
9 r2=Range(Decimal(300),Decimal(1800),Decimal(300))
10 r3=Range(Decimal(900),Decimal(1100),Decimal(300))
11 r4=Range(Decimal(900),Decimal(1800),Decimal(400))
12
13 def testSmoke(self):
14 Range(Decimal('1'), Decimal('2'), Decimal('0.1'))
15
16
17 def testGet(self):
18 r=Range(Decimal('1'), Decimal('2'), Decimal('0.1'))
19 self.assertEqual(1, r.get(0))
20 self.assertEqual(Decimal('1.1'), r.get(1))
21 self.assertEqual(Decimal('2'), r.get(10))
22
23 def testSize(self):
24 r=Range(Decimal('1'), Decimal('2'), Decimal('0.1'))
25 self.assertEqual(11, r.size())
26 self.assertEqual(4, self.r.size())
27
28 def testIterator(self):
29 r=Range(Decimal('1'), Decimal('2'), Decimal('0.1'))
30 self.assertTrue(Decimal('1') in r)
31 self.assertTrue(Decimal('2') in r)
32 self.assertFalse(Decimal('0.9') in r)
33 self.assertFalse(Decimal('0.9999') in r)
34 self.assertFalse(Decimal('1.22') in r)
35 self.assertFalse(Decimal('2.1') in r)
36
37 def testIterator2(self):
38 r=Range(Decimal('1'), Decimal('2'), Decimal('0.1'))
39 values=[v for v in r]
40 print(values)
41
42
43 def testStr(self):
44 self.assertEqual('Range[900,1800,300]', repr(self.r))
45 self.assertEqual('Range[900,1800,300]', str(self.r))
46
47 def testHash(self):
48 self.assertNotEqual(0,hash(self.r))
49 self.assertEqual(hash(self.r), hash(self.r1))
50 self.assertNotEqual(hash(self.r), hash(self.r2))
51 self.assertNotEqual(hash(self.r), hash(self.r3))
52 self.assertNotEqual(hash(self.r), hash(self.r4))
53
54 def testEqual(self):
55 self.assertEqual(self.r, self.r1)
56 self.assertNotEqual(self.r, self.r2)
57
58
59 def testContains(self):
60 self.assertTrue( self.r.contains(900))
61 self.assertTrue( self.r.contains(1200))
62 self.assertTrue( self.r.contains(1800))
63 self.assertFalse( self.r.contains(2100))
64 self.assertFalse( self.r.contains(600))
65 self.assertFalse( self.r.contains(0))
66
67 def testIterable(self):
68 self.assertEqual([Decimal('900'), Decimal('1200'),
69 Decimal('1500'), Decimal('1800')],
70 list(iter(self.r)))
71
72
Note: See TracBrowser for help on using the repository browser.