tests: More work on error handling

This commit is contained in:
Tibor Nagy
2019-02-24 00:46:26 +01:00
parent 0c539d6e4e
commit 2d027f0771
14 changed files with 126 additions and 52 deletions
+26 -2
View File
@@ -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);
}
}