forked from cleolibrary/CLEO4
-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
180 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
{$CLEO .s} | ||
{$INCLUDE_ONCE ../cleo_tester.inc} | ||
|
||
script_name '0098' | ||
test("0098 (generate_random_float)", tests) | ||
terminate_this_custom_script | ||
|
||
|
||
function tests | ||
it("should generate random floats", test1) | ||
return | ||
|
||
function test1 | ||
float min = 999.0 | ||
float max = -999.0 | ||
float avg = 0.0 | ||
|
||
int i | ||
for i = 1 to 1000 | ||
float value = generate_random_float | ||
|
||
if | ||
value < min | ||
then | ||
min = value | ||
end | ||
|
||
if | ||
value > max | ||
then | ||
max = value | ||
end | ||
|
||
avg += value | ||
end | ||
avg /= 1000.0 | ||
|
||
assert_rangef(min, 0.00, 0.05) | ||
assert_rangef(max, 0.95, 1.00) | ||
assert_rangef(avg, 0.40, 0.60) // expected value of uniform distribution | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
{$CLEO .s} | ||
{$INCLUDE_ONCE ../cleo_tester.inc} | ||
|
||
script_name '0208' | ||
test("0208 (generate_random_float_in_range)", tests) | ||
terminate_this_custom_script | ||
|
||
function tests | ||
it("should generate random floats in range", test1) | ||
return | ||
|
||
function test1 | ||
float min = 999.0 | ||
float max = -999.0 | ||
float avg = 0.0 | ||
|
||
int i | ||
for i = 1 to 2000 | ||
float value = generate_random_float_in_range {min} -10.0 {max} 40.0 | ||
|
||
if | ||
value < min | ||
then | ||
min = value | ||
end | ||
|
||
if | ||
value > max | ||
then | ||
max = value | ||
end | ||
|
||
avg += value | ||
end | ||
avg /= 2000.0 | ||
|
||
assert_rangef(min, -10.0, -9.0) | ||
assert_rangef(max, 39.0, 40.0) | ||
assert_rangef(avg, 14.0, 16.0) // expected value of uniform distribution | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
{$CLEO .s} | ||
{$INCLUDE_ONCE ../cleo_tester.inc} | ||
|
||
script_name '0209' | ||
test("0209 (generate_random_int_in_range)", tests) | ||
terminate_this_custom_script | ||
|
||
function tests | ||
it("should generate random ints in range", test1) | ||
return | ||
|
||
function test1 | ||
int min = 999 | ||
int max = -999 | ||
int avg = 0 | ||
|
||
int i | ||
for i = 1 to 2000 | ||
int value = generate_random_int_in_range {min} -10 {max} 40 | ||
|
||
if | ||
value < min | ||
then | ||
min = value | ||
end | ||
|
||
if | ||
value > max | ||
then | ||
max = value | ||
end | ||
|
||
avg += value | ||
end | ||
avg /= 2000 | ||
|
||
assert_eq(min, -10) | ||
assert_eq(max, 40) | ||
assert_range(avg, 14, 16) // expected value of uniform distribution | ||
end | ||
end |