forked from pcb2gcode/pcb2gcode
-
Notifications
You must be signed in to change notification settings - Fork 0
/
autoleveller_tests.cpp
150 lines (138 loc) · 3.77 KB
/
autoleveller_tests.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
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
#define BOOST_TEST_MODULE autoleveller tests
#include <boost/test/included/unit_test.hpp>
#include "autoleveller.hpp"
using namespace std;
namespace std {
static inline std::ostream& operator<<(std::ostream& out, const icoordpair& point) {
out << "{" << point.first << ", " << point.second << "}";
return out;
}
static inline std::ostream& operator<<(std::ostream& out, const icoords& points) {
out << "{";
for (auto p = points.cbegin(); p != points.cend(); p++) {
out << *p;
if (p + 1 != points.cend()) {
out << ", ";
}
}
out << "}";
return out;
}
}
BOOST_AUTO_TEST_SUITE(autoleveller_tests);
BOOST_AUTO_TEST_CASE(ten_by_ten) {
const auto actual = partition_segment(icoordpair(0,0),
icoordpair(100,100),
icoordpair(0,0),
icoordpair(10, 10));
const icoords expected {
{0, 0},
{10, 10},
{20, 20},
{30, 30},
{40, 40},
{50, 50},
{60, 60},
{70, 70},
{80, 80},
{90, 90},
{100, 100},
};
BOOST_CHECK_EQUAL(actual, expected);
}
BOOST_AUTO_TEST_CASE(horizontal_aligned) {
const auto actual = partition_segment(icoordpair(0,0),
icoordpair(0,100),
icoordpair(0,0),
icoordpair(10, 10));
const icoords expected {
{0, 0},
{0, 10},
{0, 20},
{0, 30},
{0, 40},
{0, 50},
{0, 60},
{0, 70},
{0, 80},
{0, 90},
{0, 100},
};
BOOST_CHECK_EQUAL(actual, expected);
}
BOOST_AUTO_TEST_CASE(horizontal_unaligned) {
const auto actual = partition_segment(icoordpair(0.1,0.1),
icoordpair(0.1,19.9),
icoordpair(0,0),
icoordpair(10, 10));
const icoords expected {
{0.1, 0.1},
{0.1, 10},
{0.1, 19.9},
};
BOOST_CHECK_EQUAL(actual, expected);
}
BOOST_AUTO_TEST_CASE(ten_by_ten_offset) {
const auto actual = partition_segment(icoordpair(0,0),
icoordpair(100,100),
icoordpair(1,1),
icoordpair(10, 10));
const icoords expected {
{0, 0},
{1, 1},
{11, 11},
{21, 21},
{31, 31},
{41, 41},
{51, 51},
{61, 61},
{71, 71},
{81, 81},
{91, 91},
{100, 100},
};
BOOST_CHECK_EQUAL(actual, expected);
}
BOOST_AUTO_TEST_CASE(source_equals_dest) {
const auto actual = partition_segment(icoordpair(0,0),
icoordpair(0,0),
icoordpair(1,2),
icoordpair(3, 4));
const icoords expected {
{0, 0}
};
BOOST_CHECK_EQUAL(actual, expected);
}
BOOST_AUTO_TEST_CASE(skewed) {
const auto actual = partition_segment(icoordpair(5,5),
icoordpair(99,12),
icoordpair(0,0),
icoordpair(7, 5));
const icoords expected {
{5, 5},
{7, 5.14894},
{14, 5.67021},
{21, 6.19149},
{28, 6.71277},
{35, 7.23404},
{42, 7.75532},
{49, 8.2766},
{56, 8.79787},
{63, 9.31915},
{70, 9.84043},
{72.1429, 10},
{77, 10.3617},
{84, 10.883},
{91, 11.4043},
{98, 11.9255},
{99, 12}
};
BOOST_CHECK_EQUAL(actual.size(), expected.size());
for (size_t i = 0; i < actual.size(); i++) {
BOOST_TEST_CONTEXT("actual[" << i << "] == expected[" << i << "]") {
BOOST_CHECK_CLOSE(actual[i].first, expected[i].first, 0.001);
BOOST_CHECK_CLOSE(actual[i].second, expected[i].second, 0.001);
}
}
}
BOOST_AUTO_TEST_SUITE_END()