-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: Vitalii Chulak <[email protected]>
- Loading branch information
1 parent
e2b0a2b
commit 69f3431
Showing
2 changed files
with
43 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
# frozen_string_literal: true | ||
|
||
require_relative '../../../lib/auxiliary/time_helper' | ||
|
||
describe AutoHCK::Helper do | ||
include AutoHCK::Helper | ||
|
||
describe '#time_to_seconds' do | ||
# 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_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 | ||
end |