public void Constants() { var TAC = GenTAC(@" var a, b, c, k; a = 5; k = 5; "); var(ok, instructions) = ThreeAddressCodeCommonExprElimination.CommonExprElimination(TAC); Assert.IsFalse(ok); var expected = new List <string>() { "a = 5", "k = 5" }; var actual = instructions.Select(instruction => instruction.ToString()); CollectionAssert.AreEqual(expected, actual); }
public void NotCommutativeOpTest() { var TAC = GenTAC(@" var a, b, c, k; a = b - c; k = c - b; "); var(ok, instructions) = ThreeAddressCodeCommonExprElimination.CommonExprElimination(TAC); Assert.IsFalse(ok); var expected = new List <string>() { "#t1 = b - c", "a = #t1", "#t2 = c - b", "k = #t2" }; var actual = instructions.Select(instruction => instruction.ToString()); CollectionAssert.AreEqual(expected, actual); }
public void Test2() { var TAC = GenTAC(@" var a, b, c, d, e, f, g, h, k; a = b + c; k = b + c; "); var(ok, instructions) = ThreeAddressCodeCommonExprElimination.CommonExprElimination(TAC); Assert.IsTrue(ok); var expected = new List <string>() { "#t1 = b + c", "a = #t1", "#t2 = #t1", "k = #t2" }; var actual = instructions.Select(instruction => instruction.ToString()); CollectionAssert.AreEqual(expected, actual); }