Skip to content

Commit

Permalink
triangle: Add tests for floats
Browse files Browse the repository at this point in the history
These have always been present, ever since
exercism/problem-specifications#424. If the
Crystal track wishes its generator to produce the test suite, without
need for post-hoc modification of the generated output, then it seems
the two choices are:

1. Include the cases
2. Add code that detects float inputs and does not output those cases.

This commit implements the former plan.
  • Loading branch information
petertseng committed Nov 1, 2019
1 parent 196edcb commit de45017
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
12 changes: 12 additions & 0 deletions exercises/triangle/spec/triangle_spec.cr
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,10 @@ describe "Triangle" do
Triangle.new([0, 0, 0]).equilateral?.should eq(false)
end

pending "sides may be floats" do
Triangle.new([0.5, 0.5, 0.5]).equilateral?.should eq(true)
end

pending "true if last two sides are equal" do
Triangle.new([3, 4, 4]).isosceles?.should eq(true)
end
Expand All @@ -42,6 +46,10 @@ describe "Triangle" do
Triangle.new([1, 1, 3]).isosceles?.should eq(false)
end

pending "sides may be floats" do
Triangle.new([0.5, 0.4, 0.5]).isosceles?.should eq(true)
end

pending "true if no sides are equal" do
Triangle.new([5, 4, 6]).scalene?.should eq(true)
end
Expand All @@ -57,4 +65,8 @@ describe "Triangle" do
pending "Sides that violate triangle inequality are not scalene, even if they are all different" do
Triangle.new([7, 3, 2]).scalene?.should eq(false)
end

pending "sides may be floats" do
Triangle.new([0.5, 0.4, 0.6]).scalene?.should eq(true)
end
end
2 changes: 1 addition & 1 deletion exercises/triangle/src/example.cr
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
class Triangle
def initialize(sides)
def initialize(sides : Array(Int32) | Array(Float64))
@sides = sides
@sides = [] of Int32 if illegal?
end
Expand Down

0 comments on commit de45017

Please sign in to comment.