diff options
author | David Robillard <d@drobilla.net> | 2020-08-14 18:39:36 +0200 |
---|---|---|
committer | David Robillard <d@drobilla.net> | 2020-08-14 19:07:52 +0200 |
commit | 64c9584f174f4161963d1e756e4cfadce5793d69 (patch) | |
tree | b9fcfd0ed967793eefd942be9a8aa31d278b7206 | |
parent | bc01889ccdfff3b39a93a537c9e92745d327e5da (diff) | |
download | serd-64c9584f174f4161963d1e756e4cfadce5793d69.tar.gz serd-64c9584f174f4161963d1e756e4cfadce5793d69.tar.bz2 serd-64c9584f174f4161963d1e756e4cfadce5793d69.zip |
Avoid use of rand()
-rw-r--r-- | .clang-tidy | 2 | ||||
-rw-r--r-- | tests/serd_test.c | 13 |
2 files changed, 3 insertions, 12 deletions
diff --git a/.clang-tidy b/.clang-tidy index 93269b93..19c7db5c 100644 --- a/.clang-tidy +++ b/.clang-tidy @@ -5,8 +5,6 @@ Checks: > -android-cloexec-fopen, -bugprone-branch-clone, -bugprone-suspicious-string-compare, - -cert-msc30-c, - -cert-msc50-cpp, -clang-analyzer-alpha.*, -clang-analyzer-valist.Uninitialized, -google-readability-todo, diff --git a/tests/serd_test.c b/tests/serd_test.c index fbc42bcd..15500a0e 100644 --- a/tests/serd_test.c +++ b/tests/serd_test.c @@ -173,15 +173,6 @@ test_read_chunks(void) static void test_string_to_double(void) { -#define MAX 1000000 -#define NUM_TESTS 1000 - for (int i = 0; i < NUM_TESTS; ++i) { - double dbl = rand() % MAX; - dbl += (rand() % MAX) / (double)MAX; - - test_strtod(dbl, 1 / (double)MAX); - } - const double expt_test_nums[] = { 2.0E18, -5e19, +8e20, 2e+24, -5e-5, 8e0, 9e-0, 2e+0 }; @@ -194,6 +185,8 @@ test_string_to_double(void) const double num = serd_strtod(expt_test_strs[i], NULL); const double delta = fabs(num - expt_test_nums[i]); assert(delta <= DBL_EPSILON); + + test_strtod(expt_test_nums[i], DBL_EPSILON); } } @@ -246,7 +239,7 @@ test_blob_to_node(void) for (size_t size = 0; size < 256; ++size) { uint8_t* data = size > 0 ? (uint8_t*)malloc(size) : NULL; for (size_t i = 0; i < size; ++i) { - data[i] = (uint8_t)(rand() % 256); + data[i] = (uint8_t)((size + i) % 256); } SerdNode blob = serd_node_new_blob(data, size, size % 5); |