Add native RND and ASC functions
Some checks failed
akbasic CI Build / cmake_build (push) Failing after 40s
akbasic CI Build / sanitizers (push) Failing after 45s
akbasic CI Build / coverage (push) Failing after 48s
akbasic CI Build / akgl_build (push) Failing after 49s
akbasic CI Build / mutation_test (push) Failing after 45s
Some checks failed
akbasic CI Build / cmake_build (push) Failing after 40s
akbasic CI Build / sanitizers (push) Failing after 45s
akbasic CI Build / coverage (push) Failing after 48s
akbasic CI Build / akgl_build (push) Failing after 49s
akbasic CI Build / mutation_test (push) Failing after 45s
Implement bounded random integers with lazy clock seeding and add ASC as the inverse of CHR. Cover dispatch, validation, deterministic LCG output, UTF-8 round trips, function reference, and the breakout tutorial. Closes #16. Co-authored-by: andrew <andrew@aklabs.net>
This commit is contained in:
3
tests/language/functions/asc.bas
Normal file
3
tests/language/functions/asc.bas
Normal file
@@ -0,0 +1,3 @@
|
||||
10 PRINT "97 : " + ASC("a")
|
||||
20 PRINT "65 : " + ASC("A")
|
||||
30 PRINT "64 : " + ASC("@")
|
||||
3
tests/language/functions/asc.txt
Normal file
3
tests/language/functions/asc.txt
Normal file
@@ -0,0 +1,3 @@
|
||||
97 : 97
|
||||
65 : 65
|
||||
64 : 64
|
||||
@@ -162,6 +162,26 @@ int main(void)
|
||||
expect_int("A# = INSTR(\"HELLO\", \"LL\")", 2);
|
||||
expect_int("A# = INSTR(\"HELLO\", \"ZZ\")", -1);
|
||||
|
||||
/* RND auto-seeds from host time and follows the documented LCG. */
|
||||
HARNESS_RUNTIME.rndseeded = false;
|
||||
TEST_REQUIRE_OK(akbasic_runtime_settime(&HARNESS_RUNTIME, 12345));
|
||||
expect_int("A# = RND(6)", 0);
|
||||
expect_int("A# = RND(6)", 4);
|
||||
expect_int("A# = RND(6)", 1);
|
||||
expect_int("A# = RND(6)", 0);
|
||||
expect_int("A# = RND(6)", 1);
|
||||
expect_int("A# = RND(1)", 0);
|
||||
TEST_REQUIRE_STATUS(eval_line("A# = RND(0)", &out), AKBASIC_ERR_VALUE);
|
||||
TEST_REQUIRE_STATUS(eval_line("A# = RND(-1)", &out), AKBASIC_ERR_VALUE);
|
||||
TEST_REQUIRE_STATUS(eval_line("A# = RND(\"x\")", &out), AKBASIC_ERR_TYPE);
|
||||
|
||||
/* ASC is the inverse of CHR for ASCII and non-ASCII code points. */
|
||||
expect_int("A# = ASC(CHR(97))", 97);
|
||||
expect_int("A# = ASC(\"A\")", 65);
|
||||
expect_int("A# = ASC(CHR(8364))", 8364);
|
||||
TEST_REQUIRE_STATUS(eval_line("A# = ASC(\"\")", &out), AKBASIC_ERR_BOUNDS);
|
||||
TEST_REQUIRE_STATUS(eval_line("A# = ASC(65)", &out), AKBASIC_ERR_TYPE);
|
||||
|
||||
/* An unknown verb is diagnosed rather than silently ignored. */
|
||||
TEST_REQUIRE_OK(akbasic_environment_zero(HARNESS_RUNTIME.environment));
|
||||
TEST_REQUIRE_STATUS(akbasic_runtime_evaluate(&HARNESS_RUNTIME, NULL, &out),
|
||||
|
||||
Reference in New Issue
Block a user