-
Notifications
You must be signed in to change notification settings - Fork 23
/
Copy pathVectorTest.cpp
107 lines (87 loc) · 2 KB
/
VectorTest.cpp
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
#include <gtest/gtest.h>
#include <random>
#include "Shapes.h"
static Vector2<int> RandVec() {
static std::random_device rd;
static std::mt19937 gen(rd());
std::binomial_distribution<> d(100, 0.5);
return {d(gen), d(gen)};
}
TEST(Vector2, EmptyInitializerIsZero) {
Vector2<int> candidate{};
ASSERT_EQ(candidate.x, 0);
ASSERT_EQ(candidate.y, 0);
}
constexpr auto sample_size_k = 10;
TEST(Vector2, Add) {
for (auto i = 0; i < sample_size_k; ++i) {
auto a = RandVec();
auto b = RandVec();
auto c = a + b;
ASSERT_EQ(c.x, a.x + b.x);
ASSERT_EQ(c.y, a.y + b.y);
}
}
TEST(Vector2, Sub) {
for (auto i = 0; i < sample_size_k; ++i) {
auto a = RandVec();
auto b = RandVec();
auto c = a - b;
ASSERT_EQ(c.x, a.x - b.x);
ASSERT_EQ(c.y, a.y - b.y);
}
}
TEST(Vector2, Mul) {
for (auto i = 0; i < sample_size_k; ++i) {
auto a = RandVec();
auto b = RandVec();
auto c = a * b;
ASSERT_EQ(c.x, a.x * b.x);
ASSERT_EQ(c.y, a.y * b.y);
}
}
TEST(Vector2, Div) {
for (auto i = 0; i < sample_size_k; ++i) {
auto a = RandVec();
auto b = RandVec();
auto c = a / b;
ASSERT_EQ(c.x, a.x / b.x);
ASSERT_EQ(c.y, a.y / b.y);
}
}
TEST(Vector2, AddScalar) {
for (auto i = 0; i < sample_size_k; ++i) {
auto a = RandVec();
auto b = RandVec().x;
auto c = a + b;
ASSERT_EQ(c.x, a.x + b);
ASSERT_EQ(c.y, a.y + b);
}
}
TEST(Vector2, SubScalar) {
for (auto i = 0; i < sample_size_k; ++i) {
auto a = RandVec();
auto b = RandVec().x;
auto c = a - b;
ASSERT_EQ(c.x, a.x - b);
ASSERT_EQ(c.y, a.y - b);
}
}
TEST(Vector2, MulScalar) {
for (auto i = 0; i < sample_size_k; ++i) {
auto a = RandVec();
auto b = RandVec().x;
auto c = a * b;
ASSERT_EQ(c.x, a.x * b);
ASSERT_EQ(c.y, a.y * b);
}
}
TEST(Vector2, DivScalar) {
for (auto i = 0; i < sample_size_k; ++i) {
auto a = RandVec();
auto b = RandVec().x;
auto c = a / b;
ASSERT_EQ(c.x, a.x / b);
ASSERT_EQ(c.y, a.y / b);
}
}