forked from riteshkranjan/apc_2018
-
Notifications
You must be signed in to change notification settings - Fork 0
/
unit_test.c
82 lines (75 loc) · 1.92 KB
/
unit_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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
#include <assert.h>
#include <stdio.h>
#include "stack.h"
#include "bitwise.h"
#include "base64.h"
#include "base64_decoder.h"
#include <string.h>
#include <stdlib.h>
void test_stack() {
printf("Testing bitwise...\n");
push(1);
push(2);
push(3);
assert(isEmpty() == 0);
assert(peek() == 3);
assert(pop() == 3);
assert(pop() == 2);
assert(pop() == 1);
assert(isEmpty() == 1);
printf("stack : all test cases passed\n");
}
void test_linkedlist() {
printf("Testing bitwise...\n");
insertFirst(1);
insertFirst(2);
insertFirst(3);
assert(is_empty() == 0);
assert(deleteFirst() == 3);
assert(deleteFirst() == 2);
assert(deleteFirst() == 1);
assert(is_empty() == 1);
printf("linkedlist : all test cases passed\n");
}
void test_bitwise() {
printf("Testing bitwise...\n");
assert(sign(-5) == -1);
assert(sign(0) == 0);
assert(sign(5) == 1);
assert(bitAnd(1, 3) == 1);
assert(bitXor(1, 3) == 2);
assert(getByte(0xABCD, 0) == 0xCD);
assert(getByte(0xABCD, 1) == 0xAB);
assert(logicalShift(-1,30)==3);
assert(bang(5) == 0);
assert(bang(-5) == 0);
assert(bang(0) == 1);
assert(conditional(5, 4, 6) == 4);
assert(conditional(0, 4, 6) == 6);
assert(isPower2(8) == 1);
assert(isPower2(7) == 0);
assert(isPower2(-8) == 0);
printf("bitwise : all test cases passed...\n");
}
void test_base64_encoder(){
printf("Testing base 64 encoder..\n");
assert(strcmp("YWJjZA==",encode("abcd"))==0);
assert(strcmp("YWJjZGU=",encode("abcde"))==0);
assert(strcmp("YWJjZGVm",encode("abcdef"))==0);
printf("Base 64 encoder : all test cases passed...\n");
}
void test_base64_decoder(){
printf("Testing base 64 decoder..\n");
assert(strcmp(decode("YWJjZA=="),"abcd")==0);
assert(strcmp(decode("YWJjZGU="),"abcde")==0);
assert(strcmp(decode("YWJjZGVm"),"abcdef")==0);
printf("Base 64 decoder : all test cases passed...\n");
}
int main() {
test_linkedlist();
test_stack();
test_bitwise();
test_base64_encoder();
test_base64_decoder();
return 1;
}