Skip to content

Commit 3f72cc6

Browse files
committed
Update shape tests
1 parent 855d304 commit 3f72cc6

File tree

1 file changed

+61
-94
lines changed

1 file changed

+61
-94
lines changed

test/irregular/shape_test.cpp

Lines changed: 61 additions & 94 deletions
Original file line numberDiff line numberDiff line change
@@ -5,91 +5,54 @@
55
using namespace packingsolver;
66
using namespace packingsolver::irregular;
77

8-
TEST(IrregularShape, CleanShapeRedundant)
8+
struct CleanShapeTestParams
99
{
10-
Shape shape = build_shape({{0, 0}, {0, 0}, {100, 0}, {100, 100}});
10+
Shape shape;
11+
Shape expected_shape;
12+
};
1113

12-
Shape cleaned_shape = clean_shape(shape);
13-
std::cout << cleaned_shape.to_string(0) << std::endl;
14-
15-
Shape expected_shape = build_shape({{0, 0}, {100, 0}, {100, 100}});
16-
EXPECT_EQ(expected_shape, cleaned_shape);
17-
}
18-
19-
TEST(IrregularShape, CleanShapeAligned)
20-
{
21-
Shape shape = build_shape({{50, 50}, {0, 0}, {100, 0}, {100, 100}});
22-
23-
Shape cleaned_shape = clean_shape(shape);
24-
25-
Shape expected_shape = build_shape({{0, 0}, {100, 0}, {100, 100}});
26-
EXPECT_EQ(expected_shape, cleaned_shape);
27-
}
28-
29-
TEST(IrregularShape, CleanShapeAligned2)
30-
{
31-
Shape shape = build_shape({{0, 0}, {100, 0}, {100, 100}, {50, 50}});
32-
33-
Shape cleaned_shape = clean_shape(shape);
34-
35-
Shape expected_shape = build_shape({{0, 0}, {100, 0}, {100, 100}});
36-
EXPECT_EQ(expected_shape, cleaned_shape);
37-
}
14+
class IrregularCleanShapeTest: public testing::TestWithParam<CleanShapeTestParams> { };
3815

39-
TEST(IrregularShape, Borders0)
16+
TEST_P(IrregularCleanShapeTest, CleanShape)
4017
{
41-
Shape shape = build_shape({{0, 0}, {1, 0}, {1, 1}, {0, 1}});
42-
std::vector<Shape> expected_borders = {};
43-
44-
std::vector<Shape> shape_borders = borders(shape);
45-
for (const Shape& border: shape_borders)
46-
std::cout << border.to_string(0) << std::endl;
47-
48-
EXPECT_EQ(shape_borders.size(), expected_borders.size());
49-
for (const Shape& expected_border: expected_borders) {
50-
EXPECT_NE(std::find(
51-
shape_borders.begin(),
52-
shape_borders.end(),
53-
expected_border),
54-
shape_borders.end());
55-
}
18+
CleanShapeTestParams test_params = GetParam();
19+
Shape cleaned_shape = clean_shape(test_params.shape);
20+
std::cout << cleaned_shape.to_string(0) << std::endl;
21+
EXPECT_EQ(test_params.expected_shape, cleaned_shape);
5622
}
5723

58-
TEST(IrregularShape, Borders1)
24+
INSTANTIATE_TEST_SUITE_P(
25+
Irregular,
26+
IrregularCleanShapeTest,
27+
testing::ValuesIn(std::vector<CleanShapeTestParams>{
28+
{
29+
build_shape({{0, 0}, {0, 0}, {100, 0}, {100, 100}}),
30+
build_shape({{0, 0}, {100, 0}, {100, 100}})
31+
}, {
32+
build_shape({{50, 50}, {0, 0}, {100, 0}, {100, 100}}),
33+
build_shape({{0, 0}, {100, 0}, {100, 100}})
34+
}, {
35+
build_shape({{0, 0}, {100, 0}, {100, 100}, {50, 50}}),
36+
build_shape({{0, 0}, {100, 0}, {100, 100}})
37+
}}));
38+
39+
40+
struct ExtractBordersTestParams
5941
{
60-
Shape shape = build_shape({{2, 0}, {3, 1}, {0, 1}});
61-
std::vector<Shape> expected_borders = {
62-
build_shape({{3, 0}, {3, 1}, {2, 0}}),
63-
build_shape({{0, 0}, {2, 0}, {0, 1}}),
64-
};
42+
Shape shape;
43+
std::vector<Shape> expected_borders;
44+
};
6545

