source: bidspace/src/test/java/geniusweb/bidspace/IntervalTest.java@ 52

Last change on this file since 52 was 52, checked in by ruud, 14 months ago

Fixed small issues in domaineditor.

File size: 3.3 KB
Line 
1package geniusweb.bidspace;
2
3import static org.junit.Assert.assertEquals;
4import static org.junit.Assert.assertFalse;
5import static org.junit.Assert.assertTrue;
6
7import java.math.BigDecimal;
8import java.util.Arrays;
9import java.util.List;
10
11import org.junit.Test;
12
13import tudelft.utilities.junit.GeneralTests;
14
15public class IntervalTest extends GeneralTests<Interval> {
16
17 private static final BigDecimal ZERO = BigDecimal.ZERO;
18 private static final BigDecimal ONE = BigDecimal.ONE;
19 private static final BigDecimal TWO = BigDecimal.valueOf(2);
20 private static final BigDecimal THREE = BigDecimal.valueOf(3);
21 private static final BigDecimal TEN = BigDecimal.TEN;
22 private static final Interval int1 = new Interval(ZERO, ONE);
23 private static final Interval int1a = new Interval(ZERO, ONE);
24 private static final Interval int2 = new Interval(ONE, TEN);
25 private static final Interval int3 = new Interval(TWO, TEN);
26
27 @Override
28 public List<List<Interval>> getGeneralTestData() {
29 return Arrays.asList(Arrays.asList(int1, int1a), Arrays.asList(int2),
30 Arrays.asList(int3));
31 }
32
33 @Override
34 public List<String> getGeneralTestStrings() {
35 return Arrays.asList("Interval\\[0,1\\]", "Interval\\[1,10\\]",
36 "Interval\\[2,10\\]");
37 }
38
39 @Test
40 public void smokeTest() {
41 new Interval(BigDecimal.ZERO, BigDecimal.ONE);
42 }
43
44 @Test
45 public void smokeTestBad() {
46 Interval i = new Interval(BigDecimal.TEN, BigDecimal.ONE);
47 assertTrue(i.isEmpty());
48 }
49
50 @Test(expected = NullPointerException.class)
51 public void smokeNull1() {
52 new Interval(null, BigDecimal.ZERO);
53 }
54
55 @Test(expected = NullPointerException.class)
56 public void smokeNull2() {
57 new Interval(BigDecimal.ZERO, null);
58 }
59
60 @Test
61 public void testMin() {
62 assertEquals(BigDecimal.ZERO, int1.getMin());
63 assertEquals(BigDecimal.ONE, int2.getMin());
64 }
65
66 @Test
67 public void testMax() {
68 assertEquals(BigDecimal.ONE, int1.getMax());
69 assertEquals(BigDecimal.TEN, int2.getMax());
70 }
71
72 @Test
73 public void containsTest() {
74 assertTrue(int1.contains(BigDecimal.valueOf(0.3)));
75 assertFalse(int1.contains(BigDecimal.valueOf(-0.3)));
76 assertFalse(int1.contains(BigDecimal.valueOf(1.3)));
77
78 assertFalse(int3.contains(ZERO));
79 assertFalse(int3.contains(ONE));
80 assertTrue(int3.contains(TWO));
81 assertTrue(int3.contains(THREE));
82 assertTrue(int3.contains(TEN));
83 assertFalse(int3.contains(BigDecimal.valueOf(10.3)));
84
85 }
86
87 @Test
88 public void testIntersect() {
89 assertEquals(int1, int1.intersect(int1));
90 assertEquals(new Interval(ONE, ONE), int1.intersect(int2));
91 assertTrue(int1.intersect(int3).isEmpty());
92 assertEquals(new Interval(ONE, TWO),
93 new Interval(ZERO, TEN).intersect(new Interval(ONE, TWO)));
94 assertEquals(new Interval(ONE, TWO),
95 new Interval(ONE, TWO).intersect(new Interval(ZERO, TEN)));
96 assertEquals(new Interval(ONE, TWO),
97 new Interval(ZERO, TWO).intersect(new Interval(ONE, TEN)));
98 assertEquals(new Interval(ONE, TWO),
99 new Interval(ONE, TEN).intersect(new Interval(ZERO, TWO)));
100 }
101
102 @Test
103 public void subtractTest() {
104 assertEquals(new Interval(BigDecimal.valueOf(-1), ZERO),
105 int1.subtract(ONE));
106 }
107
108 @Test
109 public void invertTest() {
110 assertEquals(new Interval(BigDecimal.valueOf(-10), ZERO),
111 int1.invert(int2));
112 assertEquals(new Interval(ZERO, TEN), int2.invert(int1));
113 assertEquals(
114 new Interval(BigDecimal.valueOf(-9), BigDecimal.valueOf(8)),
115 int2.invert(int3));
116 }
117
118}
Note: See TracBrowser for help on using the repository browser.