fix: tests.

This commit is contained in:
redxef 2024-10-26 23:52:16 +02:00
parent 953927bc27
commit f37f825c53
Signed by: redxef
GPG key ID: 7DAC3AA211CBD921

View file

@ -22,39 +22,39 @@ namespace Tests
[Fact]
public static void TestTokenizer() {
StringTokenStream sts = StringTokenStream.generate("(\"some literal string\" def ghj +100 -+300 1 >= ++ !=)");
Assert.Equal(sts.get().value, "(");
Assert.Equal(sts.get().value, "\"");
Assert.Equal(sts.get().value, "some");
Assert.Equal(sts.get().value, " ");
Assert.Equal(sts.get().value, "literal");
Assert.Equal(sts.get().value, " ");
Assert.Equal(sts.get().value, "string");
Assert.Equal(sts.get().value, "\"");
Assert.Equal(sts.get().value, " ");
Assert.Equal(sts.get().value, "def");
Assert.Equal(sts.get().value, " ");
Assert.Equal(sts.get().value, "ghj");
Assert.Equal(sts.get().value, " ");
Assert.Equal(sts.get().value, "+");
Assert.Equal(sts.get().value, "100");
Assert.Equal(sts.get().value, " ");
Assert.Equal(sts.get().value, "-");
Assert.Equal(sts.get().value, "+");
Assert.Equal(sts.get().value, "300");
Assert.Equal(sts.get().value, " ");
Assert.Equal(sts.get().value, "1");
Assert.Equal(sts.get().value, " ");
Assert.Equal(sts.get().value, ">");
Assert.Equal(sts.get().value, "=");
Assert.Equal(sts.get().value, " ");
Assert.Equal(sts.get().value, "+");
Assert.Equal(sts.get().value, "+");
Assert.Equal(sts.get().value, " ");
Assert.Equal(sts.get().value, "!");
Assert.Equal(sts.get().value, "=");
Assert.Equal(sts.get().value, ")");
sts.commit();
Assert.Equal(sts.available(), 0);
Assert.Equal(sts.Get().value, "(");
Assert.Equal(sts.Get().value, "\"");
Assert.Equal(sts.Get().value, "some");
Assert.Equal(sts.Get().value, " ");
Assert.Equal(sts.Get().value, "literal");
Assert.Equal(sts.Get().value, " ");
Assert.Equal(sts.Get().value, "string");
Assert.Equal(sts.Get().value, "\"");
Assert.Equal(sts.Get().value, " ");
Assert.Equal(sts.Get().value, "def");
Assert.Equal(sts.Get().value, " ");
Assert.Equal(sts.Get().value, "ghj");
Assert.Equal(sts.Get().value, " ");
Assert.Equal(sts.Get().value, "+");
Assert.Equal(sts.Get().value, "100");
Assert.Equal(sts.Get().value, " ");
Assert.Equal(sts.Get().value, "-");
Assert.Equal(sts.Get().value, "+");
Assert.Equal(sts.Get().value, "300");
Assert.Equal(sts.Get().value, " ");
Assert.Equal(sts.Get().value, "1");
Assert.Equal(sts.Get().value, " ");
Assert.Equal(sts.Get().value, ">");
Assert.Equal(sts.Get().value, "=");
Assert.Equal(sts.Get().value, " ");
Assert.Equal(sts.Get().value, "+");
Assert.Equal(sts.Get().value, "+");
Assert.Equal(sts.Get().value, " ");
Assert.Equal(sts.Get().value, "!");
Assert.Equal(sts.Get().value, "=");
Assert.Equal(sts.Get().value, ")");
sts.Commit();
Assert.Equal(sts.Available(), 0);
}
[Fact]
@ -68,6 +68,11 @@ namespace Tests
sts = StringTokenStream.generate(program);
p = new Parser(sts);
Assert.Equal(program, string.Format("{0}", p.parse()));
//program = "(* 2.4 2)";
//sts = StringTokenStream.generate(program);
//p = new Parser(sts);
//Assert.Equal(program, p.parse().ToString());
}
[Fact]
@ -108,6 +113,18 @@ namespace Tests
e = new Executor().eval("(> 2 2))");
Assert.Equal(string.Format("{0}", e), "nil");
e = new Executor().eval("(and 2 3 4)");
Assert.Equal("4", e.ToString());
e = new Executor().eval("(and 2 nil 4)");
Assert.Equal("nil", e.ToString());
e = new Executor().eval("(or 2 nil 4)");
Assert.Equal("2", e.ToString());
e = new Executor().eval("(or nil 4)");
Assert.Equal("4", e.ToString());
}
[Fact]
public static void ObjectTest() {
@ -120,6 +137,15 @@ namespace Tests
Assert.Equal(string.Format("{0}", r), "(5 nil)");
}
[Fact]
public static void ScalarTest() {
Executor e = new Executor();
Expression r;
r = e.eval("(* 2 2)");
Assert.Equal("4", r.ToString());
}
[Fact]
public static void ProcedureTest() {
Executor e = new Executor();
@ -130,10 +156,8 @@ namespace Tests
r = e.eval("(begin (define mull (lambda (a) (* a a))) (mull 3))");
Assert.Equal(string.Format("{0}", r), "9");
//r = e.eval("""
//(begin (define pi 3.1415) 1)
//""");
//Assert.Equal(string.Format("{0}", r), "1");
r = e.eval("(begin (define fact (lambda (n) (if (<= n 1) 1 (* n (fact (- n 1)))))) (fact 10))");
Assert.Equal(string.Format("{0}", r), "3628800");
}
}
}