public void TestRec() { var step = n + one; var rec = new RecNumExpression(two, zero, "x", "n", step); Assert.AreEqual("2", testAsync(rec, 200).Result); rec = new RecNumExpression(two, two, "x", "n", step); Assert.AreEqual("4", testAsync(rec, 200).Result); var logStep = x & logicTrue; var logRec = new RecLogicExpression(two, logicTrue, "n", "x", logStep); Assert.AreEqual(True, testAsync(logRec, 200).Result); logStep = x | logicTrue; logRec = new RecLogicExpression(two, logicFalse, "n", "x", logStep); Assert.AreEqual(True, testAsync(logRec, 200).Result); logStep = x | logicTrue; logRec = new RecLogicExpression(zero, logicFalse, "n", "x", logStep); Assert.AreEqual(False, testAsync(logRec, 200).Result); // Something a bit more complicated: 6 is the smallest number greater than 5 // i.e 6 is the n such that n > 5 and forall m < n we have m <=5 var step2 = x & m <= new NumConstant(5); var rec2 = new RecLogicExpression(n, logicTrue, "m", "x", step2); var testLog = new NumConstant(6) == new NumThe("n", n > new NumConstant(5) & rec2); Assert.AreEqual(True, testAsync(testLog, 10000).Result); }
public void TestThe() { NumExpression n = new NumVariable("n"); var two = new NumConstant(2); NumExpression test = new NumThe("n", n == two); Assert.AreEqual("2", testAsync(test, 1000).Result); test = new NumThe("n", n == two + two); Assert.AreEqual("4", testAsync(test, 1000).Result); test = new NumThe("n", n + n == n * n); // not valid since it has two results, but we ignore this Assert.AreEqual("0", testAsync(test, 1000).Result); // Find the positive natural such that 2n=n^2 test = new NumThe("n", (logicLoop | (n + n == n * n) & (n > zero)) | logicLoop); Assert.AreEqual("2", testAsync(test, 1000).Result); // Should fail test = new NumThe("n", (n == zero) & (n > zero)); Assert.AreEqual(False, testAsync(test, 1000).Result); test = new NumThe("n", (logicLoop | n == new NumConstant(50) | logicLoop)); Assert.AreEqual("50", testAsync(test, 1000).Result); // Find the positive natural such that 2n=n^2 this time with logicFalse test = new NumThe("n", ((n + n == n * n) & (n > zero)) | logicFalse); Assert.AreEqual("2", testAsync(test, 1000).Result); test = new NumThe("n", (n == new NumConstant(50) | logicFalse)); Assert.AreEqual("50", testAsync(test, 1000).Result); }
public void TestExists() { NumExpression n = new NumVariable("n"); var two = new NumConstant(2); var hundred = new NumConstant(100); Expression test = new NumExists("n", n == two); Assert.AreEqual(True, testAsync(test, 1000).Result); Expression test2 = new NumExists("n", n == n + n); Assert.AreEqual(True, testAsync(test2, 1000).Result); Expression test3 = new NumExists("n", n == n + two); Assert.AreEqual(False, testAsync(test3, 1000).Result); Expression test4 = new NumExists("n", n == hundred); // should take 1 sec to find (100 * 10ms) Assert.AreEqual(True, testAsync(test4, 2000).Result); Expression test5 = new NumExists("n", two < n); Assert.AreEqual(True, testAsync(test5, 2000).Result); Expression test6 = new NumExists("n", n < n); Assert.AreEqual(False, testAsync(test6, 1000).Result, "test6"); }
public void TestNumRel() { NumExpression test500 = new NumConstant(500); NumExpression test1000 = new NumConstant(1000); NumExpression zero = new NumConstant(0); NumExpression test2 = test500 + test500; LogicExpression testEq = test2 == test1000; Assert.AreEqual("True", testAsync(testEq, defaultTimeout).Result); LogicExpression testNeq = test2 != test1000; Assert.AreEqual("False", testAsync(testNeq, defaultTimeout).Result); LogicExpression testLT = test500 < test1000; Assert.AreEqual("True", testAsync(testLT, defaultTimeout).Result); LogicExpression testLTE = test500 <= test1000; Assert.AreEqual("True", testAsync(testLTE, defaultTimeout).Result); LogicExpression testGT = test1000 > test500; Assert.AreEqual("True", testAsync(testLT, defaultTimeout).Result); LogicExpression testGTE = test1000 >= test500; Assert.AreEqual("True", testAsync(testLTE, defaultTimeout).Result); LogicExpression testZero = zero > zero; Assert.AreEqual("False", testAsync(testZero, defaultTimeout).Result, "TestZero"); }
public void TestNum() { NumExpression test = new NumConstant(500); Assert.AreEqual(500, testAsyncNum(test, defaultTimeout).Result); NumExpression test2 = test * test; Assert.AreEqual(500 * 500, testAsyncNum(test2, defaultTimeout).Result); NumExpression test3 = test + test; Assert.AreEqual(500 + 500, testAsyncNum(test3, defaultTimeout).Result); }
public void TestString() { var step2 = x & m <= new NumConstant(5); var rec2 = new RecLogicExpression(n, logicTrue, "m", "x", step2); var testLog = new NumConstant(6) == new NumThe("n", n > new NumConstant(5) & rec2); Assert.AreEqual("(6 == The n. ((n > 5) & Rec(n, True, m.x. (x & (m <= 5)))))", testLog.ToString()); var test5 = new Apply(new LambdaExpression("x", x | logicTrue), logicLoop); Assert.AreEqual("(Lambda x. (x | True) @ Exists n. (n < n))", test5.ToString()); var loopTest = new PairExpression <LogicExpression, LogicExpression>(logicLoop, logicTrue); var pairLoop = new LogicProjR(loopTest); Assert.AreEqual("Snd <Exists n. (n < n), True>", pairLoop.ToString()); }
public Expression Visit(NumConstant constant) { return(constant); }
public SortedSet <string> Visit(NumConstant constant) { return(new SortedSet <string> { }); }
public T Visit(NumConstant constant) { return(default(T)); }
public async Task <Value> Visit(NumConstant constant) { return(await Task.Run(() => new NumValue(constant.Value))); // get rid of compiler warning }