source: geniuswebcore/test/geniusweb/issuevalue/NumberValueSetTest.py@ 78

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

Fix for IssueValue hashcode.

File size: 1.7 KB
Line 
1from decimal import Decimal
2import unittest
3
4from pyson.ObjectMapper import ObjectMapper
5from tudelft.utilities.immutablelist.Range import Range
6
7from geniusweb.issuevalue.NumberValue import NumberValue
8from geniusweb.issuevalue.NumberValueSet import NumberValueSet
9from geniusweb.issuevalue.ValueSet import ValueSet
10
11
12class NumberValueSetTest(unittest.TestCase):
13 pyson=ObjectMapper()
14 val = NumberValueSet(Range(Decimal('12.2'), Decimal('12.6'), Decimal('0.3')))
15 val1 = NumberValueSet(Range(Decimal('12.2'), Decimal('12.6'), Decimal('0.3')))
16 val2 = NumberValueSet(Range(Decimal('12.2'), Decimal('12.7'), Decimal('0.3')))
17 valjson = {"range":{"low":12.2,"high":12.6,"step":0.3}}
18
19 def testInit(self):
20 self.assertRaises(ValueError, lambda: NumberValueSet(range(1,5)))
21
22 def testSerialize(self):
23 print(str(self.pyson.toJson(self.val)))
24 self.assertEqual(self.valjson, self.pyson.toJson(self.val))
25
26 def testDeserialize(self):
27 set:NumberValueSet= self.pyson.parse(self.valjson, ValueSet)
28 self.assertEqual(self.val, set)
29 self.assertTrue(isinstance(set.getRange().getLow(), Decimal))
30
31 def testIterator(self):
32 self.assertTrue(NumberValue(Decimal('12.2')) in self.val)
33
34 def testGetter(self):
35 set=NumberValueSet(Range(Decimal("900"),Decimal("1800"), Decimal("300")))
36 print (str(set.get(1)))
37
38 def testRepr(self):
39 self.assertEqual("NumberValueSet[12.2,12.6,0.3]", repr(self.val))
40
41 def testEqual(self):
42 self.assertEqual(self.val, self.val1)
43 self.assertNotEqual(self.val, self.val2)
44 self.assertEqual(hash(self.val), hash(self.val1))
45 self.assertNotEqual(hash(self.val), hash(self.val2))
46
Note: See TracBrowser for help on using the repository browser.