Skip to content

Commit 0d9c30f

Browse files
committed
Split-Second Stopwatch - Fix tests exercising total
1 parent d48f7dc commit 0d9c30f

2 files changed

Lines changed: 18 additions & 0 deletions

File tree

exercises/practice/split-second-stopwatch/.meta/test_template.ecr

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,10 @@ describe "<%-= to_capitalized(@json["exercise"].to_s) %>" do
2121
<%- end %>
2222
<%- elsif command["command"] == "advanceTime" %>
2323
stopwatch.advance_time("<%= command["by"] %>")
24+
<%- elsif command["command"] == "total" %>
25+
stopwatch.total.should eq("<%= command["expected"] %>")
26+
<%- else %>
27+
raise "Unknown command: #{command["command"]}"
2428
<%- end %>
2529
<%- end %>
2630
end

exercises/practice/split-second-stopwatch/spec/split_second_stopwatch_spec.cr

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@ describe "SplitSecondStopwatch" do
1616

1717
pending "new stopwatch's total has no elapsed time" do
1818
stopwatch = SplitSecondStopwatch.new
19+
20+
stopwatch.total.should eq("00:00:00")
1921
end
2022

2123
pending "new stopwatch does not have previous laps" do
@@ -56,6 +58,8 @@ describe "SplitSecondStopwatch" do
5658
stopwatch.start
5759

5860
stopwatch.advance_time("00:00:23")
61+
62+
stopwatch.total.should eq("00:00:23")
5963
end
6064

6165
pending "start cannot be called from running state" do
@@ -102,6 +106,8 @@ describe "SplitSecondStopwatch" do
102106
stopwatch.stop
103107

104108
stopwatch.advance_time("00:00:44")
109+
110+
stopwatch.total.should eq("00:00:13")
105111
end
106112

107113
pending "stop cannot be called from ready state" do
@@ -168,6 +174,8 @@ describe "SplitSecondStopwatch" do
168174
stopwatch.start
169175

170176
stopwatch.advance_time("00:00:09")
177+
178+
stopwatch.total.should eq("00:00:32")
171179
end
172180

173181
pending "lap adds current lap to previous laps" do
@@ -214,6 +222,8 @@ describe "SplitSecondStopwatch" do
214222
stopwatch.lap
215223

216224
stopwatch.advance_time("00:00:33")
225+
226+
stopwatch.total.should eq("00:00:55")
217227
end
218228

219229
pending "lap cannot be called from ready state" do
@@ -335,6 +345,8 @@ describe "SplitSecondStopwatch" do
335345

336346
stopwatch.current_lap.should eq("04:01:40")
337347

348+
stopwatch.total.should eq("05:25:25")
349+
338350
stopwatch.lap
339351

340352
stopwatch.previous_laps.should eq(["01:23:45", "04:01:40"])
@@ -343,6 +355,8 @@ describe "SplitSecondStopwatch" do
343355

344356
stopwatch.current_lap.should eq("08:43:05")
345357

358+
stopwatch.total.should eq("14:08:30")
359+
346360
stopwatch.lap
347361

348362
stopwatch.previous_laps.should eq(["01:23:45", "04:01:40", "08:43:05"])

0 commit comments

Comments
 (0)