calcpace 1.4.0 → 1.5.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/calcpace/calculator.rb +68 -71
- data/lib/calcpace/checker.rb +5 -2
- data/lib/calcpace/converter.rb +86 -58
- data/lib/calcpace.rb +14 -16
- data/test/calcpace/test_calculator.rb +118 -118
- data/test/calcpace/test_checker.rb +21 -21
- data/test/calcpace/test_converter.rb +75 -67
- metadata +13 -13
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ae4cf16a59e2220323b0ad4b7439b7abdd7484e994db1aae7f61970843b20cd6
|
4
|
+
data.tar.gz: c9158b0f6bddd20ae5569d7341cc2fe2521e11664795b39c685f1a600b1f9401
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c895388ab6788533432c5f556c4bad4db174079538b6e9b0f81ce27fe2c5266f96c0c364fbfc0335effa9e4ea86989df81eccc5d219ac786b472901b28ea8a9a
|
7
|
+
data.tar.gz: bc709904b89da4b81aba7253c27c0caec29e1d54faad929b8ab82b020d3b6e2d3b1c9394be67c62b74cc569d950df61af83961483e4f009e049595074e807b17
|
data/lib/calcpace/calculator.rb
CHANGED
@@ -1,71 +1,68 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
end
|
18
|
-
|
19
|
-
def
|
20
|
-
|
21
|
-
|
22
|
-
end
|
23
|
-
|
24
|
-
def
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
velocity
|
45
|
-
end
|
46
|
-
|
47
|
-
def
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
end
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
end
|
63
|
-
|
64
|
-
def
|
65
|
-
check_time(time)
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
distance(time_seconds, velocity_seconds)
|
70
|
-
end
|
71
|
-
end
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
# Module to calculate time, distance, pace and velocity
|
4
|
+
module Calculator
|
5
|
+
def velocity(time, distance)
|
6
|
+
validate_positive(time, distance)
|
7
|
+
distance.to_f / time
|
8
|
+
end
|
9
|
+
|
10
|
+
def checked_velocity(time, distance)
|
11
|
+
seconds = convert_to_seconds(validate_time(time))
|
12
|
+
velocity(seconds, distance)
|
13
|
+
end
|
14
|
+
|
15
|
+
def clock_velocity(time, distance)
|
16
|
+
convert_to_clocktime(checked_velocity(time, distance))
|
17
|
+
end
|
18
|
+
|
19
|
+
def pace(time, distance)
|
20
|
+
validate_positive(time, distance)
|
21
|
+
time.to_f / distance
|
22
|
+
end
|
23
|
+
|
24
|
+
def checked_pace(time, distance)
|
25
|
+
seconds = convert_to_seconds(validate_time(time))
|
26
|
+
pace(seconds, distance)
|
27
|
+
end
|
28
|
+
|
29
|
+
def clock_pace(time, distance)
|
30
|
+
convert_to_clocktime(checked_pace(time, distance))
|
31
|
+
end
|
32
|
+
|
33
|
+
def time(velocity, distance)
|
34
|
+
validate_positive(velocity, distance)
|
35
|
+
velocity * distance
|
36
|
+
end
|
37
|
+
|
38
|
+
def checked_time(velocity, distance)
|
39
|
+
velocity_seconds = convert_to_seconds(validate_time(velocity))
|
40
|
+
time(velocity_seconds, distance)
|
41
|
+
end
|
42
|
+
|
43
|
+
def clock_time(velocity, distance)
|
44
|
+
convert_to_clocktime(checked_time(velocity, distance))
|
45
|
+
end
|
46
|
+
|
47
|
+
def distance(time, velocity)
|
48
|
+
validate_positive(time, velocity)
|
49
|
+
time.to_f / velocity
|
50
|
+
end
|
51
|
+
|
52
|
+
def checked_distance(time, velocity)
|
53
|
+
time_seconds = convert_to_seconds(validate_time(time))
|
54
|
+
velocity_seconds = convert_to_seconds(validate_time(velocity))
|
55
|
+
distance(time_seconds, velocity_seconds)
|
56
|
+
end
|
57
|
+
|
58
|
+
private
|
59
|
+
|
60
|
+
def validate_positive(*values)
|
61
|
+
values.each { |value| check_positive(value) }
|
62
|
+
end
|
63
|
+
|
64
|
+
def validate_time(time)
|
65
|
+
check_time(time)
|
66
|
+
time
|
67
|
+
end
|
68
|
+
end
|
data/lib/calcpace/checker.rb
CHANGED
@@ -3,10 +3,13 @@
|
|
3
3
|
# Module to check if the input is valid or of the correct type
|
4
4
|
module Checker
|
5
5
|
def check_positive(number)
|
6
|
-
raise 'It must be a
|
6
|
+
raise ArgumentError, 'It must be a positive number' unless number.is_a?(Numeric) && number.positive?
|
7
7
|
end
|
8
8
|
|
9
9
|
def check_time(time_string)
|
10
|
-
|
10
|
+
return if time_string =~ /\A\d{1,2}:\d{2}:\d{2}\z/
|
11
|
+
|
12
|
+
raise ArgumentError,
|
13
|
+
'It must be a valid time in the format XX:XX:XX'
|
11
14
|
end
|
12
15
|
end
|
data/lib/calcpace/converter.rb
CHANGED
@@ -1,58 +1,86 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
end
|
58
|
-
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
# Module to convert units
|
4
|
+
module Converter
|
5
|
+
module Distance
|
6
|
+
KM_TO_MI = 0.621371
|
7
|
+
MI_TO_KM = 1.60934
|
8
|
+
NAUTICAL_MI_TO_KM = 1.852
|
9
|
+
KM_TO_NAUTICAL_MI = 0.539957
|
10
|
+
METERS_TO_KM = 0.001
|
11
|
+
KM_TO_METERS = 1000
|
12
|
+
METERS_TO_MI = 0.000621371
|
13
|
+
MI_TO_METERS = 1609.34
|
14
|
+
METERS_TO_FEET = 3.28084
|
15
|
+
FEET_TO_METERS = 0.3048
|
16
|
+
METERS_TO_YARDS = 1.09361
|
17
|
+
YARDS_TO_METERS = 0.9144
|
18
|
+
METERS_TO_INCHES = 39.3701
|
19
|
+
INCHES_TO_METERS = 0.0254
|
20
|
+
KM_TO_YARDS = 1093.61
|
21
|
+
YARDS_TO_KM = 0.0009144
|
22
|
+
KM_TO_FEET = 3280.84
|
23
|
+
FEET_TO_KM = 0.0003048
|
24
|
+
KM_TO_INCHES = 39_370.1
|
25
|
+
INCHES_TO_KM = 0.0000254
|
26
|
+
MI_TO_YARDS = 1760
|
27
|
+
YARDS_TO_MI = 0.000568182
|
28
|
+
MI_TO_FEET = 5280
|
29
|
+
FEET_TO_MI = 0.000189394
|
30
|
+
MI_TO_INCHES = 63_360
|
31
|
+
INCHES_TO_MI = 0.0000157828
|
32
|
+
end
|
33
|
+
|
34
|
+
module Speed
|
35
|
+
M_S_TO_KM_H = 3.6
|
36
|
+
KM_H_TO_M_S = 0.277778
|
37
|
+
M_S_TO_MI_H = 2.23694
|
38
|
+
MI_H_TO_M_S = 0.44704
|
39
|
+
M_S_TO_NAUTICAL_MI_H = 1.94384
|
40
|
+
NAUTICAL_MI_H_TO_M_S = 0.514444
|
41
|
+
M_S_TO_FEET_S = 3.28084
|
42
|
+
FEET_S_TO_M_S = 0.3048
|
43
|
+
M_S_TO_KNOTS = 1.94384
|
44
|
+
KNOTS_TO_M_S = 0.514444
|
45
|
+
KM_H_TO_MI_H = 0.621371
|
46
|
+
MI_H_TO_KM_H = 1.60934
|
47
|
+
KM_H_TO_NAUTICAL_MI_H = 0.539957
|
48
|
+
NAUTICAL_MI_H_TO_KM_H = 1.852
|
49
|
+
MI_H_TO_NAUTICAL_MI_H = 0.868976
|
50
|
+
NAUTICAL_MI_H_TO_MI_H = 1.15078
|
51
|
+
end
|
52
|
+
|
53
|
+
def convert(value, unit)
|
54
|
+
check_positive(value)
|
55
|
+
unit_constant = constant(unit)
|
56
|
+
value * unit_constant
|
57
|
+
end
|
58
|
+
|
59
|
+
def convert_to_seconds(time)
|
60
|
+
hour, minute, seconds = time.split(':').map(&:to_i)
|
61
|
+
(hour * 3600) + (minute * 60) + seconds
|
62
|
+
end
|
63
|
+
|
64
|
+
def convert_to_clocktime(seconds)
|
65
|
+
format = seconds >= 86_400 ? '%d %H:%M:%S' : '%H:%M:%S'
|
66
|
+
Time.at(seconds.to_i).utc.strftime(format)
|
67
|
+
end
|
68
|
+
|
69
|
+
def constant(symbol)
|
70
|
+
Distance.const_get(symbol.to_s.upcase)
|
71
|
+
rescue NameError
|
72
|
+
Speed.const_get(symbol.to_s.upcase)
|
73
|
+
end
|
74
|
+
|
75
|
+
def list_all
|
76
|
+
(Distance.constants + Speed.constants).map { |c| c.downcase.to_sym }
|
77
|
+
end
|
78
|
+
|
79
|
+
def list_speed
|
80
|
+
Speed.constants.map { |c| c.downcase.to_sym }
|
81
|
+
end
|
82
|
+
|
83
|
+
def list_distance
|
84
|
+
Distance.constants.map { |c| c.downcase.to_sym }
|
85
|
+
end
|
86
|
+
end
|
data/lib/calcpace.rb
CHANGED
@@ -1,16 +1,14 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require_relative 'calcpace/calculator'
|
4
|
-
require_relative 'calcpace/checker'
|
5
|
-
require_relative 'calcpace/converter'
|
6
|
-
|
7
|
-
# Main class to calculate velocity, pace, time, distance and velocity
|
8
|
-
class Calcpace
|
9
|
-
include Calculator
|
10
|
-
include Checker
|
11
|
-
include Converter
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
def initialize; end
|
16
|
-
end
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative 'calcpace/calculator'
|
4
|
+
require_relative 'calcpace/checker'
|
5
|
+
require_relative 'calcpace/converter'
|
6
|
+
|
7
|
+
# Main class to calculate velocity, pace, time, distance and velocity
|
8
|
+
class Calcpace
|
9
|
+
include Calculator
|
10
|
+
include Checker
|
11
|
+
include Converter
|
12
|
+
|
13
|
+
def initialize; end
|
14
|
+
end
|
@@ -1,118 +1,118 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require 'minitest/autorun'
|
4
|
-
require 'bigdecimal'
|
5
|
-
require_relative '../../lib/calcpace'
|
6
|
-
|
7
|
-
class TestCalculator < Minitest::Test
|
8
|
-
def setup
|
9
|
-
@checker = Calcpace.new
|
10
|
-
end
|
11
|
-
|
12
|
-
def test_velocity
|
13
|
-
assert_equal 3.333, @checker.velocity(3600, 12_000).round(3)
|
14
|
-
assert_equal 12.3, @checker.velocity(5841, 71_844.3)
|
15
|
-
assert_equal 3.6, @checker.velocity(10_000, 36_000.0)
|
16
|
-
assert_raises(
|
17
|
-
assert_raises(
|
18
|
-
end
|
19
|
-
|
20
|
-
def test_checked_velocity
|
21
|
-
assert_raises(
|
22
|
-
assert_raises(
|
23
|
-
assert_raises(
|
24
|
-
assert_raises(
|
25
|
-
assert_equal 2.778, @checker.checked_velocity('01:00:00', 10_000).round(3)
|
26
|
-
assert_equal 10, @checker.checked_velocity('00:00:01', 10)
|
27
|
-
assert_equal 12.3, @checker.checked_velocity('01:37:21', 71_844.3)
|
28
|
-
end
|
29
|
-
|
30
|
-
def test_clock_velocity
|
31
|
-
assert_raises(
|
32
|
-
assert_raises(
|
33
|
-
assert_raises(
|
34
|
-
assert_raises(
|
35
|
-
assert_equal '00:00:02', @checker.clock_velocity('01:00:00', 10_000)
|
36
|
-
assert_equal '00:00:12', @checker.clock_velocity('01:37:21', 71_844.3)
|
37
|
-
end
|
38
|
-
|
39
|
-
def test_pace
|
40
|
-
assert_equal 300, @checker.pace(3600, 12)
|
41
|
-
assert_equal 122.81076923076924, @checker.pace(71_844.3, 585.0)
|
42
|
-
assert_raises(
|
43
|
-
assert_raises(
|
44
|
-
end
|
45
|
-
|
46
|
-
def test_checked_pace
|
47
|
-
assert_raises(
|
48
|
-
assert_raises(
|
49
|
-
assert_raises(
|
50
|
-
assert_raises(
|
51
|
-
assert_equal 360, @checker.checked_pace('01:00:00', 10)
|
52
|
-
assert_equal 474.8780487804878, @checker.checked_pace('01:37:21', 12.3)
|
53
|
-
end
|
54
|
-
|
55
|
-
def test_clock_pace
|
56
|
-
assert_raises(
|
57
|
-
assert_raises(
|
58
|
-
assert_raises(
|
59
|
-
assert_raises(
|
60
|
-
assert_equal '00:06:00', @checker.clock_pace('01:00:00', 10)
|
61
|
-
assert_equal '00:07:54', @checker.clock_pace('01:37:21', 12.3)
|
62
|
-
end
|
63
|
-
|
64
|
-
def test_time
|
65
|
-
assert_equal 43_200, @checker.time(3600, 12)
|
66
|
-
assert_equal 5841.0, @checker.time(12.3, 474.8780487804878)
|
67
|
-
assert_raises(
|
68
|
-
assert_raises(
|
69
|
-
end
|
70
|
-
|
71
|
-
def test_checked_time
|
72
|
-
assert_raises(
|
73
|
-
assert_raises(
|
74
|
-
assert_raises(
|
75
|
-
assert_raises(
|
76
|
-
assert_equal 3600, @checker.checked_time('00:05:00', 12)
|
77
|
-
assert_equal 71_844.3, @checker.checked_time('01:37:21', 12.3)
|
78
|
-
end
|
79
|
-
|
80
|
-
def test_clock_time
|
81
|
-
assert_raises(
|
82
|
-
assert_raises(
|
83
|
-
assert_raises(
|
84
|
-
assert_raises(
|
85
|
-
assert_equal '01:00:00', @checker.clock_time('00:05:00', 12)
|
86
|
-
end
|
87
|
-
|
88
|
-
def test_distance
|
89
|
-
assert_equal 30, @checker.distance(3600, 120)
|
90
|
-
assert_equal 12.3, @checker.distance(5841.0, 474.8780487804878)
|
91
|
-
assert_raises(
|
92
|
-
assert_raises(
|
93
|
-
end
|
94
|
-
|
95
|
-
def test_checked_distance
|
96
|
-
assert_raises(
|
97
|
-
assert_raises(
|
98
|
-
assert_equal 18.0, @checker.checked_distance('01:30:00', '00:05:00')
|
99
|
-
assert_equal 15.493, @checker.checked_distance('01:37:21', '00:06:17').round(3)
|
100
|
-
end
|
101
|
-
|
102
|
-
def test_readme_examples_one
|
103
|
-
assert_equal 3.386206896551724, @checker.velocity(3625, 12_275)
|
104
|
-
assert_equal 305.4166666666667, @checker.pace(3665, 12)
|
105
|
-
assert_equal 2520.0, @checker.time(210, 12)
|
106
|
-
assert_equal 80.5, @checker.distance(9660, 120)
|
107
|
-
end
|
108
|
-
|
109
|
-
def test_readme_examples_two
|
110
|
-
assert_equal 2.8658333333333332, @checker.checked_velocity('01:00:00', 10_317)
|
111
|
-
assert_equal '00:00:02', @checker.clock_velocity('01:00:00', 10_317)
|
112
|
-
assert_equal 489.2, @checker.checked_pace('01:21:32', 10)
|
113
|
-
assert_equal '00:08:09', @checker.clock_pace('01:21:32', 10)
|
114
|
-
assert_equal 4170.599999999999, @checker.checked_time('00:05:31', 12.6)
|
115
|
-
assert_equal '01:09:30', @checker.clock_time('00:05:31', 12.6)
|
116
|
-
assert_equal 12.640826873385013, @checker.checked_distance('01:21:32', '00:06:27')
|
117
|
-
end
|
118
|
-
end
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'minitest/autorun'
|
4
|
+
require 'bigdecimal'
|
5
|
+
require_relative '../../lib/calcpace'
|
6
|
+
|
7
|
+
class TestCalculator < Minitest::Test
|
8
|
+
def setup
|
9
|
+
@checker = Calcpace.new
|
10
|
+
end
|
11
|
+
|
12
|
+
def test_velocity
|
13
|
+
assert_equal 3.333, @checker.velocity(3600, 12_000).round(3)
|
14
|
+
assert_equal 12.3, @checker.velocity(5841, 71_844.3)
|
15
|
+
assert_equal 3.6, @checker.velocity(10_000, 36_000.0)
|
16
|
+
assert_raises(ArgumentError) { @checker.velocity(0, 10) }
|
17
|
+
assert_raises(ArgumentError) { @checker.velocity(10, -1) }
|
18
|
+
end
|
19
|
+
|
20
|
+
def test_checked_velocity
|
21
|
+
assert_raises(ArgumentError) { @checker.checked_velocity('', 10) }
|
22
|
+
assert_raises(ArgumentError) { @checker.checked_velocity('invalid', 10) }
|
23
|
+
assert_raises(ArgumentError) { @checker.checked_velocity('00:00:00', 0) }
|
24
|
+
assert_raises(ArgumentError) { @checker.checked_velocity('00:00:00', -1) }
|
25
|
+
assert_equal 2.778, @checker.checked_velocity('01:00:00', 10_000).round(3)
|
26
|
+
assert_equal 10, @checker.checked_velocity('00:00:01', 10)
|
27
|
+
assert_equal 12.3, @checker.checked_velocity('01:37:21', 71_844.3)
|
28
|
+
end
|
29
|
+
|
30
|
+
def test_clock_velocity
|
31
|
+
assert_raises(ArgumentError) { @checker.clock_velocity('', 10) }
|
32
|
+
assert_raises(ArgumentError) { @checker.clock_velocity('invalid', 10) }
|
33
|
+
assert_raises(ArgumentError) { @checker.clock_velocity('00:00:00', 0) }
|
34
|
+
assert_raises(ArgumentError) { @checker.clock_velocity('00:00:00', -1) }
|
35
|
+
assert_equal '00:00:02', @checker.clock_velocity('01:00:00', 10_000)
|
36
|
+
assert_equal '00:00:12', @checker.clock_velocity('01:37:21', 71_844.3)
|
37
|
+
end
|
38
|
+
|
39
|
+
def test_pace
|
40
|
+
assert_equal 300, @checker.pace(3600, 12)
|
41
|
+
assert_equal 122.81076923076924, @checker.pace(71_844.3, 585.0)
|
42
|
+
assert_raises(ArgumentError) { @checker.pace(0, 10) }
|
43
|
+
assert_raises(ArgumentError) { @checker.pace(10, -1) }
|
44
|
+
end
|
45
|
+
|
46
|
+
def test_checked_pace
|
47
|
+
assert_raises(ArgumentError) { @checker.checked_pace('', 10) }
|
48
|
+
assert_raises(ArgumentError) { @checker.checked_pace('invalid', 10) }
|
49
|
+
assert_raises(ArgumentError) { @checker.checked_pace('00:00:00', 0) }
|
50
|
+
assert_raises(ArgumentError) { @checker.checked_pace('00:00:00', -1) }
|
51
|
+
assert_equal 360, @checker.checked_pace('01:00:00', 10)
|
52
|
+
assert_equal 474.8780487804878, @checker.checked_pace('01:37:21', 12.3)
|
53
|
+
end
|
54
|
+
|
55
|
+
def test_clock_pace
|
56
|
+
assert_raises(ArgumentError) { @checker.clock_pace('', 10) }
|
57
|
+
assert_raises(ArgumentError) { @checker.clock_pace('invalid', 10) }
|
58
|
+
assert_raises(ArgumentError) { @checker.clock_pace('00:00:00', 0) }
|
59
|
+
assert_raises(ArgumentError) { @checker.clock_pace('00:00:00', -1) }
|
60
|
+
assert_equal '00:06:00', @checker.clock_pace('01:00:00', 10)
|
61
|
+
assert_equal '00:07:54', @checker.clock_pace('01:37:21', 12.3)
|
62
|
+
end
|
63
|
+
|
64
|
+
def test_time
|
65
|
+
assert_equal 43_200, @checker.time(3600, 12)
|
66
|
+
assert_equal 5841.0, @checker.time(12.3, 474.8780487804878)
|
67
|
+
assert_raises(ArgumentError) { @checker.time(0, 10) }
|
68
|
+
assert_raises(ArgumentError) { @checker.time(10, -1) }
|
69
|
+
end
|
70
|
+
|
71
|
+
def test_checked_time
|
72
|
+
assert_raises(ArgumentError) { @checker.checked_time('', 10) }
|
73
|
+
assert_raises(ArgumentError) { @checker.checked_time('invalid', 10) }
|
74
|
+
assert_raises(ArgumentError) { @checker.checked_time('00:00:00', 0) }
|
75
|
+
assert_raises(ArgumentError) { @checker.checked_time('00:00:00', -1) }
|
76
|
+
assert_equal 3600, @checker.checked_time('00:05:00', 12)
|
77
|
+
assert_equal 71_844.3, @checker.checked_time('01:37:21', 12.3)
|
78
|
+
end
|
79
|
+
|
80
|
+
def test_clock_time
|
81
|
+
assert_raises(ArgumentError) { @checker.clock_time('', 10) }
|
82
|
+
assert_raises(ArgumentError) { @checker.clock_time('invalid', 10) }
|
83
|
+
assert_raises(ArgumentError) { @checker.clock_time('00:00:00', 0) }
|
84
|
+
assert_raises(ArgumentError) { @checker.clock_time('00:00:00', -1) }
|
85
|
+
assert_equal '01:00:00', @checker.clock_time('00:05:00', 12)
|
86
|
+
end
|
87
|
+
|
88
|
+
def test_distance
|
89
|
+
assert_equal 30, @checker.distance(3600, 120)
|
90
|
+
assert_equal 12.3, @checker.distance(5841.0, 474.8780487804878)
|
91
|
+
assert_raises(ArgumentError) { @checker.distance(0, 10) }
|
92
|
+
assert_raises(ArgumentError) { @checker.distance(10, -1) }
|
93
|
+
end
|
94
|
+
|
95
|
+
def test_checked_distance
|
96
|
+
assert_raises(ArgumentError) { @checker.checked_distance('', '00:05:00') }
|
97
|
+
assert_raises(ArgumentError) { @checker.checked_distance('01:00:00', '') }
|
98
|
+
assert_equal 18.0, @checker.checked_distance('01:30:00', '00:05:00')
|
99
|
+
assert_equal 15.493, @checker.checked_distance('01:37:21', '00:06:17').round(3)
|
100
|
+
end
|
101
|
+
|
102
|
+
def test_readme_examples_one
|
103
|
+
assert_equal 3.386206896551724, @checker.velocity(3625, 12_275)
|
104
|
+
assert_equal 305.4166666666667, @checker.pace(3665, 12)
|
105
|
+
assert_equal 2520.0, @checker.time(210, 12)
|
106
|
+
assert_equal 80.5, @checker.distance(9660, 120)
|
107
|
+
end
|
108
|
+
|
109
|
+
def test_readme_examples_two
|
110
|
+
assert_equal 2.8658333333333332, @checker.checked_velocity('01:00:00', 10_317)
|
111
|
+
assert_equal '00:00:02', @checker.clock_velocity('01:00:00', 10_317)
|
112
|
+
assert_equal 489.2, @checker.checked_pace('01:21:32', 10)
|
113
|
+
assert_equal '00:08:09', @checker.clock_pace('01:21:32', 10)
|
114
|
+
assert_equal 4170.599999999999, @checker.checked_time('00:05:31', 12.6)
|
115
|
+
assert_equal '01:09:30', @checker.clock_time('00:05:31', 12.6)
|
116
|
+
assert_equal 12.640826873385013, @checker.checked_distance('01:21:32', '00:06:27')
|
117
|
+
end
|
118
|
+
end
|
@@ -1,21 +1,21 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require 'minitest/autorun'
|
4
|
-
require_relative '../../lib/calcpace'
|
5
|
-
|
6
|
-
class TestChecker < Minitest::Test
|
7
|
-
def setup
|
8
|
-
@checker = Calcpace.new
|
9
|
-
end
|
10
|
-
|
11
|
-
def test_check_positive
|
12
|
-
assert_raises(
|
13
|
-
assert_raises(
|
14
|
-
assert_nil @checker.check_positive(1)
|
15
|
-
end
|
16
|
-
|
17
|
-
def test_check_time
|
18
|
-
assert_raises(
|
19
|
-
assert_nil @checker.check_time('00:00:00')
|
20
|
-
end
|
21
|
-
end
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'minitest/autorun'
|
4
|
+
require_relative '../../lib/calcpace'
|
5
|
+
|
6
|
+
class TestChecker < Minitest::Test
|
7
|
+
def setup
|
8
|
+
@checker = Calcpace.new
|
9
|
+
end
|
10
|
+
|
11
|
+
def test_check_positive
|
12
|
+
assert_raises(ArgumentError) { @checker.check_positive(-1) }
|
13
|
+
assert_raises(ArgumentError) { @checker.check_positive(0) }
|
14
|
+
assert_nil @checker.check_positive(1)
|
15
|
+
end
|
16
|
+
|
17
|
+
def test_check_time
|
18
|
+
assert_raises(ArgumentError) { @checker.check_time('') }
|
19
|
+
assert_nil @checker.check_time('00:00:00')
|
20
|
+
end
|
21
|
+
end
|
@@ -1,67 +1,75 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require 'minitest/autorun'
|
4
|
-
require_relative '../../lib/calcpace'
|
5
|
-
|
6
|
-
class TestConverter < Minitest::Test
|
7
|
-
def setup
|
8
|
-
@checker = Calcpace.new
|
9
|
-
end
|
10
|
-
|
11
|
-
def test_convert_to_seconds
|
12
|
-
assert_equal 4262, @checker.convert_to_seconds('01:11:02')
|
13
|
-
end
|
14
|
-
|
15
|
-
def test_convert_to_clocktime
|
16
|
-
assert_equal '01:11:02', @checker.convert_to_clocktime(4262)
|
17
|
-
end
|
18
|
-
|
19
|
-
def test_convert_distance_one
|
20
|
-
assert_equal 0.621371, @checker.convert(1, :km_to_mi)
|
21
|
-
assert_equal 1.60934, @checker.convert(1, :mi_to_km)
|
22
|
-
assert_equal 1.852, @checker.convert(1, :nautical_mi_to_km)
|
23
|
-
assert_equal 0.539957, @checker.convert(1, :km_to_nautical_mi)
|
24
|
-
assert_equal 0.001, @checker.convert(1, :meters_to_km)
|
25
|
-
assert_equal 1000, @checker.convert(1, :km_to_meters)
|
26
|
-
end
|
27
|
-
|
28
|
-
def test_convert_distance_two
|
29
|
-
assert_equal 0.000621371, @checker.convert(1, :meters_to_mi)
|
30
|
-
assert_equal 1609.34, @checker.convert(1, :mi_to_meters)
|
31
|
-
assert_equal 3.28084, @checker.convert(1, :meters_to_feet)
|
32
|
-
assert_equal 0.3048, @checker.convert(1, :feet_to_meters)
|
33
|
-
assert_equal 1.09361, @checker.convert(1, :meters_to_yards)
|
34
|
-
end
|
35
|
-
|
36
|
-
def test_convert_distance_three
|
37
|
-
assert_equal 0.9144, @checker.convert(1, :yards_to_meters)
|
38
|
-
assert_equal 39.3701, @checker.convert(1, :meters_to_inches)
|
39
|
-
assert_equal 0.0254, @checker.convert(1, :inches_to_meters)
|
40
|
-
end
|
41
|
-
|
42
|
-
def test_convert_velocity_one
|
43
|
-
assert_equal 3.60, @checker.convert(1, :m_s_to_km_h)
|
44
|
-
assert_equal 0.277778, @checker.convert(1, :km_h_to_m_s)
|
45
|
-
assert_equal 2.23694, @checker.convert(1, :m_s_to_mi_h)
|
46
|
-
assert_equal 0.44704, @checker.convert(1, :mi_h_to_m_s)
|
47
|
-
assert_equal 1.94384, @checker.convert(1, :m_s_to_nautical_mi_h)
|
48
|
-
end
|
49
|
-
|
50
|
-
def test_convert_velocity_two
|
51
|
-
assert_equal 0.514444, @checker.convert(1, :nautical_mi_h_to_m_s)
|
52
|
-
assert_equal 0.621371, @checker.convert(1, :km_h_to_mi_h)
|
53
|
-
assert_equal 1.60934, @checker.convert(1, :mi_h_to_km_h)
|
54
|
-
assert_equal 1.94384, @checker.convert(1, :m_s_to_knots)
|
55
|
-
assert_equal 0.514444, @checker.convert(1, :knots_to_m_s)
|
56
|
-
end
|
57
|
-
|
58
|
-
def test_constant
|
59
|
-
assert_equal 0.621371, @checker.constant(:km_to_mi)
|
60
|
-
assert_equal 1.60934, @checker.constant(:mi_to_km)
|
61
|
-
assert_equal 1.852, @checker.constant(:nautical_mi_to_km)
|
62
|
-
end
|
63
|
-
|
64
|
-
def
|
65
|
-
assert_equal
|
66
|
-
end
|
67
|
-
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'minitest/autorun'
|
4
|
+
require_relative '../../lib/calcpace'
|
5
|
+
|
6
|
+
class TestConverter < Minitest::Test
|
7
|
+
def setup
|
8
|
+
@checker = Calcpace.new
|
9
|
+
end
|
10
|
+
|
11
|
+
def test_convert_to_seconds
|
12
|
+
assert_equal 4262, @checker.convert_to_seconds('01:11:02')
|
13
|
+
end
|
14
|
+
|
15
|
+
def test_convert_to_clocktime
|
16
|
+
assert_equal '01:11:02', @checker.convert_to_clocktime(4262)
|
17
|
+
end
|
18
|
+
|
19
|
+
def test_convert_distance_one
|
20
|
+
assert_equal 0.621371, @checker.convert(1, :km_to_mi)
|
21
|
+
assert_equal 1.60934, @checker.convert(1, :mi_to_km)
|
22
|
+
assert_equal 1.852, @checker.convert(1, :nautical_mi_to_km)
|
23
|
+
assert_equal 0.539957, @checker.convert(1, :km_to_nautical_mi)
|
24
|
+
assert_equal 0.001, @checker.convert(1, :meters_to_km)
|
25
|
+
assert_equal 1000, @checker.convert(1, :km_to_meters)
|
26
|
+
end
|
27
|
+
|
28
|
+
def test_convert_distance_two
|
29
|
+
assert_equal 0.000621371, @checker.convert(1, :meters_to_mi)
|
30
|
+
assert_equal 1609.34, @checker.convert(1, :mi_to_meters)
|
31
|
+
assert_equal 3.28084, @checker.convert(1, :meters_to_feet)
|
32
|
+
assert_equal 0.3048, @checker.convert(1, :feet_to_meters)
|
33
|
+
assert_equal 1.09361, @checker.convert(1, :meters_to_yards)
|
34
|
+
end
|
35
|
+
|
36
|
+
def test_convert_distance_three
|
37
|
+
assert_equal 0.9144, @checker.convert(1, :yards_to_meters)
|
38
|
+
assert_equal 39.3701, @checker.convert(1, :meters_to_inches)
|
39
|
+
assert_equal 0.0254, @checker.convert(1, :inches_to_meters)
|
40
|
+
end
|
41
|
+
|
42
|
+
def test_convert_velocity_one
|
43
|
+
assert_equal 3.60, @checker.convert(1, :m_s_to_km_h)
|
44
|
+
assert_equal 0.277778, @checker.convert(1, :km_h_to_m_s)
|
45
|
+
assert_equal 2.23694, @checker.convert(1, :m_s_to_mi_h)
|
46
|
+
assert_equal 0.44704, @checker.convert(1, :mi_h_to_m_s)
|
47
|
+
assert_equal 1.94384, @checker.convert(1, :m_s_to_nautical_mi_h)
|
48
|
+
end
|
49
|
+
|
50
|
+
def test_convert_velocity_two
|
51
|
+
assert_equal 0.514444, @checker.convert(1, :nautical_mi_h_to_m_s)
|
52
|
+
assert_equal 0.621371, @checker.convert(1, :km_h_to_mi_h)
|
53
|
+
assert_equal 1.60934, @checker.convert(1, :mi_h_to_km_h)
|
54
|
+
assert_equal 1.94384, @checker.convert(1, :m_s_to_knots)
|
55
|
+
assert_equal 0.514444, @checker.convert(1, :knots_to_m_s)
|
56
|
+
end
|
57
|
+
|
58
|
+
def test_constant
|
59
|
+
assert_equal 0.621371, @checker.constant(:km_to_mi)
|
60
|
+
assert_equal 1.60934, @checker.constant(:mi_to_km)
|
61
|
+
assert_equal 1.852, @checker.constant(:nautical_mi_to_km)
|
62
|
+
end
|
63
|
+
|
64
|
+
def test_list_all
|
65
|
+
assert_equal 42, @checker.list_all.size
|
66
|
+
end
|
67
|
+
|
68
|
+
def test_list_speed
|
69
|
+
assert_equal 16, @checker.list_speed.size
|
70
|
+
end
|
71
|
+
|
72
|
+
def test_list_distance_constants
|
73
|
+
assert_equal 26, @checker.list_distance.size
|
74
|
+
end
|
75
|
+
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: calcpace
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.5.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Joao Gilberto Saraiva
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2025-01-06 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: minitest
|
@@ -16,28 +16,28 @@ dependencies:
|
|
16
16
|
requirements:
|
17
17
|
- - "~>"
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version: '5.
|
19
|
+
version: '5.25'
|
20
20
|
type: :development
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
24
|
- - "~>"
|
25
25
|
- !ruby/object:Gem::Version
|
26
|
-
version: '5.
|
26
|
+
version: '5.25'
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: rake
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
30
30
|
requirements:
|
31
31
|
- - "~>"
|
32
32
|
- !ruby/object:Gem::Version
|
33
|
-
version: '13.
|
33
|
+
version: '13.2'
|
34
34
|
type: :development
|
35
35
|
prerelease: false
|
36
36
|
version_requirements: !ruby/object:Gem::Requirement
|
37
37
|
requirements:
|
38
38
|
- - "~>"
|
39
39
|
- !ruby/object:Gem::Version
|
40
|
-
version: '13.
|
40
|
+
version: '13.2'
|
41
41
|
- !ruby/object:Gem::Dependency
|
42
42
|
name: rake-compiler
|
43
43
|
requirement: !ruby/object:Gem::Requirement
|
@@ -72,17 +72,17 @@ dependencies:
|
|
72
72
|
requirements:
|
73
73
|
- - "~>"
|
74
74
|
- !ruby/object:Gem::Version
|
75
|
-
version: '1.
|
75
|
+
version: '1.69'
|
76
76
|
type: :development
|
77
77
|
prerelease: false
|
78
78
|
version_requirements: !ruby/object:Gem::Requirement
|
79
79
|
requirements:
|
80
80
|
- - "~>"
|
81
81
|
- !ruby/object:Gem::Version
|
82
|
-
version: '1.
|
83
|
-
description:
|
84
|
-
|
85
|
-
|
82
|
+
version: '1.69'
|
83
|
+
description: It is designed for calculations related to distance, speed and time.
|
84
|
+
The gem also supports conversion to 42 different units of distance and velocity,
|
85
|
+
including metric, nautical and imperial units.
|
86
86
|
email: joaogilberto@tuta.io
|
87
87
|
executables: []
|
88
88
|
extensions: []
|
@@ -118,8 +118,8 @@ requirements: []
|
|
118
118
|
rubygems_version: 3.4.6
|
119
119
|
signing_key:
|
120
120
|
specification_version: 4
|
121
|
-
summary: 'Calcpace: calculate total, distance,
|
122
|
-
easy way.'
|
121
|
+
summary: 'Calcpace: calculate total, distance, speed, and convert distances and velocity
|
122
|
+
in an easy way.'
|
123
123
|
test_files:
|
124
124
|
- test/calcpace/test_calculator.rb
|
125
125
|
- test/calcpace/test_checker.rb
|