فهرست منبع

Add more unit and integration tests

Tamo 7 ماه پیش
والد
کامیت
aa7222125e
2فایلهای تغییر یافته به همراه15 افزوده شده و 0 حذف شده
  1. 10 0
      examples/tests/core.nbt
  2. 5 0
      numbat/tests/interpreter.rs

+ 10 - 0
examples/tests/core.nbt

@@ -111,3 +111,13 @@ assert_eq(fract(-1.2), -0.2, 1e-12)
 assert_eq(fract(-1.8), -0.8, 1e-12)
 assert_eq(fract(-1.8), -0.8, 1e-12)
 assert(is_nan(fract(NaN)))
 assert(is_nan(fract(NaN)))
 assert(is_nan(fract(inf)))
 assert(is_nan(fract(inf)))
+
+# factorial and multi-factorial
+
+assert_eq(7!!, 7 * 5 * 3)
+assert_eq((7)!!!, 7 * 4)
+assert_eq((7!!!!), 7 * 3)
+
+assert_eq(8!!, 8 * 6 * 4 * 2)
+assert_eq(8.0!!!, 8 * 5 * 2)
+assert_eq( 8 !!!!, 8 * 4)

+ 5 - 0
numbat/tests/interpreter.rs

@@ -158,7 +158,9 @@ fn test_factorial() {
     expect_output("0!", "1");
     expect_output("0!", "1");
     expect_output("4!", "24");
     expect_output("4!", "24");
     expect_output("4.0!", "24");
     expect_output("4.0!", "24");
+    expect_output("4.0!!", "8");
     expect_output("4 !", "24");
     expect_output("4 !", "24");
+    expect_output("4 !!", "8");
     expect_output(" 4 !", "24");
     expect_output(" 4 !", "24");
     expect_output("(4)!", "24");
     expect_output("(4)!", "24");
     expect_output("3!^3", "216");
     expect_output("3!^3", "216");
@@ -169,6 +171,9 @@ fn test_factorial() {
     expect_output("-5!", "-120");
     expect_output("-5!", "-120");
     expect_output("-(5!)", "-120");
     expect_output("-(5!)", "-120");
     expect_output("-(5)!", "-120");
     expect_output("-(5)!", "-120");
+    expect_output("-5!!", "-15");
+    expect_output("-(5!!)", "-15");
+    expect_output("-(5)!!", "-15");
     expect_output("5!!", "15");
     expect_output("5!!", "15");
     expect_output("5!!!", "10");
     expect_output("5!!!", "10");
     expect_output("5!!!!", "5");
     expect_output("5!!!!", "5");