forked from stefano-1981/vacuum
-
Notifications
You must be signed in to change notification settings - Fork 0
/
geometry_test.cc
59 lines (48 loc) · 1017 Bytes
/
geometry_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
#include "geometry.h"
#include <cassert>
#include "tests.h"
TEST(Point_Equality) {
const Point p1{1, 2};
const Point p2{1, 2};
const Point p3{0, 0};
assert(p1 == p2);
assert(p2 == p1);
assert(!(p1 == p3));
assert(!(p2 == p3));
}
TEST(Point_Sum) {
const Point p1{-1, -2};
const Point p2{1, 3};
assert(Point({0, 1}) == (p1 + p2));
}
TEST(Matrix_InvalidInitialization) {
Matrix(-2, -3);
}
TEST(Matrix_ValidInitialization) {
Matrix m{10, 6};
for (int x = 0; x < 10; ++x) {
for (int y = 0; y < 6; ++y) {
assert(m.Get(x, y) == 0);
}
}
}
TEST(Matrix_GetAndSet) {
Matrix m{10, 6};
m.Set(0, 0, 1);
assert(m.Get(0, 0) == 1);
m.Set(9, 5, -1);
assert(m.Get(9, 5) == -1);
}
TEST(Matrix_CountNonZero) {
Matrix m(3, 2);
assert(m.CountNonZero() == 0);
for (int i = 0; i < 3; ++i) {
m.Set(1, 1, 2);
assert(m.CountNonZero() == 1);
}
m.Set(1, 1, 0);
assert(m.CountNonZero() == 0);
m.Set(1, 1, 1);
m.Set(1, 0, -2);
assert(m.CountNonZero() == 2);
}