Skip to content

Commit f1fc348

Browse files
committed
java tests: fix path resolution and BigDecimal value comparison
Pass the Gradle project directory to tests as the ladybug.projectDir system property so TestHelper can build absolute paths to dataset files regardless of the working directory at test time. ValueTest.testCreateValue: BigDecimal comparison now uses compareTo() instead of equals() to handle scale differences (e.g. 1.5 vs 1.50). Also fix two places in the map test loop that reused a stale LbugMap reference instead of constructing a fresh one from the current tuple.
1 parent d384bc2 commit f1fc348

3 files changed

Lines changed: 24 additions & 6 deletions

File tree

build.gradle

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,7 @@ tasks.sourcesJar {
130130

131131
test {
132132
useJUnitPlatform()
133+
systemProperty 'ladybug.projectDir', projectDir.absolutePath
133134
testLogging {
134135
events 'passed', 'skipped', 'failed'
135136
exceptionFormat = 'full'

src/test/java/com/lbugdb/TestHelper.java

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,17 @@
33
import java.io.BufferedReader;
44
import java.io.FileReader;
55
import java.io.IOException;
6+
import java.nio.file.Path;
7+
import java.nio.file.Paths;
68
import java.util.regex.Matcher;
79
import java.util.regex.Pattern;
810

911
public class TestHelper {
1012
private static Database db;
1113
private static Connection conn;
12-
private final static String tinysnbDir = "../../dataset/tinysnb/";
14+
private static final Path projectDir = Paths.get(System.getProperty("ladybug.projectDir", "."));
15+
private static final Path tinysnbDir = projectDir.resolve("../../dataset/tinysnb").normalize();
16+
private static final Path tinysnbSerialDir = projectDir.resolve("../../dataset/tinysnb-serial").normalize();
1317
private final static String extensions = "csv|parquet|npy|ttl|nq|json|lbug_extension";
1418
private final static Pattern dataFileRegex = Pattern.compile("\"([^\"]+\\.(" + extensions + "))\"", Pattern.CASE_INSENSITIVE);
1519

@@ -28,7 +32,7 @@ public static void loadData(String dbPath) throws IOException {
2832

2933
String line;
3034

31-
reader = new BufferedReader(new FileReader(tinysnbDir + "schema.cypher"));
35+
reader = new BufferedReader(new FileReader(tinysnbDir.resolve("schema.cypher").toFile()));
3236
while ((line = reader.readLine()) != null) {
3337
line = line.trim();
3438
if (line.isEmpty()) {
@@ -40,7 +44,7 @@ public static void loadData(String dbPath) throws IOException {
4044
reader.close();
4145

4246

43-
reader = new BufferedReader(new FileReader(tinysnbDir + "copy.cypher"));
47+
reader = new BufferedReader(new FileReader(tinysnbDir.resolve("copy.cypher").toFile()));
4448
while ((line = reader.readLine()) != null) {
4549
line = line.trim();
4650
if (line.isEmpty()) {
@@ -49,7 +53,7 @@ public static void loadData(String dbPath) throws IOException {
4953

5054
// handle multiple data files in one statement
5155
Matcher matcher = dataFileRegex.matcher(line);
52-
String statement = matcher.replaceAll("\"" + tinysnbDir + "$1\"");
56+
String statement = matcher.replaceAll("\"" + tinysnbDir.resolve("$1").normalize() + "\"");
5357

5458
try (QueryResult result = conn.query(statement)) {}
5559
}
@@ -59,7 +63,8 @@ public static void loadData(String dbPath) throws IOException {
5963
try (QueryResult result = conn.query("create node table moviesSerial (ID SERIAL, name STRING, length INT32, note STRING, PRIMARY KEY (ID));")) {
6064
}
6165

62-
try (QueryResult result = conn.query("copy moviesSerial from \"../../dataset/tinysnb-serial/vMovies.csv\"")) {
66+
try (QueryResult result = conn.query("copy moviesSerial from \"" +
67+
tinysnbSerialDir.resolve("vMovies.csv").normalize() + "\"")) {
6368
}
6469
}
6570
}

src/test/java/com/lbugdb/ValueTest.java

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,17 @@ void checkValueConversion(Value val) {
2222
QueryResult result = conn.execute(preparedStatement, parameters);
2323
if (result.hasNext()) {
2424
Value cur = result.getNext().getValue(0);
25-
assertTrue(val.isNull() && cur.isNull() || val.getValue().equals(cur.getValue()));
25+
if (val.isNull() || cur.isNull()) {
26+
assertTrue(val.isNull() && cur.isNull());
27+
return;
28+
}
29+
Object expected = val.getValue();
30+
Object actual = cur.getValue();
31+
if (expected instanceof BigDecimal && actual instanceof BigDecimal) {
32+
assertEquals(0, ((BigDecimal) expected).compareTo((BigDecimal) actual));
33+
} else {
34+
assertTrue(val.isNull() && cur.isNull() || expected.equals(actual));
35+
}
2636
}
2737
}
2838
}
@@ -1522,6 +1532,7 @@ void MapValGetKey() {
15221532

15231533
flatTuple = result.getNext();
15241534
value = flatTuple.getValue(0);
1535+
mapVal = new LbugMap(value);
15251536
assertTrue(value.isOwnedByCPP());
15261537
key = mapVal.getKey(0);
15271538
assertNull(key);
@@ -1530,6 +1541,7 @@ void MapValGetKey() {
15301541

15311542
flatTuple = result.getNext();
15321543
value = flatTuple.getValue(0);
1544+
mapVal = new LbugMap(value);
15331545
assertTrue(value.isOwnedByCPP());
15341546
key = mapVal.getKey(0);
15351547
fieldName = key.getValue();

0 commit comments

Comments
 (0)