source: geniuswebcore/test/geniusweb/bidspace/IntervalTest.py@ 94

Last change on this file since 94 was 90, checked in by Bart Vastenhouw, 3 years ago

Refactor to help reusing partiesserver.

File size: 2.9 KB
Line 
1import unittest
2from unitpy.GeneralTests import GeneralTests
3from decimal import Decimal
4from geniusweb.bidspace.Interval import Interval
5from typing import List
6
7class IntervalTest (unittest.TestCase, GeneralTests[Interval]):
8
9 ZERO = Decimal(0)
10 ONE = Decimal(1)
11 TWO = Decimal(2)
12 THREE = Decimal(3)
13 TEN = Decimal(10)
14
15 int1 = Interval(ZERO, ONE)
16 int1a = Interval(ZERO, ONE)
17 int2 = Interval(ONE, TEN)
18 int3 = Interval(TWO, TEN)
19
20 #Override
21 def getGeneralTestData(self)->List[List[Interval]] :
22 return [[self.int1, self.int1a], [self.int2],[self.int3]]
23
24 #Override
25 def getGeneralTestStrings(self) -> List[str] :
26 return ["Interval\\[0,1\\]", "Interval\\[1,10\\]",
27 "Interval\\[2,10\\]"]
28
29 def testsmokeTest(self) :
30 Interval(self.ZERO, self.ONE)
31
32 def testsmokeTestBad(self):
33 i = Interval(self.TEN, self.ONE)
34 self.assertTrue(i.isEmpty())
35
36 def testsmokeNull1Test(self):
37 self.assertRaises(ValueError, lambda: Interval(None,self.ZERO))
38
39 def testsmokeNull2test(self):
40 self.assertRaises(ValueError, lambda:Interval(self.ZERO, None))
41
42 def testMin(self):
43 self.assertEqual(Decimal(0), self.int1.getMin())
44 self.assertEqual(Decimal(1), self.int2.getMin())
45
46 def testMax(self):
47 self.assertEqual(Decimal(1), self.int1.getMax())
48 self.assertEqual(Decimal(10), self.int2.getMax())
49
50 def testcontainsTest(self):
51 self.assertTrue(self.int1.contains(Decimal(0.3)))
52 self.assertFalse(self.int1.contains(Decimal(-0.3)))
53 self.assertFalse(self.int1.contains(Decimal(1.3)))
54
55 self.assertFalse(self.int3.contains(self.ZERO))
56 self.assertFalse(self.int3.contains(self.ONE))
57 self.assertTrue(self.int3.contains(self.TWO));
58 self.assertTrue(self.int3.contains(self.THREE));
59 self.assertTrue(self.int3.contains(self.TEN));
60 self.assertFalse(self.int3.contains(Decimal(10.3)))
61
62 def testIntersect(self) :
63 self.assertEqual(self.int1, self.int1.intersect(self.int1))
64 self.assertEqual(Interval(self.ONE, self.ONE), self.int1.intersect(self.int2))
65 self.assertTrue(self.int1.intersect(self.int3).isEmpty())
66 self.assertEqual(Interval(self.ONE, self.TWO),
67 Interval(self.ZERO, self.TEN).intersect(Interval(self.ONE, self.TWO)))
68 self.assertEqual( Interval(self.ONE, self.TWO),
69 Interval(self.ONE, self.TWO).intersect(Interval(self.ZERO, self.TEN)))
70 self.assertEqual(Interval(self.ONE, self.TWO),
71 Interval(self.ZERO, self.TWO).intersect(Interval(self.ONE, self.TEN)))
72 self.assertEqual( Interval(self.ONE, self.TWO),
73 Interval(self.ONE, self.TEN).intersect( Interval(self.ZERO, self.TWO)))
74
75 def testsubtractTest(self):
76 self.assertEqual(Interval(Decimal(-1), self.ZERO),
77 self.int1.subtract(self.ONE))
78
79 def testinvertTest(self) :
80 self.assertEqual(Interval(Decimal(-10), self.ZERO),
81 self.int1.invert(self.int2))
82 self.assertEqual(Interval(self.ZERO, self.TEN), self.int2.invert(self.int1))
83 self.assertEqual(
84 Interval(Decimal(-9), Decimal(8)),
85 self.int2.invert(self.int3))
Note: See TracBrowser for help on using the repository browser.