fix: fix testing code
ci/woodpecker/push/woodpecker Pipeline was successful
Details
ci/woodpecker/push/woodpecker Pipeline was successful
Details
parent
2d89c5e80f
commit
a6e7b1dfd3
37
test/fuzzy.h
37
test/fuzzy.h
|
@ -4,6 +4,7 @@
|
|||
#include <stdlib.h>
|
||||
#include <stdbool.h>
|
||||
#include <string.h>
|
||||
#include <stdio.h>
|
||||
|
||||
typedef struct fuzzyconfig {
|
||||
int seed;
|
||||
|
@ -29,12 +30,14 @@ void random_clean_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;
|
||||
int val = rand();
|
||||
|
||||
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();
|
||||
s[i] = ((char *) &val)[0];
|
||||
s[i] = (char)(val % 256);
|
||||
}
|
||||
|
||||
// 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
|
||||
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
|
||||
// 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
|
||||
// cannot be in the trie yet.
|
||||
if (changed == *contains_dedupped[i]) {
|
||||
exit_code = 1;
|
||||
goto END;
|
||||
}
|
||||
// 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
|
||||
// changed is true, *contains_dedupped[i] should be false, as the string
|
||||
// cannot be in the trie yet.
|
||||
if (changed == *contains_dedupped[i]) {
|
||||
exit_code = 1;
|
||||
goto END;
|
||||
}
|
||||
|
||||
if (!*contains_dedupped[i]) {
|
||||
*contains_dedupped[i] = true;
|
||||
size++;
|
||||
}
|
||||
if (!*contains_dedupped[i]) {
|
||||
*contains_dedupped[i] = true;
|
||||
size++;
|
||||
}
|
||||
}
|
||||
|
||||
// Ensure size is correct
|
||||
|
|
Loading…
Reference in New Issue