From a28cdde061f262a343c08b10a265af2ff6588133 Mon Sep 17 00:00:00 2001 From: sabine Date: Tue, 14 Aug 2018 10:50:41 -0700 Subject: [PATCH 1/4] The test is not passing but just added the files --- clock.rb | 16 +++++++++++ clock_spec.rb | 74 +++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 90 insertions(+) diff --git a/clock.rb b/clock.rb index 01e8856..d569357 100644 --- a/clock.rb +++ b/clock.rb @@ -1 +1,17 @@ # clock.rb + +def clock(hours, minutes, seconds) +# if hours < 10 +# hours = "0#{hours}" +if hours > 23 || hours < 0 + raise ArgumentError, 'Hours must be between 0-23' +end +if minutes < 10 + minutes = "0#{minutes}" +end +if seconds < 10 + seconds = "0#{seconds}" +end + return "#{hours}:#{minutes}:#{seconds}" +end + # What edge case does this cover? diff --git a/clock_spec.rb b/clock_spec.rb index f5b114b..cc3fff9 100644 --- a/clock_spec.rb +++ b/clock_spec.rb @@ -1 +1,75 @@ # clock_spec.rb + +# run spec files and minitest reporters +# to get colors +require 'minitest/autorun' +require 'minitest/reporters' +require_relative 'clock' + +Minitest::Reporters.use! + +# This is to describe my test (Each block represents one tets) + +describe 'Clock' do + it 'will return a string' do # this will return a string + + # Arrange the situation + hours = 9 + minutes = 25 + seconds = 46 + + # Act - Perform the action we are trying to test + time = clock(hours, minutes, seconds) + + # Assert what I am expecting to be true - step (no matter what is does it needs to give us string) + expect(time).must_be_instance_of String # this is an expectation that the result will be an instanc of string + end + + it 'will return a string formatted in hh:mm:ss format when hours is a single digit' do + #Arrange + hours = 9 + minutes = 25 + seconds = 46 + + #Act + time = clock(hours, minutes, seconds) + + #Assert + expect(time).must_equal '09:25:46' + end + + it ' will return a string formated in hh:mm:ss even when the minutes are single digits ' do + #Arrange + hours = 9 + minutes = 3 + seconds = 7 + + #Act + time = clock(hours, minutes, seconds) + + #Assert + expect(time).must_equal '09:03:07' +end + +it 'will raise an error for an invalid hour/min/sec' do + #Arrange + hour = 23 + min = 0 + sec = 0 + + #Act + time = clock(hour, min, sec) + + #Assert + expect(time).must_equal '23:00:00' + + # re-Arrange + hour = 24 + + #Act-Assert (this keeps the program from crashing) + expect { + time = clock(hour, min, sec) + }.must_raise ArgumentError +end + +end From 761151b53ac67a895065e6242b09710f04d20a7f Mon Sep 17 00:00:00 2001 From: sabine Date: Tue, 14 Aug 2018 11:12:25 -0700 Subject: [PATCH 2/4] The test changed --- clock.rb | 43 +++++++++++++++++++++++++++++++------------ clock_spec.rb | 22 ++++++++++++++++++++++ 2 files changed, 53 insertions(+), 12 deletions(-) diff --git a/clock.rb b/clock.rb index d569357..165a2e5 100644 --- a/clock.rb +++ b/clock.rb @@ -1,17 +1,36 @@ # clock.rb def clock(hours, minutes, seconds) -# if hours < 10 -# hours = "0#{hours}" -if hours > 23 || hours < 0 - raise ArgumentError, 'Hours must be between 0-23' -end -if minutes < 10 - minutes = "0#{minutes}" -end -if seconds < 10 - seconds = "0#{seconds}" + inputs = [hours, min, sec] + max_inputs = [ 23, 59, 59] + 3.times do |index| + if inputs[index] > max_inputs[index] + raise ArgumentError, "#{inputs[index]} is too large" + elsif inputs[index] < 0 + raise ArgumentError, "#{inputs[index]} is too small" + elsif inputs[index] < 10 + inputs[index] = "0#{inputs[index]}" + end + end - return "#{hours}:#{minutes}:#{seconds}" + +return "#{inputs[0]}:#{inputs[1]}:#{inputs[2]}" + end - # What edge case does this cover? + +# if hours < 10 +# hours = "0#{hours}" +# if hours > 23 || hours < 0 +# raise ArgumentError, 'Hours must be between 0-23' +# end +# # if minutes < 10 +# # minutes = "0#{minutes}" +# if minutes > 59 || minutes < 0 +# raise ArgumentError, 'Minutes must be between 0-59' +# end +# if seconds < 10 +# seconds = "0#{seconds}" +# end +# return "#{hours}:#{minutes}:#{seconds}" +# end +# # What edge case does this cover? diff --git a/clock_spec.rb b/clock_spec.rb index cc3fff9..6a6aad3 100644 --- a/clock_spec.rb +++ b/clock_spec.rb @@ -72,4 +72,26 @@ }.must_raise ArgumentError end +it 'will raise an error for an invalid hour/min/sec' do + #Arrange + hour = 0 + min = 59 + sec = 0 + + #Act + time = clock(hour, min, sec) + + #Assert + expect(time).must_equal '00:59:00' + + # re-Arrange + min = 60 + + #Act-Assert (this keeps the program from crashing) + expect { + time = clock(hour, min, sec) + }.must_raise ArgumentError + +end + end From fa5e73e74f789fc42614531354478d8fcb28c4f6 Mon Sep 17 00:00:00 2001 From: sabine Date: Tue, 14 Aug 2018 11:24:25 -0700 Subject: [PATCH 3/4] Just saving again --- clock.rb => lib/clock.rb | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename clock.rb => lib/clock.rb (100%) diff --git a/clock.rb b/lib/clock.rb similarity index 100% rename from clock.rb rename to lib/clock.rb From c38324f00372a79ce32a8d4de7c49d67f4d01a2a Mon Sep 17 00:00:00 2001 From: sabine Date: Fri, 21 Sep 2018 13:58:51 -0700 Subject: [PATCH 4/4] Please post solutions to test/code --- Rakefile | 9 +++++++++ clock_spec.rb => specs/clock_spec.rb | 10 ++++++---- 2 files changed, 15 insertions(+), 4 deletions(-) create mode 100644 Rakefile rename clock_spec.rb => specs/clock_spec.rb (84%) diff --git a/Rakefile b/Rakefile new file mode 100644 index 0000000..deb52f2 --- /dev/null +++ b/Rakefile @@ -0,0 +1,9 @@ +require 'rake/testtask' + +Rake::TestTask.new do |t| + t.libs = ["lib"] + t.warning = true + t.test_files = FileList['specs/*_spec.rb'] +end + +task default: :test diff --git a/clock_spec.rb b/specs/clock_spec.rb similarity index 84% rename from clock_spec.rb rename to specs/clock_spec.rb index 6a6aad3..86a19c4 100644 --- a/clock_spec.rb +++ b/specs/clock_spec.rb @@ -4,25 +4,27 @@ # to get colors require 'minitest/autorun' require 'minitest/reporters' -require_relative 'clock' +require_relative '../lib/clock' Minitest::Reporters.use! # This is to describe my test (Each block represents one tets) -describe 'Clock' do +describe 'Clock' dov # Describe test contains several tests it 'will return a string' do # this will return a string - # Arrange the situation + # Arrange the situation (Something is up) hours = 9 minutes = 25 seconds = 46 - # Act - Perform the action we are trying to test + # Act - Perform the action we are trying to test (do the thing) time = clock(hours, minutes, seconds) # Assert what I am expecting to be true - step (no matter what is does it needs to give us string) + # Check that you have done the thing I ask you to do... expect(time).must_be_instance_of String # this is an expectation that the result will be an instanc of string +# These are assertions and matches. It needs to satisfy this test above. end it 'will return a string formatted in hh:mm:ss format when hours is a single digit' do