Added abs(), hash() to libstandard

This commit is contained in:
2023-02-23 18:36:12 +11:00
parent cdca6fa45c
commit 3e6d21afbb
2 changed files with 95 additions and 0 deletions

View File

@@ -1,5 +1,18 @@
import standard;
//test abs
{
assert abs(-5) == 5, "abs(-integer) failed";
assert abs(-5.5) == 5.5, "abs(-float) failed";
assert abs(5) == 5, "abs(+integer) failed";
assert abs(5.5) == 5.5, "abs(+float) failed";
var x = -5;
assert x.abs() == 5, "var.abs() failed";
}
//test clock
{
//this depends on external factors, so only check the length
@@ -162,6 +175,13 @@ import standard;
}
//test hash
{
assert typeof "Hello world".hash() == int, "typeof \"Hello world\".hash() failed";
assert "Hello world".hash() == 994097935, "\"Hello world\".hash() failed"; //NOTE: specific value based on algorithm
}
//test indexOf
{
var a = [1, 2, 42, 3];