|
|
|
@ -107,6 +107,14 @@ public class DefineListTest { |
|
|
|
|
dl.set(BOOL_VAR, false); |
|
|
|
|
assert dl.hashCode() == 0; |
|
|
|
|
assert generateSource(dl).equals(""); |
|
|
|
|
|
|
|
|
|
dl.set(BOOL_VAR, true); |
|
|
|
|
assert dl.hashCode() == 1; |
|
|
|
|
assert generateSource(dl).equals("#define BOOL_VAR 1\n"); |
|
|
|
|
|
|
|
|
|
dl.unset(BOOL_VAR); |
|
|
|
|
assert dl.hashCode() == 0; |
|
|
|
|
assert generateSource(dl).equals(""); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
@ -120,8 +128,8 @@ public class DefineListTest { |
|
|
|
|
assert generateSource(dl).equals("#define INT_VAR 123\n"); |
|
|
|
|
|
|
|
|
|
dl.set(INT_VAR, 0); |
|
|
|
|
assert dl.hashCode() == 0; |
|
|
|
|
assert generateSource(dl).equals(""); |
|
|
|
|
assert dl.hashCode() == hashCodeWithInt; |
|
|
|
|
assert generateSource(dl).equals("#define INT_VAR 0\n"); |
|
|
|
|
|
|
|
|
|
dl.set(INT_VAR, -99); |
|
|
|
|
assert dl.hashCode() == hashCodeWithInt; |
|
|
|
@ -130,6 +138,10 @@ public class DefineListTest { |
|
|
|
|
dl.set(INT_VAR, Integer.MAX_VALUE); |
|
|
|
|
assert dl.hashCode() == hashCodeWithInt; |
|
|
|
|
assert generateSource(dl).equals("#define INT_VAR 2147483647\n"); |
|
|
|
|
|
|
|
|
|
dl.unset(INT_VAR); |
|
|
|
|
assert dl.hashCode() == 0; |
|
|
|
|
assert generateSource(dl).equals(""); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
@ -141,8 +153,8 @@ public class DefineListTest { |
|
|
|
|
assert generateSource(dl).equals("#define FLOAT_VAR 1.0\n"); |
|
|
|
|
|
|
|
|
|
dl.set(FLOAT_VAR, 0f); |
|
|
|
|
assert dl.hashCode() == 0; |
|
|
|
|
assert generateSource(dl).equals(""); |
|
|
|
|
assert dl.hashCode() == (1 << FLOAT_VAR); |
|
|
|
|
assert generateSource(dl).equals("#define FLOAT_VAR 0.0\n"); |
|
|
|
|
|
|
|
|
|
dl.set(FLOAT_VAR, -1f); |
|
|
|
|
assert generateSource(dl).equals("#define FLOAT_VAR -1.0\n"); |
|
|
|
@ -157,19 +169,22 @@ public class DefineListTest { |
|
|
|
|
dl.set(FLOAT_VAR, Float.NaN); |
|
|
|
|
generateSource(dl); |
|
|
|
|
assert false; |
|
|
|
|
} catch (IllegalArgumentException ex) { } |
|
|
|
|
} catch (IllegalArgumentException ex) { |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
try { |
|
|
|
|
dl.set(FLOAT_VAR, Float.POSITIVE_INFINITY); |
|
|
|
|
generateSource(dl); |
|
|
|
|
assert false; |
|
|
|
|
} catch (IllegalArgumentException ex) { } |
|
|
|
|
} catch (IllegalArgumentException ex) { |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
try { |
|
|
|
|
dl.set(FLOAT_VAR, Float.NEGATIVE_INFINITY); |
|
|
|
|
generateSource(dl); |
|
|
|
|
assert false; |
|
|
|
|
} catch (IllegalArgumentException ex) { } |
|
|
|
|
} catch (IllegalArgumentException ex) { |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
@ -177,31 +192,50 @@ public class DefineListTest { |
|
|
|
|
DefineList dl1 = new DefineList(NUM_DEFINES); |
|
|
|
|
DefineList dl2 = new DefineList(NUM_DEFINES); |
|
|
|
|
|
|
|
|
|
assertTrue(dl1.hashCode() == 0); |
|
|
|
|
assertEquals(0, dl1.hashCode()); |
|
|
|
|
assertEquals(0, dl2.hashCode()); |
|
|
|
|
assertEquals(dl1, dl2); |
|
|
|
|
|
|
|
|
|
dl1.set(BOOL_VAR, true); |
|
|
|
|
|
|
|
|
|
assertTrue(dl1.hashCode() == 1); |
|
|
|
|
assertNotSame(dl1, dl2); |
|
|
|
|
assertEquals(1, dl1.hashCode()); |
|
|
|
|
assertEquals(0, dl2.hashCode()); |
|
|
|
|
assertNotEquals(dl1, dl2); |
|
|
|
|
|
|
|
|
|
dl2.set(BOOL_VAR, true); |
|
|
|
|
|
|
|
|
|
assertEquals(1, dl1.hashCode()); |
|
|
|
|
assertEquals(1, dl2.hashCode()); |
|
|
|
|
assertEquals(dl1, dl2); |
|
|
|
|
|
|
|
|
|
dl1.set(INT_VAR, 2); |
|
|
|
|
|
|
|
|
|
assertTrue(dl1.hashCode() == (1|2)); |
|
|
|
|
assertNotSame(dl1, dl2); |
|
|
|
|
assertEquals(1 | 2, dl1.hashCode()); |
|
|
|
|
assertEquals(1, dl2.hashCode()); |
|
|
|
|
assertNotEquals(dl1, dl2); |
|
|
|
|
|
|
|
|
|
dl2.set(INT_VAR, 2); |
|
|
|
|
|
|
|
|
|
assertEquals(1 | 2, dl1.hashCode()); |
|
|
|
|
assertEquals(1 | 2, dl2.hashCode()); |
|
|
|
|
assertEquals(dl1, dl2); |
|
|
|
|
|
|
|
|
|
dl1.set(BOOL_VAR, false); |
|
|
|
|
|
|
|
|
|
assertTrue(dl1.hashCode() == 2); |
|
|
|
|
assertNotSame(dl1, dl2); |
|
|
|
|
assertEquals(2, dl1.hashCode()); |
|
|
|
|
assertEquals(1 | 2, dl2.hashCode()); |
|
|
|
|
assertNotEquals(dl1, dl2); |
|
|
|
|
|
|
|
|
|
dl2.unset(BOOL_VAR); |
|
|
|
|
|
|
|
|
|
assertEquals(2, dl1.hashCode()); |
|
|
|
|
assertEquals(2, dl2.hashCode()); |
|
|
|
|
assertEquals(dl1, dl2); // unset is the same as false
|
|
|
|
|
|
|
|
|
|
dl1.unset(BOOL_VAR); |
|
|
|
|
assertEquals(2, dl1.hashCode()); |
|
|
|
|
assertEquals(2, dl2.hashCode()); |
|
|
|
|
assertEquals(dl1, dl2); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
@ -209,25 +243,31 @@ public class DefineListTest { |
|
|
|
|
DefineList dl1 = new DefineList(NUM_DEFINES); |
|
|
|
|
DefineList dl2 = dl1.deepClone(); |
|
|
|
|
|
|
|
|
|
assertFalse(dl1 == dl2); |
|
|
|
|
assertTrue(dl1.equals(dl2)); |
|
|
|
|
assertTrue(dl1.hashCode() == dl2.hashCode()); |
|
|
|
|
assertNotSame(dl1, dl2); |
|
|
|
|
assertEquals(dl1, dl2); |
|
|
|
|
assertEquals(dl1.hashCode(), dl2.hashCode()); |
|
|
|
|
|
|
|
|
|
dl1.set(BOOL_VAR, true); |
|
|
|
|
dl2 = dl1.deepClone(); |
|
|
|
|
|
|
|
|
|
assertTrue(dl1.equals(dl2)); |
|
|
|
|
assertTrue(dl1.hashCode() == dl2.hashCode()); |
|
|
|
|
assertEquals(dl1, dl2); |
|
|
|
|
assertEquals(dl1.hashCode(), dl2.hashCode()); |
|
|
|
|
|
|
|
|
|
dl1.set(BOOL_VAR, false); |
|
|
|
|
dl2 = dl1.deepClone(); |
|
|
|
|
|
|
|
|
|
assertEquals(dl1, dl2); |
|
|
|
|
assertEquals(dl1.hashCode(), dl2.hashCode()); |
|
|
|
|
|
|
|
|
|
dl1.set(INT_VAR, 123); |
|
|
|
|
|
|
|
|
|
assertFalse(dl1.equals(dl2)); |
|
|
|
|
assertFalse(dl1.hashCode() == dl2.hashCode()); |
|
|
|
|
assertNotEquals(dl1, dl2); |
|
|
|
|
assertNotEquals(dl1.hashCode(), dl2.hashCode()); |
|
|
|
|
|
|
|
|
|
dl2 = dl1.deepClone(); |
|
|
|
|
|
|
|
|
|
assertTrue(dl1.equals(dl2)); |
|
|
|
|
assertTrue(dl1.hashCode() == dl2.hashCode()); |
|
|
|
|
assertEquals(dl1, dl2); |
|
|
|
|
assertEquals(dl1.hashCode(), dl2.hashCode()); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
@ -242,8 +282,8 @@ public class DefineListTest { |
|
|
|
|
|
|
|
|
|
dl.set(INT_VAR, 123); |
|
|
|
|
|
|
|
|
|
assertEquals("#define BOOL_VAR 1\n" + |
|
|
|
|
"#define INT_VAR 123\n", generateSource(dl)); |
|
|
|
|
assertEquals("#define BOOL_VAR 1\n" |
|
|
|
|
+ "#define INT_VAR 123\n", generateSource(dl)); |
|
|
|
|
|
|
|
|
|
dl.set(BOOL_VAR, false); |
|
|
|
|
|
|
|
|
@ -252,27 +292,30 @@ public class DefineListTest { |
|
|
|
|
dl.set(BOOL_VAR, true); |
|
|
|
|
|
|
|
|
|
// should have predictable ordering based on defineId
|
|
|
|
|
assertEquals("#define BOOL_VAR 1\n" + |
|
|
|
|
"#define INT_VAR 123\n", generateSource(dl)); |
|
|
|
|
assertEquals("#define BOOL_VAR 1\n" |
|
|
|
|
+ "#define INT_VAR 123\n", generateSource(dl)); |
|
|
|
|
|
|
|
|
|
dl.unset(BOOL_VAR); |
|
|
|
|
assertEquals("#define INT_VAR 123\n", generateSource(dl)); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
private static String doLookup(HashMap<DefineList, String> map, boolean boolVal, int intVal, float floatVal) { |
|
|
|
|
private static String doLookup(HashMap<DefineList, String> map, Boolean boolVal, Integer intVal, Float floatVal) { |
|
|
|
|
DefineList dl = new DefineList(NUM_DEFINES); |
|
|
|
|
dl.set(BOOL_VAR, boolVal); |
|
|
|
|
dl.set(INT_VAR, intVal); |
|
|
|
|
dl.set(FLOAT_VAR, floatVal); |
|
|
|
|
dl.set(BOOL_VAR, VarType.Boolean, boolVal); |
|
|
|
|
dl.set(INT_VAR, VarType.Int, intVal); |
|
|
|
|
dl.set(FLOAT_VAR, VarType.Float, floatVal); |
|
|
|
|
return map.get(dl); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
|
public void testHashLookup() { |
|
|
|
|
String STR_EMPTY = "This is an empty define list"; |
|
|
|
|
String STR_INT = "This define list has an int value"; |
|
|
|
|
String STR_BOOL = "This define list just has boolean value set"; |
|
|
|
|
String STR_BOOL_INT = "This define list has both a boolean and int value"; |
|
|
|
|
String STR_EMPTY = "This is an empty define list"; |
|
|
|
|
String STR_INT = "This define list has an int value"; |
|
|
|
|
String STR_BOOL = "This define list just has boolean value set"; |
|
|
|
|
String STR_BOOL_INT = "This define list has both a boolean and int value"; |
|
|
|
|
String STR_BOOL_INT_FLOAT = "This define list has a boolean, int, and float value"; |
|
|
|
|
|
|
|
|
|
HashMap<DefineList, String> map = new HashMap<DefineList, String>(); |
|
|
|
|
HashMap<DefineList, String> map = new HashMap<>(); |
|
|
|
|
|
|
|
|
|
DefineList lookup = new DefineList(NUM_DEFINES); |
|
|
|
|
|
|
|
|
@ -291,10 +334,10 @@ public class DefineListTest { |
|
|
|
|
lookup.set(FLOAT_VAR, FastMath.PI); |
|
|
|
|
map.put(lookup.deepClone(), STR_BOOL_INT_FLOAT); |
|
|
|
|
|
|
|
|
|
assertEquals(doLookup(map, false, 0, 0f), STR_EMPTY); |
|
|
|
|
assertEquals(doLookup(map, false, 123, 0f), STR_INT); |
|
|
|
|
assertEquals(doLookup(map, true, 0, 0f), STR_BOOL); |
|
|
|
|
assertEquals(doLookup(map, true, 123, 0f), STR_BOOL_INT); |
|
|
|
|
assertEquals(doLookup(map, true, 123, FastMath.PI), STR_BOOL_INT_FLOAT); |
|
|
|
|
assertEquals(STR_EMPTY, doLookup(map, null, null, null)); |
|
|
|
|
assertEquals(STR_INT, doLookup(map, false, 123, null)); |
|
|
|
|
assertEquals(STR_BOOL, doLookup(map, true, null, null)); |
|
|
|
|
assertEquals(STR_BOOL_INT, doLookup(map, true, 123, null)); |
|
|
|
|
assertEquals(STR_BOOL_INT_FLOAT, doLookup(map, true, 123, FastMath.PI)); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|