-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcomplex_vector_lib_test.cc
108 lines (95 loc) · 2.73 KB
/
complex_vector_lib_test.cc
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
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
#include "complex_vector.hh"
#include "gtest/gtest.h"
#include <vector>
using namespace std;
using namespace complex;
namespace complex_vec {
namespace testing {
TEST(ComplexVectorLibTest, CopyAndSubscriptConstructor) {
Complex first(3.0, 4.0);
ComplexVector cv1(first);
ComplexVector cv2(first);
EXPECT_EQ(cv1[0], cv2[0]);
}
TEST(ComplexVectorLibTest, VectorConstructorTest) {
vector<Complex> vec;
Complex first(1.0, 2.0);
vec.push_back(first);
Complex second(3.0, 4.0);
vec.push_back(second);
ComplexVector cv(vec);
cout << cv[0] << endl;
cout << cv[1] << endl;
EXPECT_EQ(first, cv[0]);
EXPECT_EQ(second, cv[1]);
EXPECT_EQ(1, cv.ub());
cout << cv << endl;
}
TEST(ComplexVectorLibTest, ComplexConverterTest) {
Complex second[] = {Complex(1.0, 2.0), Complex(3.0, 4.0)};
ComplexVector cv(second, 2);
EXPECT_TRUE(Complex(1.0, 2.0) == cv[0]);
EXPECT_TRUE(Complex(3.0, 4.0) == cv[1]);
}
TEST(ComplexVectorLibTest, AdditionTest) {
Complex first(3.0, 4.0);
ComplexVector cv1(first);
cout << cv1 << endl;
Complex second(1.0, 2.0);
ComplexVector cv2(second);
cout << cv2 << endl;
ComplexVector cv3(cv1 + cv2);
cout << cv3 << endl;
EXPECT_EQ(cv3[0], cv1[0] + cv2[0]);
}
TEST(ComplexVectorLibTest, DotProductTest) {
Complex first[] = {Complex(3.0, 4.0), Complex(-1.0, -2.0)};
ComplexVector cv1(first, 2);
Complex second[] = {Complex(1.0, 2.0), Complex(3.0, 4.0)};
ComplexVector cv2(second, 2);
vector<double> v = cv1 * cv2;
EXPECT_EQ(2, static_cast<int>(v.size()));
EXPECT_EQ(11.0, v[0]);
EXPECT_EQ(-11.0, v[1]);
}
TEST(ComplexVectorLibTest, EqualityTest) {
Complex first[] = {Complex(3.0, 4.0), Complex(-1.0, -2.0)};
ComplexVector cv1(first, 2);
Complex second[] = {Complex(1.0, 2.0), Complex(3.0, 4.0)};
ComplexVector cv2(second, 2);
EXPECT_FALSE(cv1 == cv2);
ComplexVector cv3(second, 2);
EXPECT_TRUE(cv2 == cv3);
cout << cv2 << endl;
cout << cv3 << endl;
ComplexVector cv4;
EXPECT_FALSE(cv4 == cv3);
EXPECT_TRUE(cv4 != cv3);
}
TEST(ComplexVectorLibTest, EqualitySubscriptingTest) {
vector<Complex> vec;
Complex first(1.0, 2.0);
vec.push_back(first);
Complex second(3.0, 4.0);
vec.push_back(second);
ComplexVector cv(vec);
cout << cv[0] << endl;
cout << cv[1] << endl;
EXPECT_TRUE(first == cv[0]);
EXPECT_TRUE(second == cv[1]);
}
TEST(ComplexVectorLibTest, AssignmentTest) {
Complex first[] = {Complex(3.0, 4.0), Complex(-1.0, -2.0)};
ComplexVector cv1(first, 2);
cout << cv1 << endl;
Complex second[] = {Complex(1.0, 2.0), Complex(3.0, 4.0)};
ComplexVector cv2(second, 2);
cout << cv2 << endl;
EXPECT_FALSE(cv1 == cv2);
cv1 = cv2;
cout << cv1 << endl;
cout << cv2 << endl;
EXPECT_TRUE(cv1 == cv2);
}
} // namespace testing
} // namespace complex_vec