//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 TestArrayLiterals() { string input = "[1, 2 * 2, 3 + 3]"; var evaluated = testEval(input); Array_AST arr = evaluated as Array_AST; if (arr is null) { Assert.Fail(string.Format("object is not Array. got={0}", evaluated)); } if (arr.Elements.Count != 3) { Assert.Fail(string.Format("array has wrong num of elements. got={0}", arr.Elements.Count)); } testIntegerObject(arr.Elements[0], new Integer_AST(1)); testIntegerObject(arr.Elements[1], new Integer_AST(4)); testIntegerObject(arr.Elements[2], new Integer_AST(6)); }