66-
std::vector<Shape> shape_borders = borders(shape);
67-
for (const Shape& border: shape_borders)
68-
std::cout << border.to_string(0) << std::endl;
69-
70-
EXPECT_EQ(shape_borders.size(), expected_borders.size());
71-
for (const Shape& expected_border: expected_borders) {
72-
EXPECT_NE(std::find(
73-
shape_borders.begin(),
74-
shape_borders.end(),
75-
expected_border),
76-
shape_borders.end());
77-
}
78-
}
46+
class IrregularExtractBordersTest: public testing::TestWithParam<ExtractBordersTestParams> { };
7947

80-
TEST(IrregularShape, Borders2)
48+
TEST_P(IrregularExtractBordersTest, ExtractBorders)
8149
{
82-
Shape shape = build_shape({{0, 0}, {3, 1}, {0, 1}});
83-
std::vector<Shape> expected_borders = {
84-
build_shape({{3, 0}, {3, 1}, {0, 0}}),
85-
};
86-
87-
std::vector<Shape> shape_borders = borders(shape);
50+
ExtractBordersTestParams test_params = GetParam();
51+
std::vector<Shape> shape_borders = borders(test_params.shape);
8852
for (const Shape& border: shape_borders)
8953
std::cout << border.to_string(0) << std::endl;
90-
91-
EXPECT_EQ(shape_borders.size(), expected_borders.size());
92-
for (const Shape& expected_border: expected_borders) {
54+
EXPECT_EQ(shape_borders.size(), test_params.expected_borders.size());
55+
for (const Shape& expected_border: test_params.expected_borders) {
9356
EXPECT_NE(std::find(
9457
shape_borders.begin(),
9558
shape_borders.end(),
@@ -98,24 +61,28 @@ TEST(IrregularShape, Borders2)
9861
}
9962
}
10063

101-
TEST(IrregularShape, Borders3)
102-
{
103-
Shape shape = build_shape({{0, 0}, {50, 0}, {30, 30}});
104-
std::vector<Shape> expected_borders = {
105-
build_shape({{0, 0}, {30, 30}, {0, 30}}),
106-
build_shape({{30, 30}, {50, 0}, {50, 30}}),
107-
};
108-
109-
std::vector<Shape> shape_borders = borders(shape);
110-
for (const Shape& border: shape_borders)
111-
std::cout << border.to_string(0) << std::endl;
112-
113-
EXPECT_EQ(shape_borders.size(), expected_borders.size());
114-
for (const Shape& expected_border: expected_borders) {
115-
EXPECT_NE(std::find(
116-
shape_borders.begin(),
117-
shape_borders.end(),
118-
expected_border),
119-
shape_borders.end());
120-
}
121-
}
64+
INSTANTIATE_TEST_SUITE_P(
65+
Irregular,
66+
IrregularExtractBordersTest,
67+
testing::ValuesIn(std::vector<ExtractBordersTestParams>{
68+
{
69+
build_shape({{0, 0}, {1, 0}, {1, 1}, {0, 1}}),
70+
{},
71+
}, {
72+
build_shape({{2, 0}, {3, 1}, {0, 1}}),
73+
{
74+
build_shape({{3, 0}, {3, 1}, {2, 0}}),
75+
build_shape({{0, 0}, {2, 0}, {0, 1}}),
76+
}
77+
}, {
78+
build_shape({{0, 0}, {3, 1}, {0, 1}}),
79+
{
80+
build_shape({{3, 0}, {3, 1}, {0, 0}}),
81+
}
82+
}, {
83+
build_shape({{0, 0}, {50, 0}, {30, 30}}),
84+
{
85+
build_shape({{0, 0}, {30, 30}, {0, 30}}),
86+
build_shape({{30, 30}, {50, 0}, {50, 30}}),
87+
}
88+
}}));

0 commit comments

Comments
 (0)