-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.cpp
More file actions
69 lines (63 loc) · 1.29 KB
/
Copy pathmain.cpp
File metadata and controls
69 lines (63 loc) · 1.29 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
/*
Author: Graeme Bates
*/
#include "test.h"
#include <iostream>
int sum(int a, int b){
int i=0;
int out=a;
while(i < abs(b)){
if(b<0){
out--;
} else{
out++;
}
i++;
}
return out;
}
void test_simple_case(test_result& r){
if(sum(1,2)==3){
r.passed=true;
} else {
r.log="Expected:3 Got:"+std::to_string(sum(1,2));
r.passed=false;
}
}
void test_negative_inputs(test_result& r){
if(sum(1,-2)==-1){
r.passed=true;
} else {
r.log="Expected:-1 Got:"+std::to_string(sum(1,-2));
r.passed=false;
}
}
void test_will_fail(test_result& r){
r.log="Intentional fail";
r.passed=false;
}
void test_random_cases(test_result& r){
int a = rand()%100;
int b = rand()%100;
int result=sum(a,b);
int expected=a+b;
if(result==expected){
r.passed=true;
} else {
r.passed=false;
}
}
int main(){
srand((unsigned) time(NULL));
Test tester=Test("Sum function tests");
tester.add_test("Simple Addition Tests", test_simple_case);
tester.add_test("Negative Number Test", test_negative_inputs);
tester.add_test("Will Fail", test_will_fail);
tester.add_test("Random inputs", test_random_cases, 10);
tester.add_test("Lambda test", [](test_result& r)->void{
r.passed=true;
});
tester.run();
tester.run("test.txt");
return 0;
}