-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMain.cpp
More file actions
80 lines (60 loc) · 1.09 KB
/
Main.cpp
File metadata and controls
80 lines (60 loc) · 1.09 KB
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
#include "String.h"
#include "Stack.h"
#include "Integer.h"
#include <iostream>
using namespace std;
bool string_tests();
bool stack_tests();
bool integer_tests();
typedef bool (*func_ptr_t)(void);
func_ptr_t tests[] = {
&string_tests,
&stack_tests,
&integer_tests,
NULL
};
int main(int argc, char **argv) {
int i = 0, passed = 0;
while (tests[i] != NULL) {
if(tests[i]()) {
cout << "pass\n" ;
++passed;
}
else {
cout << "fail\n" ;
}
i++;
}
cout << passed << '/' << i << " tests passed.\n" ;
return 0;
}
bool string_tests() {
String a("hi"), b, c("bye");
b = a;
return (a == b) && !(a == c);
}
bool stack_tests() {
bool success = true;
Stack<char> s;
if (!s.empty())
success = false;
s.push('A');
s.push('B');
if (s.size() != 2)
success = false;
if (s.pop() != 'B')
success = false;
if (s.pop() != 'A')
success = false;
return s.empty();
}
bool integer_tests() {
int i;
String s, answer("0x350ed972b7230ec8e482387a8997cee5a5d");
Integer n(1);
for (i = 0; i < 5; i++) {
n = n * 0xbadf00d;
}
s = n.toHexString();
return (s == answer);
}