-
Notifications
You must be signed in to change notification settings - Fork 0
/
add_test.h
93 lines (80 loc) · 2.65 KB
/
add_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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
#ifndef __ADD_TEST_H__
#define __ADD_TEST_H__
#include "gtest/gtest.h"
#include "add.h"
#include "op_mock.h"
#include "rand_mock.h"
#include "sub_mock.h"
#include "mult_mock.h"
#include "div_mock.h"
#include "pow_mock.h"
TEST(AddTest, ThreePlusTwo) {
Base* three = new Op(3);
Base* two = new Op(2);
Add* add = new Add(three, two);
EXPECT_DOUBLE_EQ(add->evaluate(), 5.000000);
EXPECT_EQ(add->stringify(), "(3.000000 + 2.000000)");
}
TEST(AddTest, LargeNumbers) {
Base* large1 = new Op(1234);
Base* large2 = new Op(5678);
Add* add = new Add(large1, large2);
EXPECT_DOUBLE_EQ(add->evaluate(), 6912.000000);
EXPECT_EQ(add->stringify(), "(1234.000000 + 5678.000000)");
}
TEST(AddTest, Negatives) {
Base* negative1 = new Op(-3);
Base* negative2 = new Op(-2);
Add* add = new Add(negative1, negative2);
EXPECT_DOUBLE_EQ(add->evaluate(), -5.000000);
EXPECT_EQ(add->stringify(), "(-3.000000 + -2.000000)");
}
TEST(AddTest, Zero) {
Base* number = new Op(69);
Base* zero = new Op(0);
Add* add = new Add(number, zero);
EXPECT_DOUBLE_EQ(add->evaluate(), 69.000000);
EXPECT_EQ(add->stringify(), "(69.000000 + 0.000000)");
}
TEST(AddTest, Op_Mock) {
Base* mock = new Op_Mock(); // 3
Base* add = new Add(mock, mock);
EXPECT_DOUBLE_EQ(add->evaluate(), 6.000000);
EXPECT_EQ(add->stringify(), "(3.000000 + 3.000000)");
}
TEST(AddTest, Sub_Mock) {
Base* mock = new Sub_Mock(); // 3 - 2
Base* number = new Op(4);
Base* add = new Add(mock, number); // (3 - 2) + 4
EXPECT_DOUBLE_EQ(add->evaluate(), 5.000000);
EXPECT_EQ(add->stringify(), "((3.000000 - 2.000000) + 4.000000)");
}
TEST(AddTest, Rand_Mock) {
Base* mock = new Rand_Mock(); // 123
Base* number = new Op(4);
Base* add = new Add(mock, number); // (123 + 4)
EXPECT_DOUBLE_EQ(add->evaluate(), 127.000000);
EXPECT_EQ(add->stringify(), "(123.000000 + 4.000000)");
}
TEST(AddTest, Mult_Mock) {
Base* mock = new Mult_Mock(); // 3 * 2
Base* number = new Op(4);
Base* add = new Add(mock, number); // ((3 * 2) + 4)
EXPECT_DOUBLE_EQ(add->evaluate(), 10.000000);
EXPECT_EQ(add->stringify(), "((3.000000 * 2.000000) + 4.000000)");
}
TEST(AddTest, Div_Mock) {
Base* mock = new Div_Mock(); // 3 / 2
Base* number = new Op(4);
Base* add = new Add(mock, number); // ((3 / 2) + 4)
EXPECT_DOUBLE_EQ(add->evaluate(), 5.500000);
EXPECT_EQ(add->stringify(), "((3.000000 / 2.000000) + 4.000000)");
}
TEST(PowTest, Pow_Mock) {
Base* mock = new Pow_Mock(); // 3 ** 2
Base* number = new Op(4);
Base* add = new Add(mock, number); // ((3 ** 2) + 4)
EXPECT_DOUBLE_EQ(add->evaluate(), 13.000000);
EXPECT_EQ(add->stringify(), "((3.000000 ** 2.000000) + 4.000000)");
}
#endif // __ADD_TEST_H__