fix: fix testing code
ci/woodpecker/push/woodpecker Pipeline was successful Details

trie-skips
Jef Roosens 2022-12-03 21:00:07 +01:00
parent 2d89c5e80f
commit a6e7b1dfd3
Signed by: Jef Roosens
GPG Key ID: B75D4F293C7052DB
1 changed files with 20 additions and 17 deletions

View File

@ -4,6 +4,7 @@
#include <stdlib.h> #include <stdlib.h>
#include <stdbool.h> #include <stdbool.h>
#include <string.h> #include <string.h>
#include <stdio.h>
typedef struct fuzzyconfig { typedef struct fuzzyconfig {
int seed; int seed;
@ -29,12 +30,14 @@ void random_clean_string(char* s, int len) {
} }
void random_string(char* s, int len) { void random_string(char* s, int len) {
// len - 1 ensures that we can still set the null byte for the final byte int val = rand();
int val;
for (int i = 0; i < len - 1; i++) { // String can't be an empty string as they aren't supported
s[0] = (char)(val % 255 + 1);
for (int i = 1; i < len - 1; i++) {
val = rand(); val = rand();
s[i] = ((char *) &val)[0]; s[i] = (char)(val % 256);
} }
// Just in case no null characters were created // Just in case no null characters were created
@ -110,21 +113,21 @@ int fuzzy_test_trie_seed(FuzzyConfig conf, void* (*init_func) (), void (*free_fu
// Add all strings to trie, checking for duplicates // Add all strings to trie, checking for duplicates
for (int i = 0; i < conf.word_count; i++) { for (int i = 0; i < conf.word_count; i++) {
changed = add_func(ct, matrix[i], NULL); changed = add_func(ct, matrix[i], NULL);
// if changed is false, *contains_dedupped[i] should be true, as changed // if changed is false, *contains_dedupped[i] should be true, as changed
// can only be false if the string is already contained in the trie. if // can only be false if the string is already contained in the trie. if
// changed is true, *contains_dedupped[i] should be false, as the string // changed is true, *contains_dedupped[i] should be false, as the string
// cannot be in the trie yet. // cannot be in the trie yet.
if (changed == *contains_dedupped[i]) { if (changed == *contains_dedupped[i]) {
exit_code = 1; exit_code = 1;
goto END; goto END;
} }
if (!*contains_dedupped[i]) { if (!*contains_dedupped[i]) {
*contains_dedupped[i] = true; *contains_dedupped[i] = true;
size++; size++;
} }
} }
// Ensure size is correct // Ensure size is correct