mirror of
https://github.com/krgamestudios/Toy.git
synced 2026-04-15 14:54:07 +10:00
Added abs(), hash() to libstandard
This commit is contained in:
@@ -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];
|
||||
|
||||
Reference in New Issue
Block a user