aboutsummaryrefslogtreecommitdiff
path: root/tests/runner.py
diff options
context:
space:
mode:
authormax99x <max99x@gmail.com>2011-08-23 11:17:50 +0300
committermax99x <max99x@gmail.com>2011-08-23 11:17:50 +0300
commit7eb19241b1ff145a51912bfa02ffda7d913494d3 (patch)
tree7bc82982326d55af9733050a10e5dbd83e09b20a /tests/runner.py
parentdc1e8a0fb689436866d253036090e9fe7d4f3d73 (diff)
Implemented rand(), rand_r() and srand() using a simple Linear Congruential Generator.
Diffstat (limited to 'tests/runner.py')
-rw-r--r--tests/runner.py42
1 files changed, 42 insertions, 0 deletions
diff --git a/tests/runner.py b/tests/runner.py
index 438726af..77aa0d4f 100644
--- a/tests/runner.py
+++ b/tests/runner.py
@@ -2043,6 +2043,48 @@ if 'benchmark' not in sys.argv:
output_nicerizer=lambda x: x.replace('\n', '*'),
post_build=add_pre_run_and_checks)
+ def test_rand(self):
+ src = r'''
+ #include <stdio.h>
+ #include <stdlib.h>
+
+ int main() {
+ printf("%d\n", rand());
+ printf("%d\n", rand());
+
+ srand(123);
+ printf("%d\n", rand());
+ printf("%d\n", rand());
+ srand(123);
+ printf("%d\n", rand());
+ printf("%d\n", rand());
+
+ unsigned state = 0;
+ int r;
+ r = rand_r(&state);
+ printf("%d, %u\n", r, state);
+ r = rand_r(&state);
+ printf("%d, %u\n", r, state);
+ state = 0;
+ r = rand_r(&state);
+ printf("%d, %u\n", r, state);
+
+ return 0;
+ }
+ '''
+ expected = '''
+ 1250496027
+ 1116302336
+ 440917656
+ 1476150784
+ 440917656
+ 1476150784
+ 12345, 12345
+ 1406932606, 3554416254
+ 12345, 12345
+ '''
+ self.do_test(src, re.sub(r'(^|\n)\s+', r'\1', expected))
+
def test_strtod(self):
src = r'''
#include <stdio.h>