-
Notifications
You must be signed in to change notification settings - Fork 0
/
test.c
38 lines (28 loc) · 776 Bytes
/
test.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
#include "base-conv.h"
#include <string.h>
#include <assert.h>
void test_parse(void) {
uint64_t parsed;
parse_number("1234", 10, &parsed);
assert(parsed == 1234);
parse_number("DEADBEEF", 16, &parsed);
assert(parsed == 0xDEADBEEF);
assert(parse_number("!", 10, &parsed));
}
void test_serialize(void) {
char buf[65];
assert(strcmp(serialize_number(1234, 10, buf), "1234") == 0);
assert(strcmp(serialize_number(0xDEADBEEF, 16, buf), "DEADBEEF") == 0);
}
void test_digit_char(void) {
assert(char_to_digit('A') == 10);
assert(char_to_digit('3') == 3);
assert(digit_to_char(35) == 'Z');
assert(digit_to_char(10) == 'A');
}
int main(void) {
test_parse();
test_serialize();
test_digit_char();
return 0;
}