Skip to content

Commit f30c556

Browse files
Fix tests
1 parent e8af58a commit f30c556

1 file changed

Lines changed: 28 additions & 45 deletions

File tree

client-java/controller/src/test/java/org/evomaster/client/java/controller/cassandra/calculator/CassandraHeuristicsCalculatorTest.java

Lines changed: 28 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,7 @@
1111
import java.time.LocalTime;
1212
import java.util.*;
1313

14-
import static org.junit.jupiter.api.Assertions.assertEquals;
15-
import static org.junit.jupiter.api.Assertions.assertTrue;
14+
import static org.junit.jupiter.api.Assertions.*;
1615

1716
public class CassandraHeuristicsCalculatorTest {
1817

@@ -34,6 +33,15 @@ private double distNoRows(String cql) {
3433

3534
private static final double DELTA = 1e-9;
3635

36+
/**
37+
* Expected distance for a single-row table whose WHERE-clause condition evaluates to
38+
* {@code FALSE_TRUTHNESS} for that row (e.g. because the queried column is absent from it).
39+
* H-Row-set is definitely true (one row is present), so H-Query is the average of
40+
* {@code 1.0} and H-Condition, i.e. {@code buildScaledTruthness(C, C).ofTrue}.
41+
*/
42+
private static final double MISSING_COLUMN_DISTANCE =
43+
1.0 - (1.0 + (DistanceHelper.H_NOT_NULL + (1 - DistanceHelper.H_NOT_NULL) * DistanceHelper.H_NOT_NULL)) / 2.0;
44+
3745
@Test
3846
void noWhere_emptyTable_maxDistance() {
3947
// H-Table(0 rows) = FALSE_TRUTHNESS → ofTrue = C → distance = 1 - C
@@ -352,14 +360,11 @@ void in_singleElementList_match_zeroDistance() {
352360
assertEquals(0.0, dist("SELECT * FROM t WHERE col IN (42)", row("col", 42L)), DELTA);
353361
}
354362

355-
@Test
356-
void in_nullRowValue_nonZeroDistance() {
357-
assertTrue(dist("SELECT * FROM t WHERE col IN (1, 2, 3)", row("col", null)) > 0.0);
358-
}
359-
360363
@Test
361364
void in_missingColumn_nonZeroDistance() {
362-
assertTrue(dist("SELECT * FROM t WHERE col IN (1, 2, 3)", row("other", 99L)) > 0.0);
365+
assertEquals(MISSING_COLUMN_DISTANCE,
366+
dist("SELECT * FROM t WHERE col IN (1, 2, 3)", row("other", 99L)),
367+
DELTA);
363368
}
364369

365370
// CONTAINS operator
@@ -412,14 +417,11 @@ void contains_map_valueMissing_nonZero() {
412417
assertTrue(d > 0.0);
413418
}
414419

415-
@Test
416-
void contains_nullColumn_nonZeroDistance() {
417-
assertTrue(dist("SELECT * FROM t WHERE col CONTAINS 1", row("col", null)) > 0.0);
418-
}
419-
420420
@Test
421421
void contains_missingColumn_nonZeroDistance() {
422-
assertTrue(dist("SELECT * FROM t WHERE col CONTAINS 1", row("other", 99L)) > 0.0);
422+
assertEquals(MISSING_COLUMN_DISTANCE,
423+
dist("SELECT * FROM t WHERE col CONTAINS 1", row("other", 99L)),
424+
DELTA);
423425
}
424426

425427
@Test
@@ -475,45 +477,26 @@ void containsKey_closerKeyGivesBetterScore() {
475477
}
476478

477479
@Test
478-
void containsKey_nullColumn_nonZeroDistance() {
479-
assertTrue(dist("SELECT * FROM t WHERE col CONTAINS KEY 'x'", row("col", null)) > 0.0);
480+
void containsKey_missingColumn_nonZeroDistance() {
481+
assertEquals(MISSING_COLUMN_DISTANCE,
482+
dist("SELECT * FROM t WHERE col CONTAINS KEY 'x'", row("other", 99L)),
483+
DELTA);
480484
}
481485

482486
@Test
483-
void containsKey_nonMapColumn_nonZeroDistance() {
484-
assertTrue(dist("SELECT * FROM t WHERE col CONTAINS KEY 'x'",
485-
row("col", Arrays.asList("a", "b"))) > 0.0);
487+
void containsKey_nonMapColumn_throws() {
488+
CassandraRow row = row("col", Arrays.asList("a", "b"));
489+
assertThrows(IllegalArgumentException.class,
490+
() -> dist("SELECT * FROM t WHERE col CONTAINS KEY 'x'", row));
486491
}
487492

488-
// NULL handling
489-
490-
@Test
491-
void nullRowValue_returnsHighDistance() {
492-
double d = dist("SELECT * FROM t WHERE col = 1", row("col", null));
493-
assertTrue(d > 0.0);
494-
}
493+
// Missing column handling
495494

496495
@Test
497496
void missingColumn_returnsHighDistance() {
498-
double d = dist("SELECT * FROM t WHERE col = 1", row("other", 99L));
499-
assertTrue(d > 0.0);
500-
}
501-
502-
@Test
503-
void nullCell_notWorseThanMissingColumn() {
504-
// NULL cell → FALSE_TRUTHNESS_BETTER (C_BETTER=0.15 > C=0.1)
505-
// Missing column → FALSE_TRUTHNESS (C=0.1)
506-
// So NULL cell ofTrue > missing column ofTrue → distance(null) < distance(missing)
507-
double dNull = dist("SELECT * FROM t WHERE col = 1", row("col", null));
508-
double dMissing = dist("SELECT * FROM t WHERE col = 1", row("other", 99L));
509-
assertTrue(dNull <= dMissing);
510-
}
511-
512-
@Test
513-
void bothNullQueryAndRow_falseDistance() {
514-
// Both NULL → FALSE_TRUTHNESS, not zero distance
515-
double d = dist("SELECT * FROM t WHERE col = NULL", row("col", null));
516-
assertTrue(d > 0.0);
497+
assertEquals(MISSING_COLUMN_DISTANCE,
498+
dist("SELECT * FROM t WHERE col = 1", row("other", 99L)),
499+
DELTA);
517500
}
518501

519502
// Multi-row scenarios

0 commit comments

Comments
 (0)