Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Triangle - A bug or an extension? #289

Merged
merged 12 commits into from
Feb 14, 2024
6 changes: 6 additions & 0 deletions exercises/practice/triangle/.docs/instructions.append.md
cpmachado marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# Instructions Append

## Bonus: mixed types

If you're up for it, there are a couple of bonus tests where the types of the arguments are not all the same.
These tests are optional, so you don't _have_ to solve before submitting your solution.
22 changes: 12 additions & 10 deletions exercises/practice/triangle/.meta/triangle.example.pl
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
triangle(Side, Side, Side, "equilateral") :-
valid_triangle(Side, Side, Side), !.
triangle(Side1, Side2, Side3, "equilateral") :-
Side1 =:= Side2,
Side2 =:= Side3,
valid_triangle(Side1, Side2, Side3).

triangle(SideEq, SideEq, OtherSide, "isosceles") :-
valid_triangle(SideEq, SideEq, OtherSide), !.

triangle(SideEq, OtherSide, SideEq, "isosceles") :-
valid_triangle(SideEq, SideEq, OtherSide), !.

triangle(OtherSide, SideEq, SideEq, "isosceles") :-
valid_triangle(SideEq, SideEq, OtherSide), !.
triangle(Side1, Side2, Side3, "isosceles") :-
(
Side1 =:= Side2
; Side1 =:= Side3
; Side2 =:= Side3
),
valid_triangle(Side1, Side2, Side3).

triangle(Side1, Side2, Side3, "scalene") :-
\+ triangle(Side1, Side2, Side3, "equilateral"),
Expand All @@ -25,3 +26,4 @@
Side1 \== 0,
Side2 \== 0,
Side3 \== 0.

20 changes: 19 additions & 1 deletion exercises/practice/triangle/triangle_tests.plt
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ pending :-

:- begin_tests(equilateral_triangle).

test(all_sides_are_equal, condition(true)) :-
test(all_sides_are_equal) :-
triangle(2, 2, 2, "equilateral").

test(any_side_is_unequal, [fail, condition(pending)]) :-
Expand Down Expand Up @@ -72,3 +72,21 @@ pending :-
triangle((0.5), (0.4), (0.6), "scalene").

:- end_tests(scalene_triangle).


% BONUS TESTS
bonus :-
current_prolog_flag(argv, ['--bonus'|_]).

:- begin_tests(triangle_bonus, [condition(bonus)]).

test(all_sides_are_equal_but_mixed_types) :-
triangle(2, 2.0, 2, "equilateral").

test(sides_are_a_mix) :-
triangle(5, 4, 5.0, "isosceles").

test(no_sides_are_equal_mixed) :-
triangle(5.0, 4, 6, "scalene").

:- end_tests(triangle_bonus).
Loading