forked from pcb2gcode/pcb2gcode
-
Notifications
You must be signed in to change notification settings - Fork 0
/
available_drills_tests.cpp
57 lines (48 loc) · 2.48 KB
/
available_drills_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
#define BOOST_TEST_MODULE availabile_drills tests
#include <boost/test/included/unit_test.hpp>
#include "units.hpp"
#include "available_drills.hpp"
namespace po = boost::program_options;
using namespace std;
BOOST_AUTO_TEST_SUITE(available_drills_tests);
AvailableDrills string_to_available_drills(const string& text) {
stringstream ss(text);
AvailableDrills available_drills;
ss >> available_drills;;
return available_drills;
}
string available_drills_to_string(const AvailableDrills& available_drills) {
stringstream ss;
ss << available_drills;
return ss.str();
}
BOOST_AUTO_TEST_CASE(parse_available_drills) {
BOOST_CHECK_EQUAL(string_to_available_drills("4"), AvailableDrills({parse_unit<Length>("4")}));
BOOST_CHECK_EQUAL(string_to_available_drills("25.4mm"), AvailableDrills({parse_unit<Length>("1inch")}));
BOOST_CHECK_EQUAL(available_drills_to_string(AvailableDrills({parse_unit<Length>("1inch")})), "0.0254 m");
BOOST_CHECK_EQUAL(available_drills_to_string(AvailableDrills({parse_unit<Length>("1")})), "1");
BOOST_CHECK_EQUAL(available_drills_to_string(AvailableDrills({parse_unit<Length>("1inch"),
parse_unit<Length>("9")})),
"0.0254 m, 9");
BOOST_CHECK_EQUAL(string_to_available_drills("1mm:0.1mm"),
AvailableDrills({AvailableDrill(parse_unit<Length>("1mm"),
parse_unit<Length>("-0.1mm"),
parse_unit<Length>("0.1mm"))}));
BOOST_CHECK_EQUAL(string_to_available_drills("1mm:+0.1mm:-0.2mm"),
AvailableDrills({AvailableDrill(parse_unit<Length>("1mm"),
parse_unit<Length>("-0.2mm"),
parse_unit<Length>("+0.1mm"))}));
BOOST_CHECK_EQUAL(
available_drills_to_string(
string_to_available_drills("1inch:0.1inches")),
"0.0254 m:-0.00254 m:+0.00254 m");
BOOST_CHECK_EQUAL(
available_drills_to_string(
string_to_available_drills("1inch,0.1inches")),
"0.0254 m, 0.00254 m");
BOOST_CHECK_THROW(string_to_available_drills(""), po::validation_error);
BOOST_CHECK_THROW(string_to_available_drills("50.8seconds"), po::validation_error);
BOOST_CHECK_THROW(string_to_available_drills("1mm:0.1mm:0.2mm"), po::validation_error);
BOOST_CHECK_THROW(string_to_available_drills("1:0.1:0.2:0.3"), po::validation_error);
}
BOOST_AUTO_TEST_SUITE_END()