|
|
@ -40,7 +40,7 @@ import org.junit.Test; |
|
|
|
import static org.junit.Assert.*; |
|
|
|
import static org.junit.Assert.*; |
|
|
|
|
|
|
|
|
|
|
|
public class DefineListTest { |
|
|
|
public class DefineListTest { |
|
|
|
|
|
|
|
|
|
|
|
private static final List<String> DEFINE_NAMES = Arrays.asList("BOOL_VAR", "INT_VAR", "FLOAT_VAR"); |
|
|
|
private static final List<String> DEFINE_NAMES = Arrays.asList("BOOL_VAR", "INT_VAR", "FLOAT_VAR"); |
|
|
|
private static final List<VarType> DEFINE_TYPES = Arrays.asList(VarType.Boolean, VarType.Int, VarType.Float); |
|
|
|
private static final List<VarType> DEFINE_TYPES = Arrays.asList(VarType.Boolean, VarType.Int, VarType.Float); |
|
|
|
private static final int NUM_DEFINES = DEFINE_NAMES.size(); |
|
|
|
private static final int NUM_DEFINES = DEFINE_NAMES.size(); |
|
|
@ -53,49 +53,49 @@ public class DefineListTest { |
|
|
|
public void testHashCollision() { |
|
|
|
public void testHashCollision() { |
|
|
|
DefineList dl1 = new DefineList(64); |
|
|
|
DefineList dl1 = new DefineList(64); |
|
|
|
DefineList dl2 = new DefineList(64); |
|
|
|
DefineList dl2 = new DefineList(64); |
|
|
|
|
|
|
|
|
|
|
|
// Try to cause a hash collision
|
|
|
|
// Try to cause a hash collision
|
|
|
|
// (since bit #32 is aliased to bit #1 in 32-bit ints)
|
|
|
|
// (since bit #32 is aliased to bit #1 in 32-bit ints)
|
|
|
|
dl1.set(0, 123); |
|
|
|
dl1.set(0, 123); |
|
|
|
dl1.set(32, 0); |
|
|
|
dl1.set(32, 0); |
|
|
|
|
|
|
|
|
|
|
|
dl2.set(32, 0); |
|
|
|
dl2.set(32, 0); |
|
|
|
dl2.set(0, 123); |
|
|
|
dl2.set(0, 123); |
|
|
|
|
|
|
|
|
|
|
|
assert dl1.hashCode() == dl2.hashCode(); |
|
|
|
assert dl1.hashCode() == dl2.hashCode(); |
|
|
|
assert dl1.equals(dl2); |
|
|
|
assert dl1.equals(dl2); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
@Test |
|
|
|
public void testGetSet() { |
|
|
|
public void testGetSet() { |
|
|
|
DefineList dl = new DefineList(NUM_DEFINES); |
|
|
|
DefineList dl = new DefineList(NUM_DEFINES); |
|
|
|
|
|
|
|
|
|
|
|
assertFalse(dl.getBoolean(BOOL_VAR)); |
|
|
|
assertFalse(dl.getBoolean(BOOL_VAR)); |
|
|
|
assertEquals(dl.getInt(INT_VAR), 0); |
|
|
|
assertEquals(dl.getInt(INT_VAR), 0); |
|
|
|
assertEquals(dl.getFloat(FLOAT_VAR), 0f, 0f); |
|
|
|
assertEquals(dl.getFloat(FLOAT_VAR), 0f, 0f); |
|
|
|
|
|
|
|
|
|
|
|
dl.set(BOOL_VAR, true); |
|
|
|
dl.set(BOOL_VAR, true); |
|
|
|
dl.set(INT_VAR, -1); |
|
|
|
dl.set(INT_VAR, -1); |
|
|
|
dl.set(FLOAT_VAR, Float.NaN); |
|
|
|
dl.set(FLOAT_VAR, Float.NaN); |
|
|
|
|
|
|
|
|
|
|
|
assertTrue(dl.getBoolean(BOOL_VAR)); |
|
|
|
assertTrue(dl.getBoolean(BOOL_VAR)); |
|
|
|
assertEquals(dl.getInt(INT_VAR), -1); |
|
|
|
assertEquals(dl.getInt(INT_VAR), -1); |
|
|
|
assertTrue(Float.isNaN(dl.getFloat(FLOAT_VAR))); |
|
|
|
assertTrue(Float.isNaN(dl.getFloat(FLOAT_VAR))); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
private String generateSource(DefineList dl) { |
|
|
|
private String generateSource(DefineList dl) { |
|
|
|
StringBuilder sb = new StringBuilder(); |
|
|
|
StringBuilder sb = new StringBuilder(); |
|
|
|
dl.generateSource(sb, DEFINE_NAMES, DEFINE_TYPES); |
|
|
|
dl.generateSource(sb, DEFINE_NAMES, DEFINE_TYPES); |
|
|
|
return sb.toString(); |
|
|
|
return sb.toString(); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
@Test |
|
|
|
public void testSourceInitial() { |
|
|
|
public void testSourceInitial() { |
|
|
|
DefineList dl = new DefineList(NUM_DEFINES); |
|
|
|
DefineList dl = new DefineList(NUM_DEFINES); |
|
|
|
assert dl.hashCode() == 0; |
|
|
|
assert dl.hashCode() == 0; |
|
|
|
assert generateSource(dl).equals(""); |
|
|
|
assert generateSource(dl).equals(""); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
@Test |
|
|
|
public void testSourceBooleanDefine() { |
|
|
|
public void testSourceBooleanDefine() { |
|
|
|
DefineList dl = new DefineList(NUM_DEFINES); |
|
|
|
DefineList dl = new DefineList(NUM_DEFINES); |
|
|
@ -103,35 +103,47 @@ public class DefineListTest { |
|
|
|
dl.set(BOOL_VAR, true); |
|
|
|
dl.set(BOOL_VAR, true); |
|
|
|
assert dl.hashCode() == 1; |
|
|
|
assert dl.hashCode() == 1; |
|
|
|
assert generateSource(dl).equals("#define BOOL_VAR 1\n"); |
|
|
|
assert generateSource(dl).equals("#define BOOL_VAR 1\n"); |
|
|
|
|
|
|
|
|
|
|
|
dl.set(BOOL_VAR, false); |
|
|
|
dl.set(BOOL_VAR, false); |
|
|
|
assert dl.hashCode() == 0; |
|
|
|
assert dl.hashCode() == 0; |
|
|
|
assert generateSource(dl).equals(""); |
|
|
|
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 |
|
|
|
@Test |
|
|
|
public void testSourceIntDefine() { |
|
|
|
public void testSourceIntDefine() { |
|
|
|
DefineList dl = new DefineList(NUM_DEFINES); |
|
|
|
DefineList dl = new DefineList(NUM_DEFINES); |
|
|
|
|
|
|
|
|
|
|
|
int hashCodeWithInt = 1 << INT_VAR; |
|
|
|
int hashCodeWithInt = 1 << INT_VAR; |
|
|
|
|
|
|
|
|
|
|
|
dl.set(INT_VAR, 123); |
|
|
|
dl.set(INT_VAR, 123); |
|
|
|
assert dl.hashCode() == hashCodeWithInt; |
|
|
|
assert dl.hashCode() == hashCodeWithInt; |
|
|
|
assert generateSource(dl).equals("#define INT_VAR 123\n"); |
|
|
|
assert generateSource(dl).equals("#define INT_VAR 123\n"); |
|
|
|
|
|
|
|
|
|
|
|
dl.set(INT_VAR, 0); |
|
|
|
dl.set(INT_VAR, 0); |
|
|
|
assert dl.hashCode() == 0; |
|
|
|
assert dl.hashCode() == hashCodeWithInt; |
|
|
|
assert generateSource(dl).equals(""); |
|
|
|
assert generateSource(dl).equals("#define INT_VAR 0\n"); |
|
|
|
|
|
|
|
|
|
|
|
dl.set(INT_VAR, -99); |
|
|
|
dl.set(INT_VAR, -99); |
|
|
|
assert dl.hashCode() == hashCodeWithInt; |
|
|
|
assert dl.hashCode() == hashCodeWithInt; |
|
|
|
assert generateSource(dl).equals("#define INT_VAR -99\n"); |
|
|
|
assert generateSource(dl).equals("#define INT_VAR -99\n"); |
|
|
|
|
|
|
|
|
|
|
|
dl.set(INT_VAR, Integer.MAX_VALUE); |
|
|
|
dl.set(INT_VAR, Integer.MAX_VALUE); |
|
|
|
assert dl.hashCode() == hashCodeWithInt; |
|
|
|
assert dl.hashCode() == hashCodeWithInt; |
|
|
|
assert generateSource(dl).equals("#define INT_VAR 2147483647\n"); |
|
|
|
assert generateSource(dl).equals("#define INT_VAR 2147483647\n"); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
dl.unset(INT_VAR); |
|
|
|
|
|
|
|
assert dl.hashCode() == 0; |
|
|
|
|
|
|
|
assert generateSource(dl).equals(""); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
@Test |
|
|
|
public void testSourceFloatDefine() { |
|
|
|
public void testSourceFloatDefine() { |
|
|
|
DefineList dl = new DefineList(NUM_DEFINES); |
|
|
|
DefineList dl = new DefineList(NUM_DEFINES); |
|
|
@ -139,162 +151,193 @@ public class DefineListTest { |
|
|
|
dl.set(FLOAT_VAR, 1f); |
|
|
|
dl.set(FLOAT_VAR, 1f); |
|
|
|
assert dl.hashCode() == (1 << FLOAT_VAR); |
|
|
|
assert dl.hashCode() == (1 << FLOAT_VAR); |
|
|
|
assert generateSource(dl).equals("#define FLOAT_VAR 1.0\n"); |
|
|
|
assert generateSource(dl).equals("#define FLOAT_VAR 1.0\n"); |
|
|
|
|
|
|
|
|
|
|
|
dl.set(FLOAT_VAR, 0f); |
|
|
|
dl.set(FLOAT_VAR, 0f); |
|
|
|
assert dl.hashCode() == 0; |
|
|
|
assert dl.hashCode() == (1 << FLOAT_VAR); |
|
|
|
assert generateSource(dl).equals(""); |
|
|
|
assert generateSource(dl).equals("#define FLOAT_VAR 0.0\n"); |
|
|
|
|
|
|
|
|
|
|
|
dl.set(FLOAT_VAR, -1f); |
|
|
|
dl.set(FLOAT_VAR, -1f); |
|
|
|
assert generateSource(dl).equals("#define FLOAT_VAR -1.0\n"); |
|
|
|
assert generateSource(dl).equals("#define FLOAT_VAR -1.0\n"); |
|
|
|
|
|
|
|
|
|
|
|
dl.set(FLOAT_VAR, FastMath.FLT_EPSILON); |
|
|
|
dl.set(FLOAT_VAR, FastMath.FLT_EPSILON); |
|
|
|
assert generateSource(dl).equals("#define FLOAT_VAR 1.1920929E-7\n"); |
|
|
|
assert generateSource(dl).equals("#define FLOAT_VAR 1.1920929E-7\n"); |
|
|
|
|
|
|
|
|
|
|
|
dl.set(FLOAT_VAR, FastMath.PI); |
|
|
|
dl.set(FLOAT_VAR, FastMath.PI); |
|
|
|
assert generateSource(dl).equals("#define FLOAT_VAR 3.1415927\n"); |
|
|
|
assert generateSource(dl).equals("#define FLOAT_VAR 3.1415927\n"); |
|
|
|
|
|
|
|
|
|
|
|
try { |
|
|
|
try { |
|
|
|
dl.set(FLOAT_VAR, Float.NaN); |
|
|
|
dl.set(FLOAT_VAR, Float.NaN); |
|
|
|
generateSource(dl); |
|
|
|
generateSource(dl); |
|
|
|
assert false; |
|
|
|
assert false; |
|
|
|
} catch (IllegalArgumentException ex) { } |
|
|
|
} catch (IllegalArgumentException ex) { |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
try { |
|
|
|
try { |
|
|
|
dl.set(FLOAT_VAR, Float.POSITIVE_INFINITY); |
|
|
|
dl.set(FLOAT_VAR, Float.POSITIVE_INFINITY); |
|
|
|
generateSource(dl); |
|
|
|
generateSource(dl); |
|
|
|
assert false; |
|
|
|
assert false; |
|
|
|
} catch (IllegalArgumentException ex) { } |
|
|
|
} catch (IllegalArgumentException ex) { |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
try { |
|
|
|
try { |
|
|
|
dl.set(FLOAT_VAR, Float.NEGATIVE_INFINITY); |
|
|
|
dl.set(FLOAT_VAR, Float.NEGATIVE_INFINITY); |
|
|
|
generateSource(dl); |
|
|
|
generateSource(dl); |
|
|
|
assert false; |
|
|
|
assert false; |
|
|
|
} catch (IllegalArgumentException ex) { } |
|
|
|
} catch (IllegalArgumentException ex) { |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
@Test |
|
|
|
public void testEqualsAndHashCode() { |
|
|
|
public void testEqualsAndHashCode() { |
|
|
|
DefineList dl1 = new DefineList(NUM_DEFINES); |
|
|
|
DefineList dl1 = new DefineList(NUM_DEFINES); |
|
|
|
DefineList dl2 = 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); |
|
|
|
assertEquals(dl1, dl2); |
|
|
|
|
|
|
|
|
|
|
|
dl1.set(BOOL_VAR, true); |
|
|
|
dl1.set(BOOL_VAR, true); |
|
|
|
|
|
|
|
|
|
|
|
assertTrue(dl1.hashCode() == 1); |
|
|
|
assertEquals(1, dl1.hashCode()); |
|
|
|
assertNotSame(dl1, dl2); |
|
|
|
assertEquals(0, dl2.hashCode()); |
|
|
|
|
|
|
|
assertNotEquals(dl1, dl2); |
|
|
|
|
|
|
|
|
|
|
|
dl2.set(BOOL_VAR, true); |
|
|
|
dl2.set(BOOL_VAR, true); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
assertEquals(1, dl1.hashCode()); |
|
|
|
|
|
|
|
assertEquals(1, dl2.hashCode()); |
|
|
|
assertEquals(dl1, dl2); |
|
|
|
assertEquals(dl1, dl2); |
|
|
|
|
|
|
|
|
|
|
|
dl1.set(INT_VAR, 2); |
|
|
|
dl1.set(INT_VAR, 2); |
|
|
|
|
|
|
|
|
|
|
|
assertTrue(dl1.hashCode() == (1|2)); |
|
|
|
assertEquals(1 | 2, dl1.hashCode()); |
|
|
|
assertNotSame(dl1, dl2); |
|
|
|
assertEquals(1, dl2.hashCode()); |
|
|
|
|
|
|
|
assertNotEquals(dl1, dl2); |
|
|
|
|
|
|
|
|
|
|
|
dl2.set(INT_VAR, 2); |
|
|
|
dl2.set(INT_VAR, 2); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
assertEquals(1 | 2, dl1.hashCode()); |
|
|
|
|
|
|
|
assertEquals(1 | 2, dl2.hashCode()); |
|
|
|
assertEquals(dl1, dl2); |
|
|
|
assertEquals(dl1, dl2); |
|
|
|
|
|
|
|
|
|
|
|
dl1.set(BOOL_VAR, false); |
|
|
|
dl1.set(BOOL_VAR, false); |
|
|
|
|
|
|
|
|
|
|
|
assertTrue(dl1.hashCode() == 2); |
|
|
|
assertEquals(2, dl1.hashCode()); |
|
|
|
assertNotSame(dl1, dl2); |
|
|
|
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 |
|
|
|
@Test |
|
|
|
public void testDeepClone() { |
|
|
|
public void testDeepClone() { |
|
|
|
DefineList dl1 = new DefineList(NUM_DEFINES); |
|
|
|
DefineList dl1 = new DefineList(NUM_DEFINES); |
|
|
|
DefineList dl2 = dl1.deepClone(); |
|
|
|
DefineList dl2 = dl1.deepClone(); |
|
|
|
|
|
|
|
|
|
|
|
assertFalse(dl1 == dl2); |
|
|
|
assertNotSame(dl1, dl2); |
|
|
|
assertTrue(dl1.equals(dl2)); |
|
|
|
assertEquals(dl1, dl2); |
|
|
|
assertTrue(dl1.hashCode() == dl2.hashCode()); |
|
|
|
assertEquals(dl1.hashCode(), dl2.hashCode()); |
|
|
|
|
|
|
|
|
|
|
|
dl1.set(BOOL_VAR, true); |
|
|
|
dl1.set(BOOL_VAR, true); |
|
|
|
dl2 = dl1.deepClone(); |
|
|
|
dl2 = dl1.deepClone(); |
|
|
|
|
|
|
|
|
|
|
|
assertTrue(dl1.equals(dl2)); |
|
|
|
assertEquals(dl1, dl2); |
|
|
|
assertTrue(dl1.hashCode() == dl2.hashCode()); |
|
|
|
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); |
|
|
|
dl1.set(INT_VAR, 123); |
|
|
|
|
|
|
|
|
|
|
|
assertFalse(dl1.equals(dl2)); |
|
|
|
assertNotEquals(dl1, dl2); |
|
|
|
assertFalse(dl1.hashCode() == dl2.hashCode()); |
|
|
|
assertNotEquals(dl1.hashCode(), dl2.hashCode()); |
|
|
|
|
|
|
|
|
|
|
|
dl2 = dl1.deepClone(); |
|
|
|
dl2 = dl1.deepClone(); |
|
|
|
|
|
|
|
|
|
|
|
assertTrue(dl1.equals(dl2)); |
|
|
|
assertEquals(dl1, dl2); |
|
|
|
assertTrue(dl1.hashCode() == dl2.hashCode()); |
|
|
|
assertEquals(dl1.hashCode(), dl2.hashCode()); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
@Test |
|
|
|
public void testGenerateSource() { |
|
|
|
public void testGenerateSource() { |
|
|
|
DefineList dl = new DefineList(NUM_DEFINES); |
|
|
|
DefineList dl = new DefineList(NUM_DEFINES); |
|
|
|
|
|
|
|
|
|
|
|
assertEquals("", generateSource(dl)); |
|
|
|
assertEquals("", generateSource(dl)); |
|
|
|
|
|
|
|
|
|
|
|
dl.set(BOOL_VAR, true); |
|
|
|
dl.set(BOOL_VAR, true); |
|
|
|
|
|
|
|
|
|
|
|
assertEquals("#define BOOL_VAR 1\n", generateSource(dl)); |
|
|
|
assertEquals("#define BOOL_VAR 1\n", generateSource(dl)); |
|
|
|
|
|
|
|
|
|
|
|
dl.set(INT_VAR, 123); |
|
|
|
dl.set(INT_VAR, 123); |
|
|
|
|
|
|
|
|
|
|
|
assertEquals("#define BOOL_VAR 1\n" + |
|
|
|
assertEquals("#define BOOL_VAR 1\n" |
|
|
|
"#define INT_VAR 123\n", generateSource(dl)); |
|
|
|
+ "#define INT_VAR 123\n", generateSource(dl)); |
|
|
|
|
|
|
|
|
|
|
|
dl.set(BOOL_VAR, false); |
|
|
|
dl.set(BOOL_VAR, false); |
|
|
|
|
|
|
|
|
|
|
|
assertEquals("#define INT_VAR 123\n", generateSource(dl)); |
|
|
|
assertEquals("#define INT_VAR 123\n", generateSource(dl)); |
|
|
|
|
|
|
|
|
|
|
|
dl.set(BOOL_VAR, true); |
|
|
|
dl.set(BOOL_VAR, true); |
|
|
|
|
|
|
|
|
|
|
|
// should have predictable ordering based on defineId
|
|
|
|
// should have predictable ordering based on defineId
|
|
|
|
assertEquals("#define BOOL_VAR 1\n" + |
|
|
|
assertEquals("#define BOOL_VAR 1\n" |
|
|
|
"#define INT_VAR 123\n", generateSource(dl)); |
|
|
|
+ "#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); |
|
|
|
DefineList dl = new DefineList(NUM_DEFINES); |
|
|
|
dl.set(BOOL_VAR, boolVal); |
|
|
|
dl.set(BOOL_VAR, VarType.Boolean, boolVal); |
|
|
|
dl.set(INT_VAR, intVal); |
|
|
|
dl.set(INT_VAR, VarType.Int, intVal); |
|
|
|
dl.set(FLOAT_VAR, floatVal); |
|
|
|
dl.set(FLOAT_VAR, VarType.Float, floatVal); |
|
|
|
return map.get(dl); |
|
|
|
return map.get(dl); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
@Test |
|
|
|
public void testHashLookup() { |
|
|
|
public void testHashLookup() { |
|
|
|
String STR_EMPTY = "This is an empty define list"; |
|
|
|
String STR_EMPTY = "This is an empty define list"; |
|
|
|
String STR_INT = "This define list has an int value"; |
|
|
|
String STR_INT = "This define list has an int value"; |
|
|
|
String STR_BOOL = "This define list just has boolean value set"; |
|
|
|
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 = "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"; |
|
|
|
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); |
|
|
|
DefineList lookup = new DefineList(NUM_DEFINES); |
|
|
|
|
|
|
|
|
|
|
|
map.put(lookup.deepClone(), STR_EMPTY); |
|
|
|
map.put(lookup.deepClone(), STR_EMPTY); |
|
|
|
|
|
|
|
|
|
|
|
lookup.set(BOOL_VAR, true); |
|
|
|
lookup.set(BOOL_VAR, true); |
|
|
|
map.put(lookup.deepClone(), STR_BOOL); |
|
|
|
map.put(lookup.deepClone(), STR_BOOL); |
|
|
|
|
|
|
|
|
|
|
|
lookup.set(BOOL_VAR, false); |
|
|
|
lookup.set(BOOL_VAR, false); |
|
|
|
lookup.set(INT_VAR, 123); |
|
|
|
lookup.set(INT_VAR, 123); |
|
|
|
map.put(lookup.deepClone(), STR_INT); |
|
|
|
map.put(lookup.deepClone(), STR_INT); |
|
|
|
|
|
|
|
|
|
|
|
lookup.set(BOOL_VAR, true); |
|
|
|
lookup.set(BOOL_VAR, true); |
|
|
|
map.put(lookup.deepClone(), STR_BOOL_INT); |
|
|
|
map.put(lookup.deepClone(), STR_BOOL_INT); |
|
|
|
|
|
|
|
|
|
|
|
lookup.set(FLOAT_VAR, FastMath.PI); |
|
|
|
lookup.set(FLOAT_VAR, FastMath.PI); |
|
|
|
map.put(lookup.deepClone(), STR_BOOL_INT_FLOAT); |
|
|
|
map.put(lookup.deepClone(), STR_BOOL_INT_FLOAT); |
|
|
|
|
|
|
|
|
|
|
|
assertEquals(doLookup(map, false, 0, 0f), STR_EMPTY); |
|
|
|
assertEquals(STR_EMPTY, doLookup(map, null, null, null)); |
|
|
|
assertEquals(doLookup(map, false, 123, 0f), STR_INT); |
|
|
|
assertEquals(STR_INT, doLookup(map, false, 123, null)); |
|
|
|
assertEquals(doLookup(map, true, 0, 0f), STR_BOOL); |
|
|
|
assertEquals(STR_BOOL, doLookup(map, true, null, null)); |
|
|
|
assertEquals(doLookup(map, true, 123, 0f), STR_BOOL_INT); |
|
|
|
assertEquals(STR_BOOL_INT, doLookup(map, true, 123, null)); |
|
|
|
assertEquals(doLookup(map, true, 123, FastMath.PI), STR_BOOL_INT_FLOAT); |
|
|
|
assertEquals(STR_BOOL_INT_FLOAT, doLookup(map, true, 123, FastMath.PI)); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|