Skip to content

Commit 1d95202

Browse files
committed
Add templates for exercises batch 12
1 parent 1afb11e commit 1d95202

File tree

15 files changed

+472
-236
lines changed

15 files changed

+472
-236
lines changed

exercises/practice/triangle/.docs/instructions.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,8 @@ A _scalene_ triangle has all sides of different lengths.
1414
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.
1515

1616
~~~~exercism/note
17-
We opted to not include tests for degenerate triangles (triangles that violate these rules) to keep things simpler.
17+
_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`.
18+
We opted to not include tests for degenerate triangles in this exercise.
1819
You may handle those situations if you wish to do so, or safely ignore them.
1920
~~~~
2021

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
require 'minitest/autorun'
2+
require_relative 'triangle'
3+
4+
class TriangleTest < Minitest::Test
5+
<% json["cases"].each do |cases| %>
6+
<% cases["cases"].each do |sub_case| %>
7+
def test_<%= underscore(sub_case["description"]) %>
8+
<%= skip? %>
9+
actual = Triangle.new(<%= sub_case["input"]["sides"] %>).<%= sub_case["property"] %>?
10+
<%= sub_case["expected"] ? "assert" : "refute" %> actual, "Expected '<%= sub_case["expected"] %>', triangle <%= sub_case["input"]["sides"] %> is <%= sub_case["expected"] ? "" : "not " %><%= sub_case["property"] %>."
11+
end
12+
<% end %>
13+
<% end %>
14+
end

exercises/practice/triangle/triangle_test.rb

Lines changed: 63 additions & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -2,129 +2,129 @@
22
require_relative 'triangle'
33

44
class TriangleTest < Minitest::Test
5-
def test_equilateral_triangle_all_sides_are_equal
5+
def test_all_sides_are_equal
66
# skip
7-
triangle = Triangle.new([2, 2, 2])
8-
assert triangle.equilateral?, "Expected 'true', triangle [2, 2, 2] is equilateral."
7+
actual = Triangle.new([2, 2, 2]).equilateral?
8+
assert actual, "Expected 'true', triangle [2, 2, 2] is equilateral."
99
end
1010

11-
def test_equilateral_triangle_any_side_is_unequal
11+
def test_any_side_is_unequal
1212
skip
13-
triangle = Triangle.new([2, 3, 2])
14-
refute triangle.equilateral?, "Expected 'false', triangle [2, 3, 2] is not equilateral."
13+
actual = Triangle.new([2, 3, 2]).equilateral?
14+
refute actual, "Expected 'false', triangle [2, 3, 2] is not equilateral."
1515
end
1616

17-
def test_equilateral_triangle_no_sides_are_equal
17+
def test_no_sides_are_equal
1818
skip
19-
triangle = Triangle.new([5, 4, 6])
20-
refute triangle.equilateral?, "Expected 'false', triangle [5, 4, 6] is not equilateral."
19+
actual = Triangle.new([5, 4, 6]).equilateral?
20+
refute actual, "Expected 'false', triangle [5, 4, 6] is not equilateral."
2121
end
2222

23-
def test_equilateral_triangle_all_zero_sides_is_not_a_triangle
23+
def test_all_zero_sides_is_not_a_triangle
2424
skip
25-
triangle = Triangle.new([0, 0, 0])
26-
refute triangle.equilateral?, "Expected 'false', triangle [0, 0, 0] is not equilateral."
25+
actual = Triangle.new([0, 0, 0]).equilateral?
26+
refute actual, "Expected 'false', triangle [0, 0, 0] is not equilateral."
2727
end
2828

29-
def test_equilateral_triangle_sides_may_be_floats
29+
def test_sides_may_be_floats
3030
skip
31-
triangle = Triangle.new([0.5, 0.5, 0.5])
32-
assert triangle.equilateral?, "Expected 'true', triangle [0.5, 0.5, 0.5] is equilateral."
31+
actual = Triangle.new([0.5, 0.5, 0.5]).equilateral?
32+
assert actual, "Expected 'true', triangle [0.5, 0.5, 0.5] is equilateral."
3333
end
3434

35-
def test_isosceles_triangle_last_two_sides_are_equal
35+
def test_last_two_sides_are_equal
3636
skip
37-
triangle = Triangle.new([3, 4, 4])
38-
assert triangle.isosceles?, "Expected 'true', triangle [3, 4, 4] is isosceles."
37+
actual = Triangle.new([3, 4, 4]).isosceles?
38+
assert actual, "Expected 'true', triangle [3, 4, 4] is isosceles."
3939
end
4040

41-
def test_isosceles_triangle_first_two_sides_are_equal
41+
def test_first_two_sides_are_equal
4242
skip
43-
triangle = Triangle.new([4, 4, 3])
44-
assert triangle.isosceles?, "Expected 'true', triangle [4, 4, 3] is isosceles."
43+
actual = Triangle.new([4, 4, 3]).isosceles?
44+
assert actual, "Expected 'true', triangle [4, 4, 3] is isosceles."
4545
end
4646

47-
def test_isosceles_triangle_first_and_last_sides_are_equal
47+
def test_first_and_last_sides_are_equal
4848
skip
49-
triangle = Triangle.new([4, 3, 4])
50-
assert triangle.isosceles?, "Expected 'true', triangle [4, 3, 4] is isosceles."
49+
actual = Triangle.new([4, 3, 4]).isosceles?
50+
assert actual, "Expected 'true', triangle [4, 3, 4] is isosceles."
5151
end
5252

53-
def test_isosceles_triangle_equilateral_triangles_are_also_isosceles
53+
def test_equilateral_triangles_are_also_isosceles
5454
skip
55-
triangle = Triangle.new([4, 4, 4])
56-
assert triangle.isosceles?, "Expected 'true', triangle [4, 4, 4] is isosceles."
55+
actual = Triangle.new([4, 4, 4]).isosceles?
56+
assert actual, "Expected 'true', triangle [4, 4, 4] is isosceles."
5757
end
5858

59-
def test_isosceles_triangle_no_sides_are_equal
59+
def test_no_sides_are_equal
6060
skip
61-
triangle = Triangle.new([2, 3, 4])
62-
refute triangle.isosceles?, "Expected 'false', triangle [2, 3, 4] is not isosceles."
61+
actual = Triangle.new([2, 3, 4]).isosceles?
62+
refute actual, "Expected 'false', triangle [2, 3, 4] is not isosceles."
6363
end
6464

65-
def test_isosceles_triangle_first_triangle_inequality_violation
65+
def test_first_triangle_inequality_violation
6666
skip
67-
triangle = Triangle.new([1, 1, 3])
68-
refute triangle.isosceles?, "Expected 'false', triangle [1, 1, 3] is not isosceles."
67+
actual = Triangle.new([1, 1, 3]).isosceles?
68+
refute actual, "Expected 'false', triangle [1, 1, 3] is not isosceles."
6969
end
7070

71-
def test_isosceles_triangle_second_triangle_inequality_violation
71+
def test_second_triangle_inequality_violation
7272
skip
73-
triangle = Triangle.new([1, 3, 1])
74-
refute triangle.isosceles?, "Expected 'false', triangle [1, 3, 1] is not isosceles."
73+
actual = Triangle.new([1, 3, 1]).isosceles?
74+
refute actual, "Expected 'false', triangle [1, 3, 1] is not isosceles."
7575
end
7676

77-
def test_isosceles_triangle_third_triangle_inequality_violation
77+
def test_third_triangle_inequality_violation
7878
skip
79-
triangle = Triangle.new([3, 1, 1])
80-
refute triangle.isosceles?, "Expected 'false', triangle [3, 1, 1] is not isosceles."
79+
actual = Triangle.new([3, 1, 1]).isosceles?
80+
refute actual, "Expected 'false', triangle [3, 1, 1] is not isosceles."
8181
end
8282

83-
def test_isosceles_triangle_sides_may_be_floats
83+
def test_sides_may_be_floats
8484
skip
85-
triangle = Triangle.new([0.5, 0.4, 0.5])
86-
assert triangle.isosceles?, "Expected 'true', triangle [0.5, 0.4, 0.5] is isosceles."
85+
actual = Triangle.new([0.5, 0.4, 0.5]).isosceles?
86+
assert actual, "Expected 'true', triangle [0.5, 0.4, 0.5] is isosceles."
8787
end
8888

89-
def test_scalene_triangle_no_sides_are_equal
89+
def test_no_sides_are_equal
9090
skip
91-
triangle = Triangle.new([5, 4, 6])
92-
assert triangle.scalene?, "Expected 'true', triangle [5, 4, 6] is scalene."
91+
actual = Triangle.new([5, 4, 6]).scalene?
92+
assert actual, "Expected 'true', triangle [5, 4, 6] is scalene."
9393
end
9494

95-
def test_scalene_triangle_all_sides_are_equal
95+
def test_all_sides_are_equal
9696
skip
97-
triangle = Triangle.new([4, 4, 4])
98-
refute triangle.scalene?, "Expected 'false', triangle [4, 4, 4] is not scalene."
97+
actual = Triangle.new([4, 4, 4]).scalene?
98+
refute actual, "Expected 'false', triangle [4, 4, 4] is not scalene."
9999
end
100100

101-
def test_scalene_triangle_first_and_second_sides_are_equal
101+
def test_first_and_second_sides_are_equal
102102
skip
103-
triangle = Triangle.new([4, 4, 3])
104-
refute triangle.scalene?, "Expected 'false', triangle [4, 4, 3] is not scalene."
103+
actual = Triangle.new([4, 4, 3]).scalene?
104+
refute actual, "Expected 'false', triangle [4, 4, 3] is not scalene."
105105
end
106106

107-
def test_scalene_triangle_first_and_third_sides_are_equal
107+
def test_first_and_third_sides_are_equal
108108
skip
109-
triangle = Triangle.new([3, 4, 3])
110-
refute triangle.scalene?, "Expected 'false', triangle [3, 4, 3] is not scalene."
109+
actual = Triangle.new([3, 4, 3]).scalene?
110+
refute actual, "Expected 'false', triangle [3, 4, 3] is not scalene."
111111
end
112112

113-
def test_scalene_triangle_second_and_third_sides_are_equal
113+
def test_second_and_third_sides_are_equal
114114
skip
115-
triangle = Triangle.new([4, 3, 3])
116-
refute triangle.scalene?, "Expected 'false', triangle [4, 3, 3] is not scalene."
115+
actual = Triangle.new([4, 3, 3]).scalene?
116+
refute actual, "Expected 'false', triangle [4, 3, 3] is not scalene."
117117
end
118118

119-
def test_scalene_triangle_may_not_violate_triangle_inequality
119+
def test_may_not_violate_triangle_inequality
120120
skip
121-
triangle = Triangle.new([7, 3, 2])
122-
refute triangle.scalene?, "Expected 'false', triangle [7, 3, 2] is not scalene."
121+
actual = Triangle.new([7, 3, 2]).scalene?
122+
refute actual, "Expected 'false', triangle [7, 3, 2] is not scalene."
123123
end
124124

125-
def test_scalene_triangle_sides_may_be_floats
125+
def test_sides_may_be_floats
126126
skip
127-
triangle = Triangle.new([0.5, 0.4, 0.6])
128-
assert triangle.scalene?, "Expected 'true', triangle [0.5, 0.4, 0.6] is scalene."
127+
actual = Triangle.new([0.5, 0.4, 0.6]).scalene?
128+
assert actual, "Expected 'true', triangle [0.5, 0.4, 0.6] is scalene."
129129
end
130130
end
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
require 'minitest/autorun'
2+
require_relative 'two_bucket'
3+
4+
class TwoBucketTest < Minitest::Test
5+
<% json["cases"].each do |cases| %>
6+
def test_<%= underscore(cases["description"]) %>
7+
<%= skip? %>
8+
subject = TwoBucket.new(<%= cases["input"].values.inspect[1...-1] %>)
9+
actual = [subject.moves, subject.goal_bucket, subject.other_bucket]
10+
expected = <%= cases["expected"].values %>
11+
assert_equal expected, actual
12+
end
13+
<% end %>
14+
end

exercises/practice/two-bucket/.meta/tests.toml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,12 @@ description = "Measure one step using bucket one of size 1 and bucket two of siz
2727
[eb329c63-5540-4735-b30b-97f7f4df0f84]
2828
description = "Measure using bucket one of size 2 and bucket two of size 3 - start with bucket one and end with bucket two"
2929

30+
[58d70152-bf2b-46bb-ad54-be58ebe94c03]
31+
description = "Measure using bucket one much bigger than bucket two"
32+
33+
[9dbe6499-caa5-4a58-b5ce-c988d71b8981]
34+
description = "Measure using bucket one much smaller than bucket two"
35+
3036
[449be72d-b10a-4f4b-a959-ca741e333b72]
3137
description = "Not possible to reach the goal"
3238
include = false

exercises/practice/two-bucket/two_bucket_test.rb

Lines changed: 43 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -2,59 +2,75 @@
22
require_relative 'two_bucket'
33

44
class TwoBucketTest < Minitest::Test
5-
def test_measure_using_bucket_one_of_size_3_and_bucket_two_of_size_5_start_with_bucket_one
5+
def test_measure_using_bucket_one_of_size_3_and_bucket_two_of_size_5___start_with_bucket_one
66
# skip
77
subject = TwoBucket.new(3, 5, 1, "one")
8-
assert_equal 4, subject.moves
9-
assert_equal "one", subject.goal_bucket
10-
assert_equal 5, subject.other_bucket
8+
actual = [subject.moves, subject.goal_bucket, subject.other_bucket]
9+
expected = [4, "one", 5]
10+
assert_equal expected, actual
1111
end
1212

13-
def test_measure_using_bucket_one_of_size_3_and_bucket_two_of_size_5_start_with_bucket_two
13+
def test_measure_using_bucket_one_of_size_3_and_bucket_two_of_size_5___start_with_bucket_two
1414
skip
1515
subject = TwoBucket.new(3, 5, 1, "two")
16-
assert_equal 8, subject.moves
17-
assert_equal "two", subject.goal_bucket
18-
assert_equal 3, subject.other_bucket
16+
actual = [subject.moves, subject.goal_bucket, subject.other_bucket]
17+
expected = [8, "two", 3]
18+
assert_equal expected, actual
1919
end
2020

21-
def test_measure_using_bucket_one_of_size_7_and_bucket_two_of_size_11_start_with_bucket_one
21+
def test_measure_using_bucket_one_of_size_7_and_bucket_two_of_size_11___start_with_bucket_one
2222
skip
2323
subject = TwoBucket.new(7, 11, 2, "one")
24-
assert_equal 14, subject.moves
25-
assert_equal "one", subject.goal_bucket
26-
assert_equal 11, subject.other_bucket
24+
actual = [subject.moves, subject.goal_bucket, subject.other_bucket]
25+
expected = [14, "one", 11]
26+
assert_equal expected, actual
2727
end
2828

29-
def test_measure_using_bucket_one_of_size_7_and_bucket_two_of_size_11_start_with_bucket_two
29+
def test_measure_using_bucket_one_of_size_7_and_bucket_two_of_size_11___start_with_bucket_two
3030
skip
3131
subject = TwoBucket.new(7, 11, 2, "two")
32-
assert_equal 18, subject.moves
33-
assert_equal "two", subject.goal_bucket
34-
assert_equal 7, subject.other_bucket
32+
actual = [subject.moves, subject.goal_bucket, subject.other_bucket]
33+
expected = [18, "two", 7]
34+
assert_equal expected, actual
3535
end
3636

37-
def test_measure_one_step_using_bucket_one_of_size_1_and_bucket_two_of_size_3_start_with_bucket_two
37+
def test_measure_one_step_using_bucket_one_of_size_1_and_bucket_two_of_size_3___start_with_bucket_two
3838
skip
3939
subject = TwoBucket.new(1, 3, 3, "two")
40-
assert_equal 1, subject.moves
41-
assert_equal "two", subject.goal_bucket
42-
assert_equal 0, subject.other_bucket
40+
actual = [subject.moves, subject.goal_bucket, subject.other_bucket]
41+
expected = [1, "two", 0]
42+
assert_equal expected, actual
4343
end
4444

45-
def test_measure_using_bucket_one_of_size_2_and_bucket_two_of_size_3_start_with_bucket_one_and_end_with_bucket_two
45+
def test_measure_using_bucket_one_of_size_2_and_bucket_two_of_size_3___start_with_bucket_one_and_end_with_bucket_two
4646
skip
4747
subject = TwoBucket.new(2, 3, 3, "one")
48-
assert_equal 2, subject.moves
49-
assert_equal "two", subject.goal_bucket
50-
assert_equal 2, subject.other_bucket
48+
actual = [subject.moves, subject.goal_bucket, subject.other_bucket]
49+
expected = [2, "two", 2]
50+
assert_equal expected, actual
51+
end
52+
53+
def test_measure_using_bucket_one_much_bigger_than_bucket_two
54+
skip
55+
subject = TwoBucket.new(5, 1, 2, "one")
56+
actual = [subject.moves, subject.goal_bucket, subject.other_bucket]
57+
expected = [6, "one", 1]
58+
assert_equal expected, actual
59+
end
60+
61+
def test_measure_using_bucket_one_much_smaller_than_bucket_two
62+
skip
63+
subject = TwoBucket.new(3, 15, 9, "one")
64+
actual = [subject.moves, subject.goal_bucket, subject.other_bucket]
65+
expected = [6, "two", 0]
66+
assert_equal expected, actual
5167
end
5268

5369
def test_with_the_same_buckets_but_a_different_goal_then_it_is_possible
5470
skip
5571
subject = TwoBucket.new(6, 15, 9, "one")
56-
assert_equal 10, subject.moves
57-
assert_equal "two", subject.goal_bucket
58-
assert_equal 0, subject.other_bucket
72+
actual = [subject.moves, subject.goal_bucket, subject.other_bucket]
73+
expected = [10, "two", 0]
74+
assert_equal expected, actual
5975
end
6076
end
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
require 'minitest/autorun'
2+
require_relative 'two_fer'
3+
4+
class TwoFerTest < Minitest::Test
5+
<% json["cases"].each do |cases| %>
6+
def test_<%= underscore(cases["description"]) %>
7+
<%= skip? %>
8+
actual = TwoFer.two_fer(<%= cases["input"]["name"] ? "'#{cases["input"]["name"]}'" : "" %>)
9+
expected = '<%= cases["expected"] %>'
10+
assert_equal expected, actual
11+
end
12+
<% end %>
13+
end

exercises/practice/two-fer/two_fer_test.rb

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,16 +4,22 @@
44
class TwoFerTest < Minitest::Test
55
def test_no_name_given
66
# skip
7-
assert_equal "One for you, one for me.", TwoFer.two_fer
7+
actual = TwoFer.two_fer
8+
expected = 'One for you, one for me.'
9+
assert_equal expected, actual
810
end
911

1012
def test_a_name_given
1113
skip
12-
assert_equal "One for Alice, one for me.", TwoFer.two_fer("Alice")
14+
actual = TwoFer.two_fer('Alice')
15+
expected = 'One for Alice, one for me.'
16+
assert_equal expected, actual
1317
end
1418

1519
def test_another_name_given
1620
skip
17-
assert_equal "One for Bob, one for me.", TwoFer.two_fer("Bob")
21+
actual = TwoFer.two_fer('Bob')
22+
expected = 'One for Bob, one for me.'
23+
assert_equal expected, actual
1824
end
1925
end

0 commit comments

Comments
 (0)