|
13 | 13 | import java.nio.file.Path; |
14 | 14 | import java.nio.file.Paths; |
15 | 15 | import java.nio.file.StandardCopyOption; |
16 | | -import java.util.HashMap; |
17 | | -import java.util.Map; |
18 | 16 |
|
19 | 17 | import static org.junit.jupiter.api.Assertions.*; |
20 | 18 |
|
@@ -95,21 +93,31 @@ public void composedTypes() { |
95 | 93 | assertEquals(Z3Result.Status.SAT, result.getStatus(), "Response should be SAT for composed_types.smt"); |
96 | 94 |
|
97 | 95 | assertTrue(result.getSolution().containsKey("users1"), "Response should contain users1"); |
98 | | - Map<String, SMTLibValue> users1Expected = new HashMap<>(); |
99 | | - users1Expected.put("ID", new LongValue(3L)); |
100 | | - users1Expected.put("NAME", new StringValue("Alice")); |
101 | | - users1Expected.put("AGE", new LongValue(31L)); |
102 | | - users1Expected.put("POINTS", new LongValue(7L)); |
103 | | - |
104 | | - assertEquals(new StructValue(users1Expected), result.getSolution().get("users1"), "The value for users1 is incorrect"); |
105 | | - |
106 | 96 | assertTrue(result.getSolution().containsKey("users2"), "Response should contain users2"); |
107 | | - Map<String, SMTLibValue> users2Expected = new HashMap<>(); |
108 | | - users2Expected.put("ID", new LongValue(3L)); |
109 | | - users2Expected.put("NAME", new StringValue("Bob")); |
110 | | - users2Expected.put("AGE", new LongValue(31L)); |
111 | | - users2Expected.put("POINTS", new LongValue(7L)); |
112 | | - assertEquals(new StructValue(users2Expected), result.getSolution().get("users2"), "The value for users2 is incorrect"); |
| 97 | + |
| 98 | + // NOTE: assert the individual field VALUES, not StructValue equality: StructValue.equals only |
| 99 | + // compares the set of field names, so a whole-struct assertEquals would pass regardless of the |
| 100 | + // actual values Z3 returned. We assert the fully-constrained fields exactly (NAME, POINTS) and |
| 101 | + // the underconstrained fields against their SMT-LIB constraints (AGE range, distinct IDs). |
| 102 | + StructValue users1 = (StructValue) result.getSolution().get("users1"); |
| 103 | + StructValue users2 = (StructValue) result.getSolution().get("users2"); |
| 104 | + |
| 105 | + // NAME and POINTS are pinned by the SMT-LIB (NAME = "Alice"/"Bob", POINTS = 7), so deterministic. |
| 106 | + assertEquals(new StringValue("Alice"), users1.getField("NAME"), "NAME users1"); |
| 107 | + assertEquals(new StringValue("Bob"), users2.getField("NAME"), "NAME users2"); |
| 108 | + assertEquals(new LongValue(7L), users1.getField("POINTS"), "POINTS users1"); |
| 109 | + assertEquals(new LongValue(7L), users2.getField("POINTS"), "POINTS users2"); |
| 110 | + |
| 111 | + // AGE is constrained to (30, 100): assert the constraint holds rather than a specific value. |
| 112 | + long age1 = ((LongValue) users1.getField("AGE")).getValue(); |
| 113 | + long age2 = ((LongValue) users2.getField("AGE")).getValue(); |
| 114 | + assertTrue(age1 > 30 && age1 < 100, "AGE users1 out of range: " + age1); |
| 115 | + assertTrue(age2 > 30 && age2 < 100, "AGE users2 out of range: " + age2); |
| 116 | + |
| 117 | + // IDs must be distinct (the 'distinct' assertion over the PK). |
| 118 | + long id1 = ((LongValue) users1.getField("ID")).getValue(); |
| 119 | + long id2 = ((LongValue) users2.getField("ID")).getValue(); |
| 120 | + assertNotEquals(id1, id2, "user IDs must be distinct"); |
113 | 121 | } |
114 | 122 |
|
115 | 123 | /** |
|
0 commit comments