from decimal import Decimal import unittest from immutablelist.Range import Range class RangeTest (unittest.TestCase) : r=Range(Decimal(900),Decimal(1800),Decimal(300)) r1=Range(Decimal(900),Decimal(1800),Decimal(300)) r2=Range(Decimal(300),Decimal(1800),Decimal(300)) def testSmoke(self): Range(Decimal('1'), Decimal('2'), Decimal('0.1')) def testGet(self): r=Range(Decimal('1'), Decimal('2'), Decimal('0.1')) self.assertEqual(1, r.get(0)) self.assertEqual(Decimal('1.1'), r.get(1)) self.assertEqual(Decimal('2'), r.get(10)) def testSize(self): r=Range(Decimal('1'), Decimal('2'), Decimal('0.1')) self.assertEqual(11, r.size()) self.assertEqual(4, self.r.size()) def testIterator(self): r=Range(Decimal('1'), Decimal('2'), Decimal('0.1')) self.assertTrue(Decimal('1') in r) self.assertTrue(Decimal('2') in r) self.assertFalse(Decimal('0.9') in r) self.assertFalse(Decimal('0.9999') in r) self.assertFalse(Decimal('1.22') in r) self.assertFalse(Decimal('2.1') in r) def testIterator2(self): r=Range(Decimal('1'), Decimal('2'), Decimal('0.1')) values=[v for v in r] print(values) def testStr(self): self.assertEqual('Range[900,1800,300]', repr(self.r)) self.assertEqual('Range[900,1800,300]', str(self.r)) def testHash(self): self.assertNotEqual(0,hash(self.r)) def testEqual(self): self.assertEqual(self.r, self.r1) self.assertNotEqual(self.r, self.r2)