-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest.h
61 lines (57 loc) · 1.83 KB
/
test.h
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
#include <cmath>
#include <iostream>
#include "calculator.h"
#include <cassert>
#include <gtest/gtest.h>
TEST(CaculatorTest, add) {
ASSERT_EQ(calculator::add(1, 2), 3);
ASSERT_EQ(calculator::add(0, 0), 0);
ASSERT_EQ(calculator::add(1, -1),0);
ASSERT_EQ(calculator::add(-1, -1),-2);
}
TEST(CaculatorTest, exponentiate) {
ASSERT_DOUBLE_EQ(calculator::exponentiate(1, 2), 3);
ASSERT_DOUBLE_EQ(calculator::exponentiate(0, 0), 0);
ASSERT_DOUBLE_EQ(calculator::exponentiate(1, -1),0);
ASSERT_DOUBLE_EQ(calculator::exponentiate(-2, -1),-0.5);
}
class Test {
public:
Test() {}
static Test getIntance() {
static Test instance;
return instance;
}
void TEST_ADD() {
assert(calculator::add(1, 2) == 3);
assert(calculator::add(0, 0) == 0);
assert(calculator::add(1, -1) == 0);
assert(calculator::add(-1, -1) == -2);
}
void TEST_SUBTRACT() {
assert(calculator::subtract(1, 2) == -1);
assert(calculator::subtract(0, 0) == 0);
assert(calculator::subtract(1, -1) == 2);
assert(calculator::subtract(-1, -1) == 0);
}
void TEST_MULTIPLE() {
assert(calculator::multiply(1, 2) == 2);
assert(calculator::multiply(0, 0) == 0);
assert(calculator::multiply(1, -1) == -1);
assert(calculator::multiply(-1, -1) == 1);
}
void TEST_EXPONENTIATE() {
assert(calculator::exponentiate(1, 2) == 1);
assert(calculator::exponentiate(0, 0) == 1);
assert(calculator::exponentiate(1, -1) == 1);
assert(calculator::exponentiate(-1, -2) == 1);
assert(calculator::exponentiate(-2, -1) == -0.5);
}
void RUN_ALL_TEST() {
TEST_ADD();
TEST_SUBTRACT();
TEST_MULTIPLE();
TEST_EXPONENTIATE();
std::cout << "RAN ALL TESTS" << std::endl;
}
};