Skip to content

Commit 56e47eb

Browse files
committed
Added new tests
1 parent 4724084 commit 56e47eb

3 files changed

Lines changed: 124 additions & 3 deletions

File tree

liquidjava-verifier/pom.xml

Lines changed: 41 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
<project xmlns="http://maven.apache.org/POM/4.0.0"
2-
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
3-
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
2+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
43
<modelVersion>4.0.0</modelVersion>
54

65
<parent>
@@ -10,7 +9,7 @@
109
</parent>
1110

1211
<groupId>liquidjava-verifier
13-
</groupId>
12+
</groupId>
1413
<artifactId>liquidjava-verifier</artifactId>
1514
<version>5.2-SNAPSHOT</version>
1615
<name>liquidjava-verifier</name>
@@ -95,6 +94,45 @@
9594
</execution>
9695
</executions>
9796
</plugin>
97+
<plugin>
98+
<groupId>org.jacoco</groupId>
99+
<artifactId>jacoco-maven-plugin</artifactId>
100+
<version>0.8.14</version>
101+
<executions>
102+
<execution>
103+
<id>default-prepare-agent</id>
104+
<goals>
105+
<goal>prepare-agent</goal>
106+
</goals>
107+
</execution>
108+
<execution>
109+
<id>default-report</id>
110+
<goals>
111+
<goal>report</goal>
112+
</goals>
113+
</execution>
114+
<execution>
115+
<id>default-check</id>
116+
<goals>
117+
<goal>check</goal>
118+
</goals>
119+
<configuration>
120+
<rules>
121+
<rule>
122+
<element>BUNDLE</element>
123+
<limits>
124+
<limit>
125+
<counter>COMPLEXITY</counter>
126+
<value>COVEREDRATIO</value>
127+
<minimum>0.60</minimum>
128+
</limit>
129+
</limits>
130+
</rule>
131+
</rules>
132+
</configuration>
133+
</execution>
134+
</executions>
135+
</plugin>
98136
</plugins>
99137
</build>
100138

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
package liquidjava.ast.opt;
2+
3+
import static org.junit.jupiter.api.Assertions.assertEquals;
4+
5+
import org.junit.Test;
6+
7+
import liquidjava.rj_language.ast.BinaryExpression;
8+
import liquidjava.rj_language.ast.LiteralBoolean;
9+
import liquidjava.rj_language.ast.LiteralInt;
10+
import liquidjava.rj_language.opt.ConstantFolding;
11+
import liquidjava.rj_language.opt.derivation_node.ValDerivationNode;
12+
13+
public class TestOptimization {
14+
@Test
15+
public void testBinaryFold() {
16+
BinaryExpression b = new BinaryExpression(new LiteralInt(1), "+", new LiteralInt(2));
17+
18+
ValDerivationNode r = ConstantFolding.fold(new ValDerivationNode(b, null));
19+
assertEquals(r.getValue(), new LiteralInt(3));
20+
}
21+
22+
@Test
23+
public void testBinaryFoldBool() {
24+
// Given: true != false
25+
// Expected: true
26+
BinaryExpression b = new BinaryExpression(new LiteralBoolean(true), "!=", new LiteralBoolean(false));
27+
28+
ValDerivationNode r = ConstantFolding.fold(new ValDerivationNode(b, null));
29+
30+
// Then:
31+
assertEquals(r.getValue(), new LiteralBoolean(true), "Expect result to be true");
32+
}
33+
}
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
2+
package liquidjava.rj_language;
3+
4+
import static org.junit.jupiter.api.Assertions.assertFalse;
5+
import static org.junit.jupiter.api.Assertions.assertTrue;
6+
import static org.junit.Assert.assertNotEquals;
7+
8+
import org.junit.Test;
9+
import liquidjava.rj_language.ast.LiteralString;
10+
11+
public class TestLiteralString {
12+
13+
@Test
14+
public void testLiteralString() {
15+
LiteralString s1 = new LiteralString("hello");
16+
LiteralString s2 = new LiteralString("world");
17+
assertNotEquals(s1.hashCode(), s2.hashCode());
18+
}
19+
20+
@Test
21+
public void testLiteralStringEqualsClass() {
22+
// Given: s1.getClass() == LiteralString && s2.getClass() == String
23+
// Expected: False (LiteralString != String)
24+
25+
LiteralString s1 = new LiteralString("hello");
26+
String s2 = "hello";
27+
28+
// when
29+
boolean result = s1.equals(s2);
30+
31+
// Then:
32+
assertFalse(result, "Expected result to be False");
33+
}
34+
35+
@Test
36+
public void testLiteralStringEqualsNull() {
37+
// Given: s1 == null && s2 == null
38+
// Expected: True (null == null)
39+
40+
LiteralString s1 = new LiteralString(null);
41+
LiteralString s2 = new LiteralString(null);
42+
43+
// When
44+
boolean result = s1.equals(s2);
45+
46+
// Then
47+
assertTrue(result, "Expected result to be True");
48+
}
49+
50+
}

0 commit comments

Comments
 (0)