-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Also added unit test for low-level string conversion functions.
- Loading branch information
1 parent
c50d06f
commit 08a417b
Showing
5 changed files
with
77 additions
and
19 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -273,7 +273,8 @@ CHECK_P := \ | |
pmove \ | ||
pnorm \ | ||
pzero \ | ||
negnot | ||
negnot \ | ||
strings | ||
|
||
CHECK_Z := \ | ||
getset \ | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
#include "../check.h" | ||
#include <stdio.h> | ||
#include <stdlib.h> | ||
|
||
static struct hebi_kiss kiss = HEBI_KISS_INIT; | ||
|
||
/* packet buffers for stress test */ | ||
enum { MAX_PACKETS = 16 }; | ||
static hebi_packet x[MAX_PACKETS + 1]; | ||
static hebi_packet y[MAX_PACKETS + 1]; | ||
static hebi_packet z[MAX_PACKETS + 1]; | ||
|
||
/* room for all base 2 digits, optional radix prefix and null terminator */ | ||
enum { MAX_LENGTH = MAX_PACKETS * HEBI_PACKET_BIT + 2 + 1 }; | ||
static char str[MAX_LENGTH]; | ||
|
||
static void | ||
stresstest(unsigned int flags) | ||
{ | ||
size_t i, m, n, bits, len; | ||
unsigned int base; | ||
|
||
for (i = 0; i < MAX_PACKETS * HEBI_PACKET_BIT; i++) { | ||
/* get next random value */ | ||
bits = i; | ||
n = (bits + HEBI_PACKET_BIT - 1) / HEBI_PACKET_BIT; | ||
if (n > 0) { | ||
hebi_prand_kiss(x, n, bits, &kiss); | ||
n = hebi_pnorm(x, n); /* TODO: fix prand */ | ||
} | ||
|
||
/* test converting to string and back for each base */ | ||
for (base = 2; base <= 62 /* TODO: 63 & 64 */; base++) { | ||
hebi_pcopy(z, x, n); | ||
len = hebi_pgetstr(str, sizeof(str), z, n, base, flags); | ||
assert(len > 0 && len < sizeof(str)); | ||
|
||
hebi_pzero(y, MAX_PACKETS + 1); | ||
m = hebi_psetstr(y, MAX_PACKETS + 1, str, len, base, flags); | ||
assert(m == n && hebi_pcmp(x, y, m) == 0); | ||
} | ||
} | ||
} | ||
|
||
int | ||
main(int argc, char *argv[]) | ||
{ | ||
checkinit(argc, argv); | ||
stresstest(HEBI_STR_CLASSIC_ALPHABET); | ||
return 0; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters