Skip to content

Commit 34e49c5

Browse files
committed
Increased coverage in interpreternew.values
1 parent 1c4906c commit 34e49c5

12 files changed

+425
-16
lines changed

rosetta-lang/src/main/java/com/regnosys/rosetta/interpreternew/values/RosettaInterpreterError.java

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,20 @@
1717
import com.regnosys.rosetta.rosetta.interpreter.RosettaInterpreterBaseError;
1818

1919
public class RosettaInterpreterError implements RosettaInterpreterBaseError {
20+
private String errorMessage;
21+
22+
public RosettaInterpreterError(String errorMessage) {
23+
super();
24+
this.errorMessage = errorMessage;
25+
}
26+
27+
public String getError() { return errorMessage; }
28+
29+
@Override
30+
public String toString() {
31+
return "RosettaInterpreterError [errorMessage=" + errorMessage + "]";
32+
}
33+
2034
@Override
2135
public int hashCode() {
2236
return Objects.hash(errorMessage);
@@ -37,20 +51,6 @@ public boolean equals(Object obj) {
3751
return Objects.equals(errorMessage, other.errorMessage);
3852
}
3953

40-
private String errorMessage;
41-
42-
public RosettaInterpreterError(String errorMessage) {
43-
super();
44-
this.errorMessage = errorMessage;
45-
}
46-
47-
public String getError() { return errorMessage; }
48-
49-
@Override
50-
public String toString() {
51-
return "RosettaInterpreterError [errorMessage=" + errorMessage + "]";
52-
}
53-
5454
@Override
5555
public EClass eClass() {
5656
// TODO Auto-generated method stub

rosetta-lang/src/main/java/com/regnosys/rosetta/interpreternew/values/RosettaInterpreterErrorValue.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88
import org.eclipse.emf.common.util.BasicEList;
99
import org.eclipse.emf.common.util.EList;
1010

11-
import com.regnosys.rosetta.interpreternew.RosettaInterpreterNewException;
1211
import com.regnosys.rosetta.rosetta.interpreter.RosettaInterpreterBaseError;
1312
import com.regnosys.rosetta.rosetta.interpreter.RosettaInterpreterValue;
1413

rosetta-lang/src/main/java/com/regnosys/rosetta/interpreternew/values/RosettaInterpreterListValue.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ public int hashCode() {
2121

2222
@Override
2323
public String toString() {
24-
return "RosettaInterpreterListValue [expressions=" + expressions + "]";
24+
return "RosettaInterpreterListValue [expressions=" + expressions.toString() + "]";
2525
}
2626

2727
@Override

rosetta-lang/src/main/java/com/regnosys/rosetta/interpreternew/values/RosettaInterpreterNumberValue.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,4 +65,9 @@ public Stream<RosettaInterpreterValue> toValueStream() {
6565
return Stream.of(this);
6666
}
6767

68+
@Override
69+
public String toString() {
70+
return "RosettaInterpreterNumberValue [" + value.toString() + "]";
71+
}
72+
6873
}

rosetta-lang/src/main/java/com/regnosys/rosetta/interpreternew/values/RosettaInterpreterStringValue.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,4 +61,9 @@ public Stream<RosettaInterpreterValue> toValueStream() {
6161
return Stream.of(this);
6262
}
6363

64+
@Override
65+
public String toString() {
66+
return "RosettaInterpreterStringValue [" + value + "]";
67+
}
68+
6469
}
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
package com.regnosys.rosetta.interpreternew.value;
2+
3+
import static org.junit.jupiter.api.Assertions.assertEquals;
4+
import static org.junit.jupiter.api.Assertions.assertFalse;
5+
import static org.junit.jupiter.api.Assertions.assertTrue;
6+
7+
import java.math.BigDecimal;
8+
import java.util.ArrayList;
9+
import java.util.List;
10+
import java.util.stream.Collectors;
11+
12+
import org.junit.jupiter.api.Test;
13+
14+
import com.regnosys.rosetta.interpreternew.values.RosettaInterpreterBooleanValue;
15+
import com.regnosys.rosetta.interpreternew.values.RosettaInterpreterNumberValue;
16+
17+
public class RosettaInterpreterBooleanValueTest {
18+
19+
@Test
20+
void equalsGoodWeatherTest() {
21+
RosettaInterpreterBooleanValue b1 = new RosettaInterpreterBooleanValue(true);
22+
RosettaInterpreterBooleanValue b2 = new RosettaInterpreterBooleanValue(true);
23+
24+
assertTrue(b1.equals(b1));
25+
assertTrue(b1.equals(b2));
26+
}
27+
28+
@Test
29+
void equalsBadWeatherTest() {
30+
RosettaInterpreterBooleanValue b1 = new RosettaInterpreterBooleanValue(true);
31+
RosettaInterpreterBooleanValue b2 = new RosettaInterpreterBooleanValue(false);
32+
33+
assertFalse(b1.equals(b2));
34+
assertFalse(b1.equals(null));
35+
assertFalse(b1.equals(true));
36+
}
37+
38+
@Test
39+
void streamElementTest() {
40+
RosettaInterpreterBooleanValue b1 = new RosettaInterpreterBooleanValue(true);
41+
List<Object> result = new ArrayList<Object>();
42+
result.add(true);
43+
44+
assertEquals(result, b1.toElementStream().collect(Collectors.toList()));
45+
}
46+
47+
@Test
48+
void toStringTest() {
49+
RosettaInterpreterBooleanValue b1 = new RosettaInterpreterBooleanValue(true);
50+
51+
assertEquals("RosettaInterpreterBooleanValue [value=true]", b1.toString());
52+
}
53+
54+
}
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
package com.regnosys.rosetta.interpreternew.value;
2+
3+
import static org.junit.jupiter.api.Assertions.assertEquals;
4+
5+
import java.util.HashMap;
6+
import java.util.Map;
7+
8+
import org.junit.jupiter.api.Test;
9+
10+
import com.regnosys.rosetta.interpreternew.values.RosettaInterpreterBaseValue;
11+
import com.regnosys.rosetta.interpreternew.values.RosettaInterpreterEnvironment;
12+
import com.regnosys.rosetta.interpreternew.values.RosettaInterpreterNumberValue;
13+
14+
public class RosettaInterpreterEnvironmentTest {
15+
16+
@Test
17+
void replaceValueTest() {
18+
Map<String, RosettaInterpreterBaseValue> map = new HashMap<>();
19+
map.put("a", new RosettaInterpreterNumberValue(2));
20+
21+
RosettaInterpreterEnvironment env = new RosettaInterpreterEnvironment(map);
22+
23+
env.addValue("a", new RosettaInterpreterNumberValue(3));
24+
25+
Map<String, RosettaInterpreterBaseValue> updatedMap = new HashMap<>();
26+
updatedMap.put("a", new RosettaInterpreterNumberValue(3));
27+
28+
assertEquals(updatedMap, env.getEnvironment());
29+
30+
}
31+
32+
}
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
package com.regnosys.rosetta.interpreternew.value;
2+
3+
import static org.junit.jupiter.api.Assertions.assertEquals;
4+
import static org.junit.jupiter.api.Assertions.assertFalse;
5+
import static org.junit.jupiter.api.Assertions.assertNotEquals;
6+
import static org.junit.jupiter.api.Assertions.assertTrue;
7+
8+
import org.junit.jupiter.api.Test;
9+
10+
import com.regnosys.rosetta.interpreternew.values.RosettaInterpreterError;
11+
12+
public class RosettaInterpreterErrorTest {
13+
14+
@Test
15+
void hashTest() {
16+
RosettaInterpreterError e1 = new RosettaInterpreterError("error1");
17+
RosettaInterpreterError e2 = new RosettaInterpreterError("error1");
18+
RosettaInterpreterError e3 = new RosettaInterpreterError("error3");
19+
20+
assertEquals(e1.hashCode(), e2.hashCode());
21+
assertNotEquals(e1.hashCode(), e3.hashCode());
22+
}
23+
24+
@Test
25+
void equalsGoodWeatherTest() {
26+
RosettaInterpreterError e1 = new RosettaInterpreterError("error1");
27+
RosettaInterpreterError e2 = new RosettaInterpreterError("error1");
28+
29+
assertTrue(e1.equals(e1));
30+
assertTrue(e1.equals(e2));
31+
}
32+
33+
@Test
34+
void equalsBadWeatherTest() {
35+
RosettaInterpreterError e1 = new RosettaInterpreterError("error1");
36+
RosettaInterpreterError e2 = new RosettaInterpreterError("error2");
37+
38+
assertFalse(e1.equals(e2));
39+
assertFalse(e1.equals(null));
40+
assertFalse(e1.equals("notAnError"));
41+
}
42+
43+
@Test
44+
void toStringTest() {
45+
RosettaInterpreterError e1 = new RosettaInterpreterError("error1");
46+
47+
assertEquals("RosettaInterpreterError [errorMessage=error1]", e1.toString());
48+
}
49+
}

rosetta-testing/src/test/java/com/regnosys/rosetta/interpreternew/value/RosettaInterpreterErrorValueTest.java

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,15 @@
66

77
import java.util.ArrayList;
88
import java.util.List;
9+
import java.util.stream.Collectors;
910

1011
import org.junit.jupiter.api.BeforeEach;
1112
import org.junit.jupiter.api.Test;
1213

1314
import com.regnosys.rosetta.interpreternew.values.RosettaInterpreterErrorValue;
15+
import com.regnosys.rosetta.rosetta.interpreter.RosettaInterpreterBaseError;
1416
import com.regnosys.rosetta.rosetta.interpreter.RosettaInterpreterValue;
17+
import com.regnosys.rosetta.interpreternew.values.RosettaInterpreterBaseValue;
1518
import com.regnosys.rosetta.interpreternew.values.RosettaInterpreterBooleanValue;
1619
import com.regnosys.rosetta.interpreternew.values.RosettaInterpreterError;
1720

@@ -30,6 +33,10 @@ class RosettaInterpreterErrorValueTest {
3033
RosettaInterpreterBooleanValue vb1;
3134
List<RosettaInterpreterValue> vals;
3235

36+
RosettaInterpreterBaseError b1;
37+
RosettaInterpreterBaseError b2;
38+
List<RosettaInterpreterBaseError> baseErr;
39+
3340
@BeforeEach
3441
void setup() {
3542
e1 = new RosettaInterpreterError("e1");
@@ -42,6 +49,10 @@ void setup() {
4249
vb1 = new RosettaInterpreterBooleanValue(true);
4350
vb2 = new RosettaInterpreterBooleanValue(false);
4451
vals = new ArrayList<>(List.of(v1,v2,v3,vb1,vb2));
52+
53+
b1 = new RosettaInterpreterError("b1");
54+
b2 = new RosettaInterpreterError("b2");
55+
baseErr = new ArrayList<>(List.of(b1,b2));
4556
}
4657

4758
@Test
@@ -118,4 +129,33 @@ void testMergeRosettaInterpreterValueRosettaInterpreterValue() {
118129
assertEquals(val, RosettaInterpreterErrorValue.merge(v2, v3));
119130
}
120131

132+
@Test
133+
void hashTest() {
134+
RosettaInterpreterErrorValue err1 = new RosettaInterpreterErrorValue(baseErr);
135+
RosettaInterpreterErrorValue err2 = new RosettaInterpreterErrorValue(baseErr);
136+
137+
assertEquals(err1.hashCode(), err2.hashCode());
138+
}
139+
140+
@Test
141+
void toStringTest() {
142+
assertEquals(
143+
"RosettaInterpreterErrorValue [errors=[RosettaInterpreterError [errorMessage=e1]]]",
144+
v1.toString());
145+
}
146+
147+
@Test
148+
void streamElementTest() {
149+
List<Object> result = new ArrayList<Object>();
150+
result.add(e1);
151+
152+
assertEquals(result, v1.toElementStream().collect(Collectors.toList()).get(0));
153+
}
154+
155+
@Test
156+
void equalsBadWeatherTest() {
157+
assertFalse(v1.equals(null));
158+
assertFalse(v1.equals("error"));
159+
}
160+
121161
}
Lines changed: 98 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,98 @@
1+
package com.regnosys.rosetta.interpreternew.value;
2+
3+
import static org.junit.jupiter.api.Assertions.assertEquals;
4+
import static org.junit.jupiter.api.Assertions.assertFalse;
5+
import static org.junit.jupiter.api.Assertions.assertNotEquals;
6+
import static org.junit.jupiter.api.Assertions.assertTrue;
7+
8+
import java.math.BigDecimal;
9+
import java.util.ArrayList;
10+
import java.util.List;
11+
import java.util.stream.Collectors;
12+
13+
import org.junit.jupiter.api.Test;
14+
15+
import com.regnosys.rosetta.interpreternew.values.RosettaInterpreterListValue;
16+
import com.regnosys.rosetta.interpreternew.values.RosettaInterpreterNumberValue;
17+
18+
public class RosettaInterpreterListValueTest {
19+
20+
@Test
21+
void hashTest() {
22+
RosettaInterpreterListValue l1 =
23+
new RosettaInterpreterListValue(List.of(
24+
new RosettaInterpreterNumberValue(BigDecimal.valueOf(1)),
25+
new RosettaInterpreterNumberValue(BigDecimal.valueOf(2))));
26+
RosettaInterpreterListValue l2 =
27+
new RosettaInterpreterListValue(List.of(
28+
new RosettaInterpreterNumberValue(BigDecimal.valueOf(1)),
29+
new RosettaInterpreterNumberValue(BigDecimal.valueOf(2))));
30+
RosettaInterpreterListValue l3 =
31+
new RosettaInterpreterListValue(List.of(
32+
new RosettaInterpreterNumberValue(BigDecimal.valueOf(1)),
33+
new RosettaInterpreterNumberValue(BigDecimal.valueOf(3))));
34+
35+
assertEquals(l1.hashCode(), l2.hashCode());
36+
assertNotEquals(l1.hashCode(), l3.hashCode());
37+
38+
}
39+
40+
@Test
41+
void equalsGoodWeatherTest() {
42+
RosettaInterpreterListValue l1 =
43+
new RosettaInterpreterListValue(List.of(
44+
new RosettaInterpreterNumberValue(BigDecimal.valueOf(1)),
45+
new RosettaInterpreterNumberValue(BigDecimal.valueOf(2))));
46+
RosettaInterpreterListValue l2 =
47+
new RosettaInterpreterListValue(List.of(
48+
new RosettaInterpreterNumberValue(BigDecimal.valueOf(1)),
49+
new RosettaInterpreterNumberValue(BigDecimal.valueOf(2))));
50+
51+
assertTrue(l1.equals(l1));
52+
assertTrue(l1.equals(l2));
53+
54+
}
55+
56+
@Test
57+
void equalsBadWeatherTest() {
58+
RosettaInterpreterListValue l1 =
59+
new RosettaInterpreterListValue(List.of(
60+
new RosettaInterpreterNumberValue(BigDecimal.valueOf(1)),
61+
new RosettaInterpreterNumberValue(BigDecimal.valueOf(2))));
62+
RosettaInterpreterListValue l2 =
63+
new RosettaInterpreterListValue(List.of(
64+
new RosettaInterpreterNumberValue(BigDecimal.valueOf(1)),
65+
new RosettaInterpreterNumberValue(BigDecimal.valueOf(3))));
66+
67+
assertFalse(l1.equals(l2));
68+
assertFalse(l1.equals(null));
69+
assertFalse(l1.equals("hey"));
70+
}
71+
72+
@Test
73+
void toStringTest() {
74+
RosettaInterpreterListValue l1 =
75+
new RosettaInterpreterListValue(List.of(
76+
new RosettaInterpreterNumberValue(BigDecimal.valueOf(1)),
77+
new RosettaInterpreterNumberValue(BigDecimal.valueOf(2))));
78+
79+
assertEquals("RosettaInterpreterListValue "
80+
+ "[expressions=[RosettaInterpreterNumberValue [1], "
81+
+ "RosettaInterpreterNumberValue [2]]]",
82+
l1.toString());
83+
}
84+
85+
@Test
86+
void streamElementTest() {
87+
RosettaInterpreterListValue l1 =
88+
new RosettaInterpreterListValue(List.of(
89+
new RosettaInterpreterNumberValue(BigDecimal.valueOf(1)),
90+
new RosettaInterpreterNumberValue(BigDecimal.valueOf(2))));
91+
92+
List<Object> result = new ArrayList<Object>();
93+
result.add(new RosettaInterpreterNumberValue(BigDecimal.valueOf(1)));
94+
result.add(new RosettaInterpreterNumberValue(BigDecimal.valueOf(2)));
95+
96+
assertEquals(result, l1.toElementStream().collect(Collectors.toList()));
97+
}
98+
}

0 commit comments

Comments
 (0)