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

Last change on this file since 66 was 59, checked in by Wouter Pasman, 3 years ago

#44 manual commit of first public release, because this will cause the dist directory to move

File size: 1.6 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 testSerialize(self):
20 print(str(self.pyson.toJson(self.val)))
21 self.assertEqual(self.valjson, self.pyson.toJson(self.val))
22
23 def testDeserialize(self):
24 set:NumberValueSet= self.pyson.parse(self.valjson, ValueSet)
25 self.assertEqual(self.val, set)
26 self.assertTrue(isinstance(set.getRange().getLow(), Decimal))
27
28 def testIterator(self):
29 self.assertTrue(NumberValue(Decimal('12.2')) in self.val)
30
31 def testGetter(self):
32 set=NumberValueSet(Range(Decimal("900"),Decimal("1800"), Decimal("300")))
33 print (str(set.get(1)))
34
35 def testRepr(self):
36 self.assertEqual("NumberValueSet[12.2,12.6,0.3]", repr(self.val))
37
38 def testEqual(self):
39 self.assertEqual(self.val, self.val1)
40 self.assertNotEqual(self.val, self.val2)
41 self.assertEqual(hash(self.val), hash(self.val1))
42 self.assertNotEqual(hash(self.val), hash(self.val2))
43
Note: See TracBrowser for help on using the repository browser.