Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
U
unionized-triangles-2
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Brandon Lai-Cheong
unionized-triangles-2
Commits
526671eb
Commit
526671eb
authored
3 months ago
by
Brandon Lai-Cheong
Browse files
Options
Downloads
Patches
Plain Diff
refactored union tests
parent
607ece8f
No related branches found
No related tags found
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
tests/edge_union_cases.cpp
+3
-29
3 additions, 29 deletions
tests/edge_union_cases.cpp
tests/union_tests.cpp
+39
-34
39 additions, 34 deletions
tests/union_tests.cpp
tests/union_tests.h
+15
-0
15 additions, 0 deletions
tests/union_tests.h
with
57 additions
and
63 deletions
tests/edge_union_cases.cpp
+
3
−
29
View file @
526671eb
...
...
@@ -2,38 +2,11 @@
#include
<union.h>
#include
<triangle.h>
#include
<orientation.h>
#include
"union_tests.h"
struct
UnionParams
{
Triangle
t1
;
Triangle
t2
;
std
::
vector
<
Triangle
>
expected
;
};
std
::
ostream
&
operator
<<
(
std
::
ostream
&
os
,
const
UnionParams
&
u
)
{
os
<<
u
.
t1
<<
"|"
<<
u
.
t2
;
return
os
;
}
class
InstantiateUnionEdgeTests
:
public
testing
::
TestWithParam
<
UnionParams
>
{
};
TEST_P
(
InstantiateUnionEdgeTests
,
UnionTest
)
{
const
Triangle
&
t1
=
GetParam
().
t1
;
const
Triangle
&
t2
=
GetParam
().
t2
;
auto
expected
=
GetParam
().
expected
;
ASSERT_NE
(
orientation
(
t1
),
Clockwise
);
ASSERT_NE
(
orientation
(
t2
),
Clockwise
);
auto
result
=
unionize
(
t1
,
t2
);
EXPECT_EQ
(
result
,
expected
);
}
INSTANTIATE_TEST_SUITE_P
(
EdgeUnionTests
,
InstantiateUnion
Edge
Tests
,
testing
::
Values
(
INSTANTIATE_TEST_SUITE_P
(
EdgeUnionTests
,
InstantiateUnionTests
,
testing
::
Values
(
// Point on top of triangle
UnionParams
{
Triangle
({
0
,
0
,
4
},
{
5
,
0
,
4
},
{
2
,
3
,
4
},
1
),
Triangle
({
1
,
1
,
0
},
{
1
,
1
,
0
},
{
1
,
1
,
0
},
2
),
{
Triangle
({
0
,
0
,
4
},
{
5
,
0
,
4
},
{
2
,
3
,
4
},
1
),
Triangle
({
1
,
1
,
0
},
{
1
,
1
,
0
},
{
1
,
1
,
0
},
2
)}},
// Point on edge of triangle
...
...
@@ -82,3 +55,4 @@ TEST(UnionEdgeTests, TriangleOnSide)
EXPECT_EQ
(
results
,
expected
);
}
This diff is collapsed.
Click to expand it.
tests/union_tests.cpp
+
39
−
34
View file @
526671eb
...
...
@@ -3,6 +3,12 @@
#include
<triangle.h>
#include
<orientation.h>
#include
<shift_triangle.h>
#include
"union_tests.h"
std
::
ostream
&
operator
<<
(
std
::
ostream
&
os
,
const
UnionParams
&
u
)
{
os
<<
u
.
t1
<<
"|"
<<
u
.
t2
;
return
os
;
}
TEST
(
UnionTrivialTests
,
NotTouching
)
{
...
...
@@ -53,7 +59,7 @@ TEST(UnionTests, SharesPointTest)
results
=
unionize
(
bottom
,
top
);
std
::
vector
<
Triangle
>
expected_results_2
{
Triangle
({
0
,
5
},
{
3
,
2
},
{
5
,
3
},
1
),
Triangle
({
0
,
5
,
10
},
{
3
,
2
,
10
},
{
5
,
3
,
10
},
1
),
Triangle
({
0.1
,
7
,
5
},
{
5
,
3
,
5
},
{
3.2
,
9
,
5
},
2
)
};
...
...
@@ -90,60 +96,59 @@ TEST(UnionTests, FoldTriangleTest)
EXPECT_EQ
(
results
,
expected_results_2
);
}
/*
TEST(UnionTests, IceCreamTest)
{
Triangle bottom = Triangle({0, 5}, {3, 2}, {5, 3}, 2, 1);
Triangle top = Triangle({-1, 5}, {2, 4}, {5, 7}, 1, 2);
auto results = unionize(bottom, top);
std::vector<Triangle> expected_results_1;
EXPECT_EQ(results, expected_results_1);
top.depth = 3;
results = unionize(bottom, top);
std::vector<Triangle> expected_results_2;
EXPECT_EQ(results, expected_results_2);
}*/
TEST
(
UnionTests
,
StarTest
)
{
Triangle
bot
to
m
=
Triangle
({
0
,
3
},
{
5
,
3
},
{
2.5
,
6
},
1
);
Triangle
top
=
Triangle
({
0
,
5
,
1
},
{
2
,
0
,
1
},
{
5
,
5
,
1
},
2
);
Triangle
to
p
=
Triangle
({
0
,
3
,
0
},
{
5
,
3
,
0
},
{
2.5
,
6
,
0
},
1
);
Triangle
bot
=
Triangle
({
0
,
5
,
1
},
{
2
,
0
,
1
},
{
5
,
5
,
1
},
2
);
ASSERT_EQ
(
orientation
(
bottom
.
points
[
0
],
bottom
.
points
[
1
],
bottom
.
points
[
2
]),
Counterclockwise
);
ASSERT_EQ
(
orientation
(
top
.
points
[
0
],
top
.
points
[
1
],
top
.
points
[
2
]),
Counterclockwise
);
ASSERT_EQ
(
orientation
(
bot
.
points
[
0
],
bot
.
points
[
1
],
bot
.
points
[
2
]),
Counterclockwise
);
auto
results
=
unionize
(
bot
to
m
,
top
);
auto
results
=
unionize
(
to
p
,
bot
);
std
::
vector
<
Triangle
>
expected_results_1
=
{
Triangle
({
2
,
0
},
{
3.8
,
3
},
{
0.8
,
3
},
2
),
Triangle
({
5
,
5
},
{
3.33333
,
5
},
{
4.30233
,
3.83721
},
2
),
Triangle
({
0
,
5
},
{
0.540541
,
3.64865
},
{
1.66667
,
5
},
2
),
Triangle
({
2
,
0
,
1
},
{
3.8
,
3
,
1
},
{
0.8
,
3
,
1
},
2
),
Triangle
({
5
,
5
,
1
},
{
3.33333
,
5
,
1
},
{
4.30233
,
3.83721
,
1
},
2
),
Triangle
({
0
,
5
,
1
},
{
0.540541
,
3.64865
,
1
},
{
1.66667
,
5
,
1
},
2
),
Triangle
({
0
,
3
},
{
5
,
3
},
{
2.5
,
6
},
1
)
};
EXPECT_EQ
(
results
,
expected_results_1
);
shiftZ
(
bot
to
m
,
3
);
shiftZ
(
to
p
,
3
);
results
=
unionize
(
bot
to
m
,
top
);
results
=
unionize
(
to
p
,
bot
);
std
::
vector
<
Triangle
>
expected_results_2
=
{
Triangle
({
0
,
3
},
{
0.8
,
3
},
{
0.540541
,
3.64865
},
1
),
Triangle
({
5
,
3
},
{
4.30233
,
3.83721
},
{
3.8
,
3
},
1
),
Triangle
({
2.5
,
6
},
{
1.66667
,
5
},
{
3.33333
,
5
},
1
),
Triangle
({
0
,
5
},
{
2
,
0
},
{
5
,
5
},
2
)
Triangle
({
0
,
3
,
3
},
{
0.8
,
3
,
3
},
{
0.540541
,
3.64865
,
3
},
1
),
Triangle
({
5
,
3
,
3
},
{
4.30233
,
3.83721
,
3
},
{
3.8
,
3
,
3
},
1
),
Triangle
({
2.5
,
6
,
3
},
{
1.66667
,
5
,
3
},
{
3.33333
,
5
,
3
},
1
),
Triangle
({
0
,
5
,
1
},
{
2
,
0
,
1
},
{
5
,
5
,
1
},
2
)
};
EXPECT_EQ
(
results
,
expected_results_2
);
}
TEST
(
UnionTests
,
DepthTest
)
{
TEST_P
(
InstantiateUnionTests
,
UnionTest
)
{
const
Triangle
&
t1
=
GetParam
().
t1
;
const
Triangle
&
t2
=
GetParam
().
t2
;
auto
expected
=
GetParam
().
expected
;
ASSERT_NE
(
orientation
(
t1
),
Clockwise
);
ASSERT_NE
(
orientation
(
t2
),
Clockwise
);
auto
result
=
unionize
(
t1
,
t2
);
EXPECT_EQ
(
result
,
expected
);
}
INSTANTIATE_TEST_SUITE_P
(
ParameterizedUnionTests
,
InstantiateUnionTests
,
testing
::
Values
(
UnionParams
{
Triangle
({
0
,
0
,
0
},
{
5
,
0
,
0
},
{
2
,
3
,
0
},
1
),
Triangle
(
Point
{
3
,
1
,
10
},
Point
{
6
,
1
,
2
},
Point
{
4
,
3
,
1
},
2
),
{
Triangle
({
6
,
1
,
2
},
{
4
,
3
,
1
},
{
3.333333
,
1.66666
,
7.23542
},
2
),
Triangle
({
6
,
1
,
2
},
{
3.33333
,
1.66667
,
7.23542
},
{
4
,
1
,
7.3680
},
2
),
Triangle
({
0
,
0
},
{
5
,
0
},
{
2
,
3
},
1
)}}
));
\ No newline at end of file
This diff is collapsed.
Click to expand it.
tests/union_tests.h
0 → 100644
+
15
−
0
View file @
526671eb
#pragma once
#include
<triangle.h>
struct
UnionParams
{
Triangle
t1
;
Triangle
t2
;
std
::
vector
<
Triangle
>
expected
;
};
class
InstantiateUnionTests
:
public
testing
::
TestWithParam
<
UnionParams
>
{};
std
::
ostream
&
operator
<<
(
std
::
ostream
&
os
,
const
UnionParams
&
u
);
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment