Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 41 additions & 3 deletions liquidjava-verifier/pom.xml
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
<project xmlns="http://maven.apache.org/POM/4.0.0"
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">
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">
<modelVersion>4.0.0</modelVersion>

<parent>
Expand All @@ -10,7 +9,7 @@
</parent>

<groupId>liquidjava-verifier
</groupId>
</groupId>
<artifactId>liquidjava-verifier</artifactId>
<version>5.2-SNAPSHOT</version>
<name>liquidjava-verifier</name>
Expand Down Expand Up @@ -95,6 +94,45 @@
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.jacoco</groupId>
<artifactId>jacoco-maven-plugin</artifactId>
<version>0.8.14</version>
<executions>
<execution>
<id>default-prepare-agent</id>
<goals>
<goal>prepare-agent</goal>
</goals>
</execution>
<execution>
<id>default-report</id>
<goals>
<goal>report</goal>
</goals>
</execution>
<execution>
<id>default-check</id>
<goals>
<goal>check</goal>
</goals>
<configuration>
<rules>
<rule>
<element>BUNDLE</element>
<limits>
<limit>
<counter>COMPLEXITY</counter>
<value>COVEREDRATIO</value>
<minimum>0.60</minimum>
</limit>
</limits>
</rule>
</rules>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
package liquidjava.ast.opt;

import static org.junit.jupiter.api.Assertions.assertEquals;

import org.junit.Test;

import liquidjava.rj_language.ast.BinaryExpression;
import liquidjava.rj_language.ast.LiteralBoolean;
import liquidjava.rj_language.ast.LiteralInt;
import liquidjava.rj_language.opt.ConstantFolding;
import liquidjava.rj_language.opt.derivation_node.ValDerivationNode;

public class TestOptimization {
@Test
public void testBinaryFold() {
BinaryExpression b = new BinaryExpression(new LiteralInt(1), "+", new LiteralInt(2));

ValDerivationNode r = ConstantFolding.fold(new ValDerivationNode(b, null));
assertEquals(r.getValue(), new LiteralInt(3));
}

@Test
public void testBinaryFoldBool() {
// Given: true != false
// Expected: true
BinaryExpression b = new BinaryExpression(new LiteralBoolean(true), "!=", new LiteralBoolean(false));

ValDerivationNode r = ConstantFolding.fold(new ValDerivationNode(b, null));

// Then:
assertEquals(r.getValue(), new LiteralBoolean(true), "Expect result to be true");
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@

package liquidjava.rj_language;

import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.junit.Assert.assertNotEquals;

import org.junit.Test;
import liquidjava.rj_language.ast.LiteralString;

public class TestLiteralString {

@Test
public void testLiteralString() {
LiteralString s1 = new LiteralString("hello");
LiteralString s2 = new LiteralString("world");
assertNotEquals(s1.hashCode(), s2.hashCode());
}

@Test
public void testLiteralStringEqualsClass() {
// Given: s1.getClass() == LiteralString && s2.getClass() == String
// Expected: False (LiteralString != String)

LiteralString s1 = new LiteralString("hello");
String s2 = "hello";

// when
boolean result = s1.equals(s2);

// Then:
assertFalse(result, "Expected result to be False");
}

@Test
public void testLiteralStringEqualsNull() {
// Given: s1 == null && s2 == null
// Expected: True (null == null)

LiteralString s1 = new LiteralString(null);
LiteralString s2 = new LiteralString(null);

// When
boolean result = s1.equals(s2);

// Then
assertTrue(result, "Expected result to be True");
}

}
Loading