Skip to content

Commit

Permalink
Fix rspec depends to comments
Browse files Browse the repository at this point in the history
Signed-off-by: Vitalii Chulak <vitalii@daynix.com>
  • Loading branch information
Jedoku committed Feb 13, 2024
1 parent 8e065cd commit 9aaaf50
Showing 1 changed file with 19 additions and 11 deletions.
30 changes: 19 additions & 11 deletions spec/lib/auxiliary/test_helper_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,22 +2,30 @@

require_relative '../../../lib/auxiliary/time_helper'

RSpec.describe AutoHCK::Helper do
describe AutoHCK::Helper do
include AutoHCK::Helper

describe '#time_to_seconds' do
time_strings = {
'1:2' => 3720, # hh:mm
'1:2:3' => 3723, # hh:mm:ss
'1.2:3' => 86_400 + 7380, # dd.hh:mm
'1.2:3:4' => 86_400 + 7380 + 4, # dd.hh:mm:ss
'1:2:3.22' => 3723.22, # hh:mm:ss.ff
'1.2:3:4.22' => 86_400 + 7380 + 4.22 # dd.hh:mm:ss.ff
# Define test cases with time strings and their expected second counts,
# with explicit calculations for clarity.
time_conversion_cases = {
# Format: hh:mm
'1:2' => (1 * 60 * 60) + (2 * 60), # 1 hour and 2 minutes in seconds
# Format: hh:mm:ss
'1:2:3' => (1 * 60 * 60) + (2 * 60) + 3, # 1 hour, 2 minutes, and 3 seconds
# Format: dd.hh:mm
'1.2:3' => (1 * 86_400) + (2 * 60 * 60) + (3 * 60), # 1 day, 2 hours, and 3 minutes
# Format: dd.hh:mm:ss
'1.2:3:4' => (1 * 86_400) + (2 * 60 * 60) + (3 * 60) + 4, # 1 day, 2 hours, 3 minutes, and 4 seconds
# Format: hh:mm:ss.ff
'1:2:3.22' => (1 * 60 * 60) + (2 * 60) + 3.22, # 1 hour, 2 minutes, and 3.22 seconds
# Format: dd.hh:mm:ss.ff
'1.2:3:4.22' => (1 * 86_400) + (2 * 60 * 60) + (3 * 60) + 4.22 # 1 day, 2 hours, 3 minutes, and 4.22 seconds
}

time_strings.each do |time, expected|
it "correctly converts '#{time}' to #{expected} seconds" do
expect(time_to_seconds(time)).to eq(expected)
time_conversion_cases.each do |time_string, seconds|
it "correctly converts '#{time_string}' to #{seconds} seconds" do
expect(time_to_seconds(time_string)).to eq(seconds)
end
end
end
Expand Down

0 comments on commit 9aaaf50

Please sign in to comment.