Skip to content

Commit 144f347

Browse files
DebbieSanvaeng
andauthored
test: sync triangle tests (#787)
[no important files changed] --------- Co-authored-by: vaeng <[email protected]>
1 parent 8c494a4 commit 144f347

File tree

2 files changed

+130
-67
lines changed

2 files changed

+130
-67
lines changed
Lines changed: 45 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,60 +1,83 @@
1-
# This is an auto-generated file. Regular comments will be removed when this
2-
# file is regenerated. Regenerating will not touch any manually added keys,
3-
# so comments can be added in a "comment" key.
1+
# This is an auto-generated file.
2+
#
3+
# Regenerating this file via `configlet sync` will:
4+
# - Recreate every `description` key/value pair
5+
# - Recreate every `reimplements` key/value pair, where they exist in problem-specifications
6+
# - Remove any `include = true` key/value pair (an omitted `include` key implies inclusion)
7+
# - Preserve any other key/value pair
8+
#
9+
# As user-added comments (using the # character) will be removed when this file
10+
# is regenerated, comments can be added via a `comment` key.
411

512
[8b2c43ac-7257-43f9-b552-7631a91988af]
6-
description = "all sides are equal"
13+
description = "equilateral triangle -> all sides are equal"
714

815
[33eb6f87-0498-4ccf-9573-7f8c3ce92b7b]
9-
description = "any side is unequal"
16+
description = "equilateral triangle -> any side is unequal"
1017

1118
[c6585b7d-a8c0-4ad8-8a34-e21d36f7ad87]
12-
description = "no sides are equal"
19+
description = "equilateral triangle -> no sides are equal"
1320

1421
[16e8ceb0-eadb-46d1-b892-c50327479251]
15-
description = "all zero sides is not a triangle"
22+
description = "equilateral triangle -> all zero sides is not a triangle"
1623

1724
[3022f537-b8e5-4cc1-8f12-fd775827a00c]
18-
description = "sides may be floats"
25+
description = "equilateral triangle -> sides may be floats"
1926

2027
[cbc612dc-d75a-4c1c-87fc-e2d5edd70b71]
21-
description = "last two sides are equal"
28+
description = "isosceles triangle -> last two sides are equal"
2229

2330
[e388ce93-f25e-4daf-b977-4b7ede992217]
24-
description = "first two sides are equal"
31+
description = "isosceles triangle -> first two sides are equal"
2532

2633
[d2080b79-4523-4c3f-9d42-2da6e81ab30f]
27-
description = "first and last sides are equal"
34+
description = "isosceles triangle -> first and last sides are equal"
2835

2936
[8d71e185-2bd7-4841-b7e1-71689a5491d8]
30-
description = "equilateral triangles are also isosceles"
37+
description = "isosceles triangle -> equilateral triangles are also isosceles"
38+
include = false
39+
comment = "the chosen implementation does not allow for this equivalence"
3140

3241
[840ed5f8-366f-43c5-ac69-8f05e6f10bbb]
33-
description = "no sides are equal"
42+
description = "isosceles triangle -> no sides are equal"
3443

3544
[2eba0cfb-6c65-4c40-8146-30b608905eae]
36-
description = "first triangle inequality violation"
45+
description = "isosceles triangle -> first triangle inequality violation"
3746

3847
[278469cb-ac6b-41f0-81d4-66d9b828f8ac]
39-
description = "second triangle inequality violation"
48+
description = "isosceles triangle -> second triangle inequality violation"
4049

4150
[90efb0c7-72bb-4514-b320-3a3892e278ff]
42-
description = "third triangle inequality violation"
51+
description = "isosceles triangle -> third triangle inequality violation"
4352

4453
[adb4ee20-532f-43dc-8d31-e9271b7ef2bc]
45-
description = "sides may be floats"
54+
description = "isosceles triangle -> sides may be floats"
4655

4756
[e8b5f09c-ec2e-47c1-abec-f35095733afb]
48-
description = "no sides are equal"
57+
description = "scalene triangle -> no sides are equal"
4958

5059
[2510001f-b44d-4d18-9872-2303e7977dc1]
51-
description = "all sides are equal"
60+
description = "scalene triangle -> all sides are equal"
61+
include = false
62+
comment = "the chosen implementation does not allow for this equivalence"
5263

5364
[c6e15a92-90d9-4fb3-90a2-eef64f8d3e1e]
54-
description = "two sides are equal"
65+
description = "scalene triangle -> first and second sides are equal"
66+
include = false
67+
comment = "the chosen implementation does not allow for this equivalence"
68+
69+
[3da23a91-a166-419a-9abf-baf4868fd985]
70+
description = "scalene triangle -> first and third sides are equal"
71+
include = false
72+
comment = "the chosen implementation does not allow for this equivalence"
73+
74+
[b6a75d98-1fef-4c42-8e9a-9db854ba0a4d]
75+
description = "scalene triangle -> second and third sides are equal"
76+
include = false
77+
comment = "the chosen implementation does not allow for this equivalence"
5578

5679
[70ad5154-0033-48b7-af2c-b8d739cd9fdc]
57-
description = "may not violate triangle inequality"
80+
description = "scalene triangle -> may not violate triangle inequality"
5881

5982
[26d9d59d-f8f1-40d3-ad58-ae4d54123d7d]
60-
description = "sides may be floats"
83+
description = "scalene triangle -> sides may be floats"

exercises/practice/triangle/triangle_test.cpp

Lines changed: 85 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -6,85 +6,125 @@
66
#endif
77
#include <stdexcept>
88

9+
/*
10+
Problem spec commentary:
11+
12+
Pursuant to discussion in #202, we have decided NOT to test triangles
13+
where all side lengths are positive but a + b = c. e.g:
14+
(2, 4, 2, Isosceles), (1, 3, 4, Scalene).
15+
It's true that the triangle inequality admits such triangles.These
16+
triangles have zero area, however.
17+
They're degenerate triangles with all three vertices collinear.
18+
(In contrast, we will test (0, 0, 0, Illegal), as it is a point)
19+
The tests assert properties of the triangle are true or false.
20+
See: https://github.com/exercism/problem-specifications/issues/379 for
21+
disscussion of this approach How you handle invalid triangles is up to you.
22+
These tests suggest a triangle is returned, but all of its properties are
23+
false. But you could also have the creation of an invalid triangle return an
24+
error or exception. Choose what is idiomatic for your language."
25+
26+
The CPP track has chosen to throw a domain error for invalid triangles.
27+
28+
Tests, that check if an equilateral is also scalene (etc.) do not work with
29+
the chosen implementation, they are therefore not implemented for this track.
30+
31+
*/
32+
933
// improves error messages with triangle flavor enum text instead of integers:
10-
CATCH_REGISTER_ENUM(triangle::flavor,
11-
triangle::flavor::equilateral,
12-
triangle::flavor::isosceles,
13-
triangle::flavor::scalene)
34+
CATCH_REGISTER_ENUM(triangle::flavor, triangle::flavor::equilateral,
35+
triangle::flavor::isosceles, triangle::flavor::scalene)
1436

15-
TEST_CASE("equilateral_triangles_have_equal_sides")
16-
{
37+
TEST_CASE("equilateral triangle -> all sides are equal",
38+
"[8b2c43ac-7257-43f9-b552-7631a91988af]") {
1739
REQUIRE(triangle::flavor::equilateral == triangle::kind(2, 2, 2));
1840
}
1941

2042
#if defined(EXERCISM_RUN_ALL_TESTS)
21-
TEST_CASE("larger_equilateral_triangles_also_have_equal_sides")
22-
{
23-
REQUIRE(triangle::flavor::equilateral == triangle::kind(10, 10, 10));
43+
44+
TEST_CASE("equilateral triangle -> any side is unequal",
45+
"[33eb6f87-0498-4ccf-9573-7f8c3ce92b7b]") {
46+
REQUIRE_FALSE(triangle::flavor::equilateral == triangle::kind(2, 3, 2));
47+
}
48+
49+
TEST_CASE("equilateral triangle -> no sides are equal",
50+
"[c6585b7d-a8c0-4ad8-8a34-e21d36f7ad87]") {
51+
REQUIRE_FALSE(triangle::flavor::equilateral == triangle::kind(5, 4, 6));
52+
}
53+
54+
TEST_CASE("equilateral triangle -> sides may be floats",
55+
"[3022f537-b8e5-4cc1-8f12-fd775827a00c]") {
56+
REQUIRE(triangle::flavor::equilateral == triangle::kind(0.5, 0.5, 0.5));
2457
}
2558

26-
TEST_CASE("isosceles_triangles_have_last_two_sides_equal")
27-
{
59+
TEST_CASE("isosceles triangle -> last two sides are equal",
60+
"[cbc612dc-d75a-4c1c-87fc-e2d5edd70b71]") {
2861
REQUIRE(triangle::flavor::isosceles == triangle::kind(3, 4, 4));
2962
}
3063

31-
TEST_CASE("isosceles_triangles_have_first_and_last_sides_equal")
32-
{
64+
TEST_CASE("isosceles triangle -> first two sides are equal",
65+
"[e388ce93-f25e-4daf-b977-4b7ede992217]") {
66+
REQUIRE(triangle::flavor::isosceles == triangle::kind(4, 4, 3));
67+
}
68+
69+
TEST_CASE("isosceles triangle -> first and last sides are equal",
70+
"[d2080b79-4523-4c3f-9d42-2da6e81ab30f]") {
3371
REQUIRE(triangle::flavor::isosceles == triangle::kind(4, 3, 4));
3472
}
3573

36-
TEST_CASE("isosceles_triangles_have_first_two_sides_equal")
37-
{
38-
REQUIRE(triangle::flavor::isosceles == triangle::kind(4, 4, 3));
74+
TEST_CASE("isosceles triangle -> no sides are equal",
75+
"[840ed5f8-366f-43c5-ac69-8f05e6f10bbb]") {
76+
REQUIRE_FALSE(triangle::flavor::isosceles == triangle::kind(2, 3, 4));
3977
}
4078

41-
TEST_CASE("isosceles_triangles_have_in_fact_exactly_two_sides_equal")
42-
{
43-
REQUIRE(triangle::flavor::isosceles == triangle::kind(10, 10, 2));
79+
TEST_CASE("isosceles triangle -> first triangle inequality violation",
80+
"[2eba0cfb-6c65-4c40-8146-30b608905eae]") {
81+
REQUIRE_THROWS_AS(triangle::kind(1, 1, 3), std::domain_error);
4482
}
4583

46-
TEST_CASE("scalene_triangles_have_no_equal_sides")
47-
{
48-
REQUIRE(triangle::flavor::scalene == triangle::kind(3, 4, 5));
84+
TEST_CASE("isosceles triangle -> second triangle inequality violation",
85+
"[278469cb-ac6b-41f0-81d4-66d9b828f8ac]") {
86+
REQUIRE_THROWS_AS(triangle::kind(1, 3, 1), std::domain_error);
4987
}
5088

51-
TEST_CASE("scalene_triangles_have_no_equal_sides_at_a_larger_scale_too")
52-
{
53-
REQUIRE(triangle::flavor::scalene == triangle::kind(10, 11, 12));
89+
TEST_CASE("isosceles triangle -> third triangle inequality violation",
90+
"[90efb0c7-72bb-4514-b320-3a3892e278ff]") {
91+
REQUIRE_THROWS_AS(triangle::kind(3, 1, 1), std::domain_error);
5492
}
5593

56-
TEST_CASE("scalene_triangles_have_no_equal_sides_in_descending_order_either")
57-
{
58-
REQUIRE(triangle::flavor::scalene == triangle::kind(5, 4, 2));
94+
TEST_CASE("isosceles triangle -> sides may be floats",
95+
"[adb4ee20-532f-43dc-8d31-e9271b7ef2bc]") {
96+
REQUIRE(triangle::flavor::isosceles == triangle::kind(0.5, 0.4, 0.5));
5997
}
6098

61-
TEST_CASE("very_small_triangles_are_legal")
62-
{
63-
REQUIRE(triangle::flavor::scalene == triangle::kind(0.4, 0.6, 0.3));
99+
TEST_CASE("scalene triangle -> no sides are equal",
100+
"[e8b5f09c-ec2e-47c1-abec-f35095733afb]") {
101+
REQUIRE(triangle::flavor::scalene == triangle::kind(5, 4, 6));
64102
}
65103

66-
TEST_CASE("triangles_with_no_size_are_illegal")
67-
{
68-
REQUIRE_THROWS_AS(triangle::kind(0, 0, 0), std::domain_error);
104+
TEST_CASE("scalene triangle -> may not violate triangle inequality",
105+
"[70ad5154-0033-48b7-af2c-b8d739cd9fdc]") {
106+
REQUIRE_THROWS_AS(triangle::kind(7, 3, 2), std::domain_error);
69107
}
70108

71-
TEST_CASE("triangles_with_negative_sides_are_illegal")
72-
{
73-
REQUIRE_THROWS_AS(triangle::kind(3, 4, -5), std::domain_error);
109+
TEST_CASE("scalene triangle -> sides may be floats",
110+
"[26d9d59d-f8f1-40d3-ad58-ae4d54123d7d]") {
111+
REQUIRE(triangle::flavor::scalene == triangle::kind(0.4, 0.6, 0.3));
74112
}
75113

76-
TEST_CASE("triangles_violating_triangle_inequality_are_illegal")
77-
{
78-
REQUIRE_THROWS_AS(triangle::kind(1, 1, 3), std::domain_error);
114+
TEST_CASE("all zero sides is not a triangle",
115+
"[16e8ceb0-eadb-46d1-b892-c50327479251]") {
116+
REQUIRE_THROWS_AS(triangle::kind(0, 0, 0), std::domain_error);
79117
}
80118

81-
TEST_CASE("larger_triangles_violating_triangle_inequality_are_illegal")
82-
{
83-
REQUIRE_THROWS_AS(triangle::kind(7, 3, 2), std::domain_error);
119+
// Tests that are not in the problem spec
120+
// kept for legacy and specific cpp functionality
121+
122+
TEST_CASE("triangles_with_negative_sides_are_illegal") {
123+
REQUIRE_THROWS_AS(triangle::kind(3, 4, -5), std::domain_error);
84124
}
85125

86-
TEST_CASE("double_and_integer_arguments")
87-
{
126+
TEST_CASE("double_and_integer_arguments") {
88127
REQUIRE(triangle::flavor::scalene == triangle::kind(5.5, 4, 2));
89128
}
129+
90130
#endif

0 commit comments

Comments
 (0)