mirror of
https://github.com/krgamestudios/Toy.git
synced 2026-04-15 23:04:08 +10:00
Moved tests from scripts/ to test/scripts/
This commit is contained in:
50
test/scripts/lib/interactions.toy
Normal file
50
test/scripts/lib/interactions.toy
Normal file
@@ -0,0 +1,50 @@
|
||||
//test the standard library, under a number of different circumstances
|
||||
|
||||
//test basic import
|
||||
{
|
||||
import standard;
|
||||
|
||||
//this depends on external factors, so only check the length
|
||||
assert clock().length() == 24, "import library failed";
|
||||
}
|
||||
|
||||
|
||||
//test import within a function
|
||||
{
|
||||
fn f() {
|
||||
import standard;
|
||||
|
||||
assert clock != null, "import library within function failed";
|
||||
|
||||
return clock;
|
||||
}
|
||||
|
||||
//invoke
|
||||
assert f()().length() == 24, "import library within function and return failed";
|
||||
}
|
||||
|
||||
|
||||
//test closing over standard library element
|
||||
{
|
||||
import standard;
|
||||
|
||||
fn f() {
|
||||
assert clock != null, "import library outside function failed";
|
||||
|
||||
return clock;
|
||||
}
|
||||
|
||||
//invoke
|
||||
assert f()().length() == 24, "import library outside function and return failed";
|
||||
}
|
||||
|
||||
|
||||
//test importing as an alias
|
||||
{
|
||||
import standard as std;
|
||||
|
||||
assert std["clock"]().length() == 24, "import library as alias failed";
|
||||
}
|
||||
|
||||
|
||||
print "All good";
|
||||
10
test/scripts/lib/standard.toy
Normal file
10
test/scripts/lib/standard.toy
Normal file
@@ -0,0 +1,10 @@
|
||||
//test the standard library
|
||||
{
|
||||
import standard;
|
||||
|
||||
//this depends on external factors, so only check the length
|
||||
assert clock().length() == 24, "clock() import failed";
|
||||
}
|
||||
|
||||
|
||||
print "All good";
|
||||
56
test/scripts/lib/timer.toy
Normal file
56
test/scripts/lib/timer.toy
Normal file
@@ -0,0 +1,56 @@
|
||||
//test the timer library
|
||||
{
|
||||
//create a timer, manipulate it's values
|
||||
import timer;
|
||||
|
||||
//create a timer
|
||||
var timer: opaque = createTimer();
|
||||
|
||||
//set the timer
|
||||
timer.setTimer(42, 8891);
|
||||
|
||||
//check the timer values
|
||||
assert timer.getTimerSeconds() == 42, "getTimerSeconds() failed";
|
||||
assert timer.getTimerMicroseconds() == 42, "getTimerMicroseconds() failed";
|
||||
}
|
||||
|
||||
{
|
||||
//create a timer, run it for a short time
|
||||
import timer;
|
||||
|
||||
var timerA: opaque = createTimer();
|
||||
|
||||
timerA.startTimer();
|
||||
for (var i: int = 0; i < 1000 * 1000; i++);
|
||||
timerA.stopTimer();
|
||||
|
||||
//create another timer, run it for a longer time
|
||||
var timerB: opaque = createTimer();
|
||||
|
||||
timerB.startTimer();
|
||||
for (var i: int = 0; i < 1000 * 1000 * 10; i++);
|
||||
timerB.stopTimer();
|
||||
|
||||
//check to ensure that the second timer took longer than the first
|
||||
//WARNING: this has the small possibility of failing due to external factors
|
||||
var difference: opaque = timerA.compareTimer(timerB);
|
||||
|
||||
assert difference.getTimerSeconds() >= 0, "compareTimer() (seconds) failed";
|
||||
if (difference.getTimerSeconds() == 0) {
|
||||
assert difference.getTimerMicroseconds() >= 0, "compareTimer() (microseconds) failed";
|
||||
}
|
||||
}
|
||||
|
||||
{
|
||||
//set a timer to check string representation
|
||||
import timer;
|
||||
|
||||
var timer: opaque = createTimer();
|
||||
|
||||
timer.setTimer(42, 999);
|
||||
|
||||
assert timer.timerToString() == "42.999", "timerToString() failed";
|
||||
}
|
||||
|
||||
|
||||
print "All good";
|
||||
Reference in New Issue
Block a user