Skip to content

Commit 2b1e0c2

Browse files
committed
Clock: Canonical test improvements
Generated from x-common clock data Now generates tests from data in x-common. The template file is skinny, the generator a little fatter. fixes #282 references exercism/problem-specifications#166
1 parent 2898686 commit 2b1e0c2

File tree

3 files changed

+10
-9
lines changed

3 files changed

+10
-9
lines changed

exercises/clock/clock_test.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,7 @@ def test_add_across_midnight
132132
assert '00:01', Clock.at(23, 59) + 2
133133
end
134134

135-
def test_add_more_than_one_day__1500_min_is_equal_to_25_hrs_
135+
def test_add_more_than_one_day__1500_min_is_equal_to_25_hrs
136136
skip
137137
assert '06:32', Clock.at(5, 32) + 1500
138138
end
@@ -172,7 +172,7 @@ def test_subtract_more_than_two_hours_with_borrow
172172
assert '03:35', Clock.at(6, 15) + -160
173173
end
174174

175-
def test_subtract_more_than_one_day__1500_min_is_equal_to_25_hrs_
175+
def test_subtract_more_than_one_day__1500_min_is_equal_to_25_hrs
176176
skip
177177
assert '04:32', Clock.at(5, 32) + -1500
178178
end

exercises/clock/example.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,12 @@ def self.at(*args)
55
Clock.new(*args)
66
end
77

8-
def initialize(hours = 0, minutes = 0)
8+
def initialize(hours=0, minutes=0)
99
@internal = hours * 60 + minutes
1010
end
1111

1212
# rubocop:disable Style/OpMethod
13-
def +(hours = 0, minutes)
13+
def +(hours=0, minutes)
1414
@internal += hours * 60 + minutes
1515
self
1616
end

lib/clock_cases.rb

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
11
class ClockCase < OpenStruct
22
def name
3-
'test_%s' % description.gsub(/[\(\) -]/, '_').gsub('=', 'is_equal_to')
3+
'test_%s' % description
4+
.gsub(/[() -]/, '_')
5+
.gsub('=', 'is_equal_to')
6+
.chomp('_')
47
end
58

69
def test_body
7-
section == 'equal' &&
8-
compare_clocks || simple_test
10+
section == 'equal' ? compare_clocks : simple_test
911
end
1012

1113
def compare_clocks
@@ -27,11 +29,10 @@ def add_to_clock
2729
end
2830

2931
def skipped
30-
index > 0 && 'skip' || '# skip'
32+
index.zero? ? '# skip' : 'skip'
3133
end
3234
end
3335

34-
require 'pp'
3536
ClockCases = proc do |data|
3637
i = 0
3738
json = JSON.parse(data)

0 commit comments

Comments
 (0)