1 | from decimal import Decimal
|
---|
2 | import unittest
|
---|
3 |
|
---|
4 | from pyson.ObjectMapper import ObjectMapper
|
---|
5 | from tudelft.utilities.immutablelist.Range import Range
|
---|
6 |
|
---|
7 | from geniusweb.issuevalue.NumberValue import NumberValue
|
---|
8 | from geniusweb.issuevalue.NumberValueSet import NumberValueSet
|
---|
9 | from geniusweb.issuevalue.ValueSet import ValueSet
|
---|
10 |
|
---|
11 |
|
---|
12 | class 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 | |
---|