from decimal import Decimal from tudelft.utilities.immutablelist.Range import Range import unittest 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)) r3=Range(Decimal(900),Decimal(1100),Decimal(300)) r4=Range(Decimal(900),Decimal(1800),Decimal(400)) 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)) self.assertEqual(hash(self.r), hash(self.r1)) self.assertNotEqual(hash(self.r), hash(self.r2)) self.assertNotEqual(hash(self.r), hash(self.r3)) self.assertNotEqual(hash(self.r), hash(self.r4)) def testEqual(self): self.assertEqual(self.r, self.r1) self.assertNotEqual(self.r, self.r2) def testContains(self): self.assertTrue( self.r.contains(900)) self.assertTrue( self.r.contains(1200)) self.assertTrue( self.r.contains(1800)) self.assertFalse( self.r.contains(2100)) self.assertFalse( self.r.contains(600)) self.assertFalse( self.r.contains(0)) def testIterable(self): self.assertEqual([Decimal('900'), Decimal('1200'), Decimal('1500'), Decimal('1800')], list(iter(self.r)))