Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion exercises/practice/triangle/.docs/instructions.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@ A _scalene_ triangle has all sides of different lengths.
For a shape to be a triangle at all, all sides have to be of length > 0, and the sum of the lengths of any two sides must be greater than or equal to the length of the third side.

~~~~exercism/note
We opted to not include tests for degenerate triangles (triangles that violate these rules) to keep things simpler.
_Degenerate triangles_ are triangles where the sum of the length of two sides is **equal** to the length of the third side, e.g. `1, 1, 2`.
We opted to not include tests for degenerate triangles in this exercise.
You may handle those situations if you wish to do so, or safely ignore them.
~~~~

Expand Down
14 changes: 14 additions & 0 deletions exercises/practice/triangle/.meta/test_template.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
require 'minitest/autorun'
require_relative 'triangle'

class TriangleTest < Minitest::Test
<% json["cases"].each do |cases| %>
<% cases["cases"].each do |sub_case| %>
def test_<%= underscore(sub_case["description"]) %>_on_<%= underscore(cases["description"])%>
<%= skip? %>
actual = Triangle.new(<%= sub_case["input"]["sides"] %>).<%= sub_case["property"] %>?
<%= sub_case["expected"] ? "assert" : "refute" %> actual, "Expected '<%= sub_case["expected"] %>', triangle <%= sub_case["input"]["sides"] %> is <%= sub_case["expected"] ? "" : "not " %><%= sub_case["property"] %>."
end
<% end %>
<% end %>
end
126 changes: 63 additions & 63 deletions exercises/practice/triangle/triangle_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,129 +2,129 @@
require_relative 'triangle'

class TriangleTest < Minitest::Test
def test_equilateral_triangle_all_sides_are_equal
def test_all_sides_are_equal_on_equilateral_triangle
# skip
triangle = Triangle.new([2, 2, 2])
assert triangle.equilateral?, "Expected 'true', triangle [2, 2, 2] is equilateral."
actual = Triangle.new([2, 2, 2]).equilateral?
assert actual, "Expected 'true', triangle [2, 2, 2] is equilateral."
end

def test_equilateral_triangle_any_side_is_unequal
def test_any_side_is_unequal_on_equilateral_triangle
skip
triangle = Triangle.new([2, 3, 2])
refute triangle.equilateral?, "Expected 'false', triangle [2, 3, 2] is not equilateral."
actual = Triangle.new([2, 3, 2]).equilateral?
refute actual, "Expected 'false', triangle [2, 3, 2] is not equilateral."
end

def test_equilateral_triangle_no_sides_are_equal
def test_no_sides_are_equal_on_equilateral_triangle
skip
triangle = Triangle.new([5, 4, 6])
refute triangle.equilateral?, "Expected 'false', triangle [5, 4, 6] is not equilateral."
actual = Triangle.new([5, 4, 6]).equilateral?
refute actual, "Expected 'false', triangle [5, 4, 6] is not equilateral."
end

def test_equilateral_triangle_all_zero_sides_is_not_a_triangle
def test_all_zero_sides_is_not_a_triangle_on_equilateral_triangle
skip
triangle = Triangle.new([0, 0, 0])
refute triangle.equilateral?, "Expected 'false', triangle [0, 0, 0] is not equilateral."
actual = Triangle.new([0, 0, 0]).equilateral?
refute actual, "Expected 'false', triangle [0, 0, 0] is not equilateral."
end

def test_equilateral_triangle_sides_may_be_floats
def test_sides_may_be_floats_on_equilateral_triangle
skip
triangle = Triangle.new([0.5, 0.5, 0.5])
assert triangle.equilateral?, "Expected 'true', triangle [0.5, 0.5, 0.5] is equilateral."
actual = Triangle.new([0.5, 0.5, 0.5]).equilateral?
assert actual, "Expected 'true', triangle [0.5, 0.5, 0.5] is equilateral."
end

def test_isosceles_triangle_last_two_sides_are_equal
def test_last_two_sides_are_equal_on_isosceles_triangle
skip
triangle = Triangle.new([3, 4, 4])
assert triangle.isosceles?, "Expected 'true', triangle [3, 4, 4] is isosceles."
actual = Triangle.new([3, 4, 4]).isosceles?
assert actual, "Expected 'true', triangle [3, 4, 4] is isosceles."
end

def test_isosceles_triangle_first_two_sides_are_equal
def test_first_two_sides_are_equal_on_isosceles_triangle
skip
triangle = Triangle.new([4, 4, 3])
assert triangle.isosceles?, "Expected 'true', triangle [4, 4, 3] is isosceles."
actual = Triangle.new([4, 4, 3]).isosceles?
assert actual, "Expected 'true', triangle [4, 4, 3] is isosceles."
end

def test_isosceles_triangle_first_and_last_sides_are_equal
def test_first_and_last_sides_are_equal_on_isosceles_triangle
skip
triangle = Triangle.new([4, 3, 4])
assert triangle.isosceles?, "Expected 'true', triangle [4, 3, 4] is isosceles."
actual = Triangle.new([4, 3, 4]).isosceles?
assert actual, "Expected 'true', triangle [4, 3, 4] is isosceles."
end

def test_isosceles_triangle_equilateral_triangles_are_also_isosceles
def test_equilateral_triangles_are_also_isosceles_on_isosceles_triangle
skip
triangle = Triangle.new([4, 4, 4])
assert triangle.isosceles?, "Expected 'true', triangle [4, 4, 4] is isosceles."
actual = Triangle.new([4, 4, 4]).isosceles?
assert actual, "Expected 'true', triangle [4, 4, 4] is isosceles."
end

def test_isosceles_triangle_no_sides_are_equal
def test_no_sides_are_equal_on_isosceles_triangle
skip
triangle = Triangle.new([2, 3, 4])
refute triangle.isosceles?, "Expected 'false', triangle [2, 3, 4] is not isosceles."
actual = Triangle.new([2, 3, 4]).isosceles?
refute actual, "Expected 'false', triangle [2, 3, 4] is not isosceles."
end

def test_isosceles_triangle_first_triangle_inequality_violation
def test_first_triangle_inequality_violation_on_isosceles_triangle
skip
triangle = Triangle.new([1, 1, 3])
refute triangle.isosceles?, "Expected 'false', triangle [1, 1, 3] is not isosceles."
actual = Triangle.new([1, 1, 3]).isosceles?
refute actual, "Expected 'false', triangle [1, 1, 3] is not isosceles."
end

def test_isosceles_triangle_second_triangle_inequality_violation
def test_second_triangle_inequality_violation_on_isosceles_triangle
skip
triangle = Triangle.new([1, 3, 1])
refute triangle.isosceles?, "Expected 'false', triangle [1, 3, 1] is not isosceles."
actual = Triangle.new([1, 3, 1]).isosceles?
refute actual, "Expected 'false', triangle [1, 3, 1] is not isosceles."
end

def test_isosceles_triangle_third_triangle_inequality_violation
def test_third_triangle_inequality_violation_on_isosceles_triangle
skip
triangle = Triangle.new([3, 1, 1])
refute triangle.isosceles?, "Expected 'false', triangle [3, 1, 1] is not isosceles."
actual = Triangle.new([3, 1, 1]).isosceles?
refute actual, "Expected 'false', triangle [3, 1, 1] is not isosceles."
end

def test_isosceles_triangle_sides_may_be_floats
def test_sides_may_be_floats_on_isosceles_triangle
skip
triangle = Triangle.new([0.5, 0.4, 0.5])
assert triangle.isosceles?, "Expected 'true', triangle [0.5, 0.4, 0.5] is isosceles."
actual = Triangle.new([0.5, 0.4, 0.5]).isosceles?
assert actual, "Expected 'true', triangle [0.5, 0.4, 0.5] is isosceles."
end

def test_scalene_triangle_no_sides_are_equal
def test_no_sides_are_equal_on_scalene_triangle
skip
triangle = Triangle.new([5, 4, 6])
assert triangle.scalene?, "Expected 'true', triangle [5, 4, 6] is scalene."
actual = Triangle.new([5, 4, 6]).scalene?
assert actual, "Expected 'true', triangle [5, 4, 6] is scalene."
end

def test_scalene_triangle_all_sides_are_equal
def test_all_sides_are_equal_on_scalene_triangle
skip
triangle = Triangle.new([4, 4, 4])
refute triangle.scalene?, "Expected 'false', triangle [4, 4, 4] is not scalene."
actual = Triangle.new([4, 4, 4]).scalene?
refute actual, "Expected 'false', triangle [4, 4, 4] is not scalene."
end

def test_scalene_triangle_first_and_second_sides_are_equal
def test_first_and_second_sides_are_equal_on_scalene_triangle
skip
triangle = Triangle.new([4, 4, 3])
refute triangle.scalene?, "Expected 'false', triangle [4, 4, 3] is not scalene."
actual = Triangle.new([4, 4, 3]).scalene?
refute actual, "Expected 'false', triangle [4, 4, 3] is not scalene."
end

def test_scalene_triangle_first_and_third_sides_are_equal
def test_first_and_third_sides_are_equal_on_scalene_triangle
skip
triangle = Triangle.new([3, 4, 3])
refute triangle.scalene?, "Expected 'false', triangle [3, 4, 3] is not scalene."
actual = Triangle.new([3, 4, 3]).scalene?
refute actual, "Expected 'false', triangle [3, 4, 3] is not scalene."
end

def test_scalene_triangle_second_and_third_sides_are_equal
def test_second_and_third_sides_are_equal_on_scalene_triangle
skip
triangle = Triangle.new([4, 3, 3])
refute triangle.scalene?, "Expected 'false', triangle [4, 3, 3] is not scalene."
actual = Triangle.new([4, 3, 3]).scalene?
refute actual, "Expected 'false', triangle [4, 3, 3] is not scalene."
end

def test_scalene_triangle_may_not_violate_triangle_inequality
def test_may_not_violate_triangle_inequality_on_scalene_triangle
skip
triangle = Triangle.new([7, 3, 2])
refute triangle.scalene?, "Expected 'false', triangle [7, 3, 2] is not scalene."
actual = Triangle.new([7, 3, 2]).scalene?
refute actual, "Expected 'false', triangle [7, 3, 2] is not scalene."
end

def test_scalene_triangle_sides_may_be_floats
def test_sides_may_be_floats_on_scalene_triangle
skip
triangle = Triangle.new([0.5, 0.4, 0.6])
assert triangle.scalene?, "Expected 'true', triangle [0.5, 0.4, 0.6] is scalene."
actual = Triangle.new([0.5, 0.4, 0.6]).scalene?
assert actual, "Expected 'true', triangle [0.5, 0.4, 0.6] is scalene."
end
end
14 changes: 14 additions & 0 deletions exercises/practice/two-bucket/.meta/test_template.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
require 'minitest/autorun'
require_relative 'two_bucket'

class TwoBucketTest < Minitest::Test
<% json["cases"].each do |cases| %>
def test_<%= underscore(cases["description"]) %>
<%= skip? %>
subject = TwoBucket.new(<%= cases["input"].values.inspect[1...-1] %>)
actual = [subject.moves, subject.goal_bucket, subject.other_bucket]
expected = <%= cases["expected"].values %>
assert_equal expected, actual
end
<% end %>
end
6 changes: 6 additions & 0 deletions exercises/practice/two-bucket/.meta/tests.toml
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,12 @@ description = "Measure one step using bucket one of size 1 and bucket two of siz
[eb329c63-5540-4735-b30b-97f7f4df0f84]
description = "Measure using bucket one of size 2 and bucket two of size 3 - start with bucket one and end with bucket two"

[58d70152-bf2b-46bb-ad54-be58ebe94c03]
description = "Measure using bucket one much bigger than bucket two"

[9dbe6499-caa5-4a58-b5ce-c988d71b8981]
description = "Measure using bucket one much smaller than bucket two"

[449be72d-b10a-4f4b-a959-ca741e333b72]
description = "Not possible to reach the goal"
include = false
Expand Down
70 changes: 43 additions & 27 deletions exercises/practice/two-bucket/two_bucket_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,59 +2,75 @@
require_relative 'two_bucket'

class TwoBucketTest < Minitest::Test
def test_measure_using_bucket_one_of_size_3_and_bucket_two_of_size_5_start_with_bucket_one
def test_measure_using_bucket_one_of_size_3_and_bucket_two_of_size_5___start_with_bucket_one
# skip
subject = TwoBucket.new(3, 5, 1, "one")
assert_equal 4, subject.moves
assert_equal "one", subject.goal_bucket
assert_equal 5, subject.other_bucket
actual = [subject.moves, subject.goal_bucket, subject.other_bucket]
expected = [4, "one", 5]
assert_equal expected, actual
end

def test_measure_using_bucket_one_of_size_3_and_bucket_two_of_size_5_start_with_bucket_two
def test_measure_using_bucket_one_of_size_3_and_bucket_two_of_size_5___start_with_bucket_two
skip
subject = TwoBucket.new(3, 5, 1, "two")
assert_equal 8, subject.moves
assert_equal "two", subject.goal_bucket
assert_equal 3, subject.other_bucket
actual = [subject.moves, subject.goal_bucket, subject.other_bucket]
expected = [8, "two", 3]
assert_equal expected, actual
end

def test_measure_using_bucket_one_of_size_7_and_bucket_two_of_size_11_start_with_bucket_one
def test_measure_using_bucket_one_of_size_7_and_bucket_two_of_size_11___start_with_bucket_one
skip
subject = TwoBucket.new(7, 11, 2, "one")
assert_equal 14, subject.moves
assert_equal "one", subject.goal_bucket
assert_equal 11, subject.other_bucket
actual = [subject.moves, subject.goal_bucket, subject.other_bucket]
expected = [14, "one", 11]
assert_equal expected, actual
end

def test_measure_using_bucket_one_of_size_7_and_bucket_two_of_size_11_start_with_bucket_two
def test_measure_using_bucket_one_of_size_7_and_bucket_two_of_size_11___start_with_bucket_two
skip
subject = TwoBucket.new(7, 11, 2, "two")
assert_equal 18, subject.moves
assert_equal "two", subject.goal_bucket
assert_equal 7, subject.other_bucket
actual = [subject.moves, subject.goal_bucket, subject.other_bucket]
expected = [18, "two", 7]
assert_equal expected, actual
end

def test_measure_one_step_using_bucket_one_of_size_1_and_bucket_two_of_size_3_start_with_bucket_two
def test_measure_one_step_using_bucket_one_of_size_1_and_bucket_two_of_size_3___start_with_bucket_two
skip
subject = TwoBucket.new(1, 3, 3, "two")
assert_equal 1, subject.moves
assert_equal "two", subject.goal_bucket
assert_equal 0, subject.other_bucket
actual = [subject.moves, subject.goal_bucket, subject.other_bucket]
expected = [1, "two", 0]
assert_equal expected, actual
end

def test_measure_using_bucket_one_of_size_2_and_bucket_two_of_size_3_start_with_bucket_one_and_end_with_bucket_two
def test_measure_using_bucket_one_of_size_2_and_bucket_two_of_size_3___start_with_bucket_one_and_end_with_bucket_two
skip
subject = TwoBucket.new(2, 3, 3, "one")
assert_equal 2, subject.moves
assert_equal "two", subject.goal_bucket
assert_equal 2, subject.other_bucket
actual = [subject.moves, subject.goal_bucket, subject.other_bucket]
expected = [2, "two", 2]
assert_equal expected, actual
end

def test_measure_using_bucket_one_much_bigger_than_bucket_two
skip
subject = TwoBucket.new(5, 1, 2, "one")
actual = [subject.moves, subject.goal_bucket, subject.other_bucket]
expected = [6, "one", 1]
assert_equal expected, actual
end

def test_measure_using_bucket_one_much_smaller_than_bucket_two
skip
subject = TwoBucket.new(3, 15, 9, "one")
actual = [subject.moves, subject.goal_bucket, subject.other_bucket]
expected = [6, "two", 0]
assert_equal expected, actual
end

def test_with_the_same_buckets_but_a_different_goal_then_it_is_possible
skip
subject = TwoBucket.new(6, 15, 9, "one")
assert_equal 10, subject.moves
assert_equal "two", subject.goal_bucket
assert_equal 0, subject.other_bucket
actual = [subject.moves, subject.goal_bucket, subject.other_bucket]
expected = [10, "two", 0]
assert_equal expected, actual
end
end
13 changes: 13 additions & 0 deletions exercises/practice/two-fer/.meta/test_template.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
require 'minitest/autorun'
require_relative 'two_fer'

class TwoFerTest < Minitest::Test
<% json["cases"].each do |cases| %>
def test_<%= underscore(cases["description"]) %>
<%= skip? %>
actual = TwoFer.two_fer(<%= cases["input"]["name"] ? "'#{cases["input"]["name"]}'" : "" %>)
expected = '<%= cases["expected"] %>'
assert_equal expected, actual
end
<% end %>
end
12 changes: 9 additions & 3 deletions exercises/practice/two-fer/two_fer_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,22 @@
class TwoFerTest < Minitest::Test
def test_no_name_given
# skip
assert_equal "One for you, one for me.", TwoFer.two_fer
actual = TwoFer.two_fer
expected = 'One for you, one for me.'
assert_equal expected, actual
end

def test_a_name_given
skip
assert_equal "One for Alice, one for me.", TwoFer.two_fer("Alice")
actual = TwoFer.two_fer('Alice')
expected = 'One for Alice, one for me.'
assert_equal expected, actual
end

def test_another_name_given
skip
assert_equal "One for Bob, one for me.", TwoFer.two_fer("Bob")
actual = TwoFer.two_fer('Bob')
expected = 'One for Bob, one for me.'
assert_equal expected, actual
end
end
Loading