1 | package geniusweb.model;
|
---|
2 |
|
---|
3 | import static org.junit.Assert.assertEquals;
|
---|
4 | import static org.mockito.ArgumentMatchers.any;
|
---|
5 | import static org.mockito.Mockito.mock;
|
---|
6 | import static org.mockito.Mockito.times;
|
---|
7 | import static org.mockito.Mockito.verify;
|
---|
8 |
|
---|
9 | import java.math.BigDecimal;
|
---|
10 |
|
---|
11 | import org.junit.Test;
|
---|
12 |
|
---|
13 | import geniusweb.domaineditor.ProfileEditor;
|
---|
14 | import geniusweb.domaineditor.model.NumberValueSetModel;
|
---|
15 | import geniusweb.issuevalue.NumberValueSet;
|
---|
16 | import geniusweb.issuevalue.ValueSet;
|
---|
17 | import tudelft.utilities.immutablelist.Range;
|
---|
18 | import tudelft.utilities.listener.Unacceptable;
|
---|
19 | import tudelft.utilities.logging.Reporter;
|
---|
20 | import tudelft.utilities.mvc.model.NumberModel;
|
---|
21 |
|
---|
22 | public class NumberValueSetModelTest {
|
---|
23 | private final Reporter log = mock(Reporter.class);
|
---|
24 |
|
---|
25 | @Test
|
---|
26 | public void smoke() throws Unacceptable {
|
---|
27 | new NumberValueSetModel(log);
|
---|
28 | }
|
---|
29 |
|
---|
30 | @Test
|
---|
31 | public void testSomeGoodValues() throws Unacceptable {
|
---|
32 | NumberValueSetModel model = new NumberValueSetModel(log);
|
---|
33 | assertEquals(11, model.getList().getSize()); // default is 0...10
|
---|
34 | model.getLow().setValue(new BigDecimal("2"));
|
---|
35 | assertEquals(9, model.getList().getSize()); // 2..10
|
---|
36 | model.getHigh().setValue(new BigDecimal("3"));
|
---|
37 | assertEquals(2, model.getLow().getValue().intValue());
|
---|
38 | assertEquals(3, model.getHigh().getValue().intValue());
|
---|
39 | assertEquals(2, model.getList().getSize()); // 2..3
|
---|
40 | model.getStep().setValue(new BigDecimal("0.1"));
|
---|
41 | assertEquals(11, model.getList().getSize()); // 2.0, 2.1, ...,3.0
|
---|
42 | }
|
---|
43 |
|
---|
44 | @Test(expected = Unacceptable.class)
|
---|
45 | public void testIllegal1() throws Unacceptable {
|
---|
46 | new NumberValueSetModel(
|
---|
47 | new NumberModel(BigDecimal.TEN, log, ProfileEditor.TIME),
|
---|
48 | new NumberModel(BigDecimal.ONE, log, ProfileEditor.TIME),
|
---|
49 | new NumberModel(BigDecimal.ONE, log, ProfileEditor.TIME), log);
|
---|
50 | }
|
---|
51 |
|
---|
52 | @Test
|
---|
53 | public void testIllegal12() throws Unacceptable {
|
---|
54 | NumberValueSetModel n = new NumberValueSetModel(log);
|
---|
55 | // change low above high must log problem
|
---|
56 | n.getLow().setValue(BigDecimal.valueOf(20));
|
---|
57 | verify(log, times(1)).log(any(), any());
|
---|
58 | }
|
---|
59 |
|
---|
60 | @Test(expected = Unacceptable.class)
|
---|
61 | public void testIllegal3() throws Unacceptable {
|
---|
62 | NumberValueSetModel model = new NumberValueSetModel(
|
---|
63 | new NumberModel(BigDecimal.TEN, log, ProfileEditor.TIME),
|
---|
64 | new NumberModel(BigDecimal.ONE, log, ProfileEditor.TIME),
|
---|
65 | new NumberModel(BigDecimal.ONE, log, ProfileEditor.TIME), log);
|
---|
66 | model.getLow().setValue(BigDecimal.valueOf(20));
|
---|
67 | }
|
---|
68 |
|
---|
69 | @Test
|
---|
70 | public void testLowIncrease() throws Unacceptable {
|
---|
71 | NumberValueSetModel set = new NumberValueSetModel(
|
---|
72 | new NumberModel(BigDecimal.ZERO, log, ProfileEditor.TIME),
|
---|
73 | new NumberModel(BigDecimal.TEN, log, ProfileEditor.TIME),
|
---|
74 | new NumberModel(BigDecimal.ONE, log, ProfileEditor.TIME), log);
|
---|
75 | ValueSet v = new NumberValueSet(
|
---|
76 | new Range(BigDecimal.ONE, BigDecimal.TEN, BigDecimal.ONE));
|
---|
77 | set.setCurrentValue(v);
|
---|
78 |
|
---|
79 | }
|
---|
80 |
|
---|
81 | @Test
|
---|
82 | public void testHighDecrease() throws Unacceptable {
|
---|
83 | NumberValueSetModel set = new NumberValueSetModel(
|
---|
84 | new NumberModel(BigDecimal.ZERO, log, ProfileEditor.TIME),
|
---|
85 | new NumberModel(BigDecimal.TEN, log, ProfileEditor.TIME),
|
---|
86 | new NumberModel(BigDecimal.ONE, log, ProfileEditor.TIME), log);
|
---|
87 | ValueSet v = new NumberValueSet(
|
---|
88 | new Range(BigDecimal.ZERO, BigDecimal.ONE, BigDecimal.ONE));
|
---|
89 | set.setCurrentValue(v);
|
---|
90 |
|
---|
91 | }
|
---|
92 |
|
---|
93 | @Test
|
---|
94 | public void testIncreaseBoth() throws Unacceptable {
|
---|
95 | NumberValueSetModel set = new NumberValueSetModel(
|
---|
96 | new NumberModel(BigDecimal.ZERO, log, ProfileEditor.TIME),
|
---|
97 | new NumberModel(BigDecimal.ONE, log, ProfileEditor.TIME),
|
---|
98 | new NumberModel(BigDecimal.ONE, log, ProfileEditor.TIME), log);
|
---|
99 | ValueSet v = new NumberValueSet(
|
---|
100 | new Range(BigDecimal.ONE, BigDecimal.TEN, BigDecimal.ONE));
|
---|
101 | set.setCurrentValue(v);
|
---|
102 | }
|
---|
103 |
|
---|
104 | @Test
|
---|
105 | public void testIncreaseBothMuch() throws Unacceptable {
|
---|
106 | NumberValueSetModel set = new NumberValueSetModel(
|
---|
107 | new NumberModel(BigDecimal.ZERO, log, ProfileEditor.TIME),
|
---|
108 | new NumberModel(BigDecimal.ONE, log, ProfileEditor.TIME),
|
---|
109 | new NumberModel(BigDecimal.ONE, log, ProfileEditor.TIME), log);
|
---|
110 | ValueSet v = new NumberValueSet(new Range(new BigDecimal("20"),
|
---|
111 | new BigDecimal("80"), BigDecimal.ONE));
|
---|
112 | set.setCurrentValue(v);
|
---|
113 | }
|
---|
114 |
|
---|
115 | @Test
|
---|
116 | public void testDecreaseBoth() throws Unacceptable {
|
---|
117 | NumberValueSetModel set = new NumberValueSetModel(
|
---|
118 | new NumberModel(BigDecimal.ONE, log, ProfileEditor.TIME),
|
---|
119 | new NumberModel(BigDecimal.TEN, log, ProfileEditor.TIME),
|
---|
120 | new NumberModel(BigDecimal.ONE, log, ProfileEditor.TIME), log);
|
---|
121 | ValueSet v = new NumberValueSet(
|
---|
122 | new Range(BigDecimal.ZERO, BigDecimal.ONE, BigDecimal.ONE));
|
---|
123 | set.setCurrentValue(v);
|
---|
124 | }
|
---|
125 |
|
---|
126 | @Test
|
---|
127 | public void testDecreaseBothMuch() throws Unacceptable {
|
---|
128 | NumberValueSetModel set = new NumberValueSetModel(
|
---|
129 | new NumberModel(new BigDecimal("20"), log, ProfileEditor.TIME),
|
---|
130 | new NumberModel(new BigDecimal("80"), log, ProfileEditor.TIME),
|
---|
131 | new NumberModel(BigDecimal.ONE, log, ProfileEditor.TIME), log);
|
---|
132 | ValueSet v = new NumberValueSet(
|
---|
133 | new Range(BigDecimal.ZERO, BigDecimal.ONE, BigDecimal.ONE));
|
---|
134 | set.setCurrentValue(v);
|
---|
135 | }
|
---|
136 |
|
---|
137 | }
|
---|