source: immutablelistpy/test/immutablelist/RangeTest.py@ 209

Last change on this file since 209 was 199, checked in by wouter, 3 years ago

#85 cleaned up and tested immutablelistpy. Removed pyson dependency, added doc

File size: 1.4 KB
Line 
1from decimal import Decimal
2import unittest
3
4from immutablelist.Range import Range
5
6
7class RangeTest (unittest.TestCase) :
8 r=Range(Decimal(900),Decimal(1800),Decimal(300))
9 r1=Range(Decimal(900),Decimal(1800),Decimal(300))
10 r2=Range(Decimal(300),Decimal(1800),Decimal(300))
11
12 def testSmoke(self):
13 Range(Decimal('1'), Decimal('2'), Decimal('0.1'))
14
15
16 def testGet(self):
17 r=Range(Decimal('1'), Decimal('2'), Decimal('0.1'))
18 self.assertEqual(1, r.get(0))
19 self.assertEqual(Decimal('1.1'), r.get(1))
20 self.assertEqual(Decimal('2'), r.get(10))
21
22 def testSize(self):
23 r=Range(Decimal('1'), Decimal('2'), Decimal('0.1'))
24 self.assertEqual(11, r.size())
25 self.assertEqual(4, self.r.size())
26
27 def testIterator(self):
28 r=Range(Decimal('1'), Decimal('2'), Decimal('0.1'))
29 self.assertTrue(Decimal('1') in r)
30 self.assertTrue(Decimal('2') in r)
31 self.assertFalse(Decimal('0.9') in r)
32 self.assertFalse(Decimal('0.9999') in r)
33 self.assertFalse(Decimal('1.22') in r)
34 self.assertFalse(Decimal('2.1') in r)
35
36 def testIterator2(self):
37 r=Range(Decimal('1'), Decimal('2'), Decimal('0.1'))
38 values=[v for v in r]
39 print(values)
40
41
42 def testStr(self):
43 self.assertEqual('Range[900,1800,300]', repr(self.r))
44 self.assertEqual('Range[900,1800,300]', str(self.r))
45
46 def testHash(self):
47 self.assertNotEqual(0,hash(self.r))
48
49 def testEqual(self):
50 self.assertEqual(self.r, self.r1)
51 self.assertNotEqual(self.r, self.r2)
Note: See TracBrowser for help on using the repository browser.