tests: More work on error handling
This commit is contained in:
+26
-2
@@ -4,7 +4,31 @@
|
||||
#include "test_helpers.h"
|
||||
|
||||
int main(void) {
|
||||
printf("%d\n", rand());
|
||||
// Uninitialized generator
|
||||
int rand_uninit = rand();
|
||||
printf("%d\n", rand_uninit);
|
||||
|
||||
// Testing the reproducibility of values
|
||||
srand(259);
|
||||
printf("%d\n", rand());
|
||||
int rand_seed259_1 = rand();
|
||||
printf("%d\n", rand_seed259_1);
|
||||
|
||||
srand(259);
|
||||
int rand_seed259_2 = rand();
|
||||
printf("%d\n", rand_seed259_2);
|
||||
|
||||
if (rand_seed259_1 != rand_seed259_2) {
|
||||
puts("rand() doesn't return reproducible values");
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
|
||||
// Seed value 1 should return the same values as the ininitialized generator
|
||||
srand(1);
|
||||
int rand_seed1 = rand();
|
||||
printf("%d\n", rand_seed1);
|
||||
|
||||
if (rand_uninit != rand_seed1) {
|
||||
puts("srand(1) doesn't work");
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user