//it only assert integer aray elements at the moment..implement functionality in Array_AST to test equality private void testArrayObject(Object_AST resultObj, Array_AST expectedObj) { Array_AST result = resultObj as Array_AST; if (result is null) { Assert.Fail(string.Format("resultObj is not Array_AST. got={0}", resultObj));//Assert.Fail will internally anyways throw an AssertFailedException } Array_AST expected = expectedObj as Array_AST; if (expected is null) { Assert.Fail(string.Format("expectedObj is not Array_AST. got={0}", expected)); } Assert.AreEqual(result.Elements.Count, expected.Elements.Count, string.Format("resultObj has wrong number of array elements. got={0}, want={1}", result.Elements.Count, expected.Elements.Count)); for (int i = 0; i < expected.Elements.Count; i++) { Integer_AST exp_int = expected.Elements[i] as Integer_AST; Integer_AST res_int = result.Elements[i] as Integer_AST; Assert.AreEqual(res_int.Value, exp_int.Value, string.Format("resultObj array elements do not match. got={0}, want={1}", res_int, exp_int)); } }
public void TestIntegerHashKey() { Integer_AST hello1 = new Integer_AST(1); Integer_AST hello2 = new Integer_AST(1); Integer_AST diff1 = new Integer_AST(2); Integer_AST diff2 = new Integer_AST(2); //Assert.Equals(hello1.HashKey(), hello2.HashKey());//this assertion works on structs fine //if (hello1.HashKey() != hello2.HashKey()) {//outof the box, comparison like this do not work for structs. if (!hello1.HashKey().Equals(hello2.HashKey())) { throw new AssertFailedException("ints with same content have different hash keys"); } //if (diff1.HashKey() != diff2.HashKey()) { if (!diff1.HashKey().Equals(diff2.HashKey())) { throw new AssertFailedException("ints with same content have different hash keys"); } //if (hello1.HashKey() == diff1.HashKey()) { if (hello1.HashKey().Equals(diff1.HashKey())) { throw new AssertFailedException("ints with different content have same hash keys"); } }
private void testIntegerObject(Object_AST resultObj, Object_AST expectedObj) { Integer_AST result = resultObj as Integer_AST; if (result is null) { throw new AssertFailedException(string.Format("resultObj is not Integer_AST. got={0}", resultObj)); } Integer_AST expected = expectedObj as Integer_AST; if (expected is null) { throw new AssertFailedException(string.Format("expectedObj is not Integer_AST. got={0}", expected)); } Assert.AreEqual(result.Value, expected.Value, string.Format("resultObj has wrong value. got={0}, want={1}", result.Value, expected.Value)); }