source: java2python/geniuswebtranslator/geniuswebtest/geniusweb/issuevalue/NumberValueSetTest.java@ 655

Last change on this file since 655 was 595, checked in by wouter, 16 months ago

#197 working on translating @Test annotations.
added (expected-..) support.
Fixed poms that suddenly require https and /maven2

File size: 3.3 KB
Line 
1package geniusweb.issuevalue;
2
3import static org.junit.Assert.assertEquals;
4import static org.junit.Assert.assertNotEquals;
5import static org.junit.Assert.assertTrue;
6
7import java.io.IOException;
8import java.math.BigDecimal;
9import java.math.BigInteger;
10
11import org.junit.Test;
12
13import com.fasterxml.jackson.core.JsonParseException;
14import com.fasterxml.jackson.core.JsonProcessingException;
15import com.fasterxml.jackson.databind.JsonMappingException;
16import com.fasterxml.jackson.databind.ObjectMapper;
17
18import tudelft.utilities.immutablelist.Range;
19
20public class NumberValueSetTest {
21
22 private static final BigDecimal ZERO_THREE = new BigDecimal("0.3");
23 private static final BigDecimal TWELVE_SIX = new BigDecimal("12.6");
24 private static final BigDecimal TWELVE_TWO = new BigDecimal("12.2");
25 private final static NumberValueSet set = new NumberValueSet(TWELVE_TWO,
26 TWELVE_SIX, ZERO_THREE);
27 private final static NumberValueSet set1 = new NumberValueSet(TWELVE_TWO,
28 TWELVE_SIX, ZERO_THREE);
29 private final static NumberValueSet setb = new NumberValueSet(TWELVE_TWO,
30 new BigDecimal("12.6000000000001"), ZERO_THREE);
31 private final static NumberValueSet set10 = new NumberValueSet(
32 BigDecimal.ZERO, BigDecimal.ONE, new BigDecimal("0.1"));
33
34 private final String asString = "{\"range\":{\"low\":12.2,\"high\":12.6,\"step\":0.3}}";
35 private final static NumberValueSet bigset = new NumberValueSet(
36 BigDecimal.ZERO, BigDecimal.TEN, new BigDecimal("0.00003"));
37
38 @Test(expected = IllegalArgumentException.class)
39 public void testConstructor1() {
40 new NumberValueSet(TWELVE_SIX, TWELVE_TWO, ZERO_THREE);
41 }
42
43 @Test(expected = IllegalArgumentException.class)
44 public void testConstructor2() {
45 new NumberValueSet(BigDecimal.ZERO, BigDecimal.TEN,
46 new BigDecimal("-1"));
47 }
48
49 @Test
50 public void testIterator() {
51 assertEquals(new NumberValue(BigDecimal.ZERO),
52 bigset.iterator().next());
53 }
54
55 @Test
56 public void testSerialize() throws JsonProcessingException {
57 ObjectMapper jackson = new ObjectMapper();
58
59 String json = jackson.writeValueAsString(set);
60 System.out.println(json);
61 assertEquals(asString, json);
62 }
63
64 @Test
65 public void testDeserialize()
66 throws JsonParseException, JsonMappingException, IOException {
67 ObjectMapper jackson = new ObjectMapper();
68 ValueSet p = jackson.readValue(asString, NumberValueSet.class);
69 assertEquals(set, p);
70 }
71
72 @Test
73 public void containsTest() {
74 assertTrue(bigset.contains(new NumberValue(new BigDecimal("0.00393"))));
75 }
76
77 @Test
78 public void containsFirstTest() {
79 assertTrue(bigset.contains(new NumberValue(BigDecimal.ZERO)));
80 }
81
82 @Test
83 public void containsLastTest() {
84 assertTrue(set10.contains(new NumberValue(BigDecimal.ONE)));
85 }
86
87 @Test
88 public void equalsTest() {
89 assertEquals(set, set1);
90 assertEquals(set1, set);
91 assertNotEquals(set, null);
92 assertNotEquals(null, set);
93 assertNotEquals(set, setb);
94
95 }
96
97 @Test
98 public void getRangeTest() {
99 assertEquals(new Range(TWELVE_TWO, TWELVE_SIX, ZERO_THREE),
100 set.getRange());
101 }
102
103 @Test
104 public void testGet() {
105 assertEquals(new NumberValue(TWELVE_TWO), set.get(BigInteger.ZERO));
106 assertEquals(new NumberValue(TWELVE_TWO), set.get(0));
107 assertEquals(new NumberValue(TWELVE_TWO.add(ZERO_THREE)),
108 set.get(BigInteger.ONE));
109 }
110
111 @Test
112 public void testSize() {
113 assertEquals(new BigInteger("2"), set.size());
114 assertEquals(new BigInteger("11"), set10.size());
115 }
116
117}
Note: See TracBrowser for help on using the repository browser.