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

Last change on this file since 742 was 661, checked in by wouter, 13 months ago

#227 opending tests

File size: 1.7 KB
RevLine 
[222]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
11 def testSmoke(self):
12 Range(Decimal('1'), Decimal('2'), Decimal('0.1'))
13
14
15 def testGet(self):
16 r=Range(Decimal('1'), Decimal('2'), Decimal('0.1'))
17 self.assertEqual(1, r.get(0))
18 self.assertEqual(Decimal('1.1'), r.get(1))
19 self.assertEqual(Decimal('2'), r.get(10))
20
21 def testSize(self):
22 r=Range(Decimal('1'), Decimal('2'), Decimal('0.1'))
23 self.assertEqual(11, r.size())
24 self.assertEqual(4, self.r.size())
25
26 def testIterator(self):
27 r=Range(Decimal('1'), Decimal('2'), Decimal('0.1'))
28 self.assertTrue(Decimal('1') in r)
29 self.assertTrue(Decimal('2') in r)
30 self.assertFalse(Decimal('0.9') in r)
31 self.assertFalse(Decimal('0.9999') in r)
32 self.assertFalse(Decimal('1.22') in r)
33 self.assertFalse(Decimal('2.1') in r)
34
35 def testIterator2(self):
36 r=Range(Decimal('1'), Decimal('2'), Decimal('0.1'))
37 values=[v for v in r]
38 print(values)
39
40
41 def testStr(self):
42 self.assertEqual('Range[900,1800,300]', repr(self.r))
43 self.assertEqual('Range[900,1800,300]', str(self.r))
44
45 def testHash(self):
46 self.assertNotEqual(0,hash(self.r))
47
48 def testEqual(self):
49 self.assertEqual(self.r, self.r1)
[661]50 self.assertNotEqual(self.r, self.r2)
51
52
53 def testContains(self):
54 self.assertTrue( self.r.contains(900))
55 self.assertTrue( self.r.contains(1200))
56 self.assertTrue( self.r.contains(1800))
57 self.assertFalse( self.r.contains(2100))
58 self.assertFalse( self.r.contains(600))
59 self.assertFalse( self.r.contains(0))
60
61
62
63
Note: See TracBrowser for help on using the repository browser.