()
| 1419 | |
| 1420 | #[test] |
| 1421 | fn test_randomize_and_rnd() { |
| 1422 | // These tests could lead to flakiness if the PRNG happens to yield the same number twice |
| 1423 | // in a row because we did not previously configure the seed. It is very unlikely though, |
| 1424 | // and we need a way to test that the PRNG was initialized before we call RANDOMIZE. |
| 1425 | check_expr_ok(false, "RND(1) = RND(1)"); |
| 1426 | check_expr_ok(false, "RND(1) = RND(10)"); |
| 1427 | check_expr_ok(true, "RND(-1) = RND(-1)"); |
| 1428 | check_expr_ok(false, "RND(-1) = RND(-2)"); |
| 1429 | check_expr_ok(true, "RND(0) = RND(0)"); |
| 1430 | |
| 1431 | Tester::default() |
| 1432 | .run("RANDOMIZE 10") |
| 1433 | .check() |
| 1434 | .run("result = RND(1)") |
| 1435 | .expect_var("result", 0.7097578208683426) |
| 1436 | .check() |
| 1437 | .run("result = RND(-1)") |
| 1438 | .expect_var("result", 0.6150244305876607) |
| 1439 | .check() |
| 1440 | .run("result = RND(1)") |
| 1441 | .expect_var("result", 0.11707478019340774) |
| 1442 | .check() |
| 1443 | .run("result = RND(-1)") |
| 1444 | .expect_var("result", 0.6150244305876607) |
| 1445 | .check() |
| 1446 | .run("result = RND(1.1)") |
| 1447 | .expect_var("result", 0.11707478019340774) |
| 1448 | .check() |
| 1449 | .run("result = RND(0)") |
| 1450 | .expect_var("result", 0.11707478019340774) |
| 1451 | .check() |
| 1452 | .run("result = RND(10)") |
| 1453 | .expect_var("result", 0.8423819585801992) |
| 1454 | .check() |
| 1455 | .run("RANDOMIZE 10.2") |
| 1456 | .expect_var("result", 0.8423819585801992) |
| 1457 | .check() |
| 1458 | .run("result = RND(1)") |
| 1459 | .expect_var("result", 0.7097578208683426) |
| 1460 | .check(); |
| 1461 | |
| 1462 | check_expr_compilation_error("1:10: RND expected <> | <n%>", "RND(1, 7)"); |
| 1463 | check_expr_compilation_error("1:14: BOOLEAN is not a number", "RND(FALSE)"); |
| 1464 | |
| 1465 | check_stmt_compilation_err("1:1: RANDOMIZE expected <> | <seed%>", "RANDOMIZE ,"); |
| 1466 | check_stmt_compilation_err("1:11: BOOLEAN is not a number", "RANDOMIZE TRUE"); |
| 1467 | } |
| 1468 | |
| 1469 | #[test] |
| 1470 | fn test_round() { |
nothing calls this directly
no test coverage detected