calcpace 1.3.0 → 1.5.0
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 -52
- data/lib/calcpace/checker.rb +12 -12
- data/lib/calcpace/converter.rb +86 -64
- data/lib/calcpace.rb +14 -18
- data/test/calcpace/test_calculator.rb +118 -83
- data/test/calcpace/test_checker.rb +21 -21
- data/test/calcpace/test_converter.rb +75 -59
- metadata +8 -8
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 68fc31f44ee7ddb620bc3648c7e58b6d96513433a0e76f5d29ee69fb00eb43a7
|
4
|
+
data.tar.gz: e6a583a06e8ff84ab5e519efc62a234248cc098713ade0656b3331070754f11b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 7f1fab83a5c2a44992a0273451a3fa7815f47d6d0022377b5ccdec095f3f8c00c90f7a20f91630eefdd9b3f086811f69a0e3dd67c822967f24db7507f707855d
|
7
|
+
data.tar.gz: 2e598a0d206c7f0d68b5c1eedcd8ce419b2ea8dc0c2bcb348d845ce2146c582121e9931bd0eb2d196985cfd0cfa57cf7e91241eb28d17074efb57a59e9ea4f85
|
data/lib/calcpace/calculator.rb
CHANGED
@@ -1,52 +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 time
|
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
|
-
|
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
@@ -1,12 +1,12 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
# Module to check if the input is valid
|
4
|
-
module Checker
|
5
|
-
def check_positive(number)
|
6
|
-
raise 'It must be a
|
7
|
-
end
|
8
|
-
|
9
|
-
def check_time(time_string)
|
10
|
-
raise 'It must be a XX:XX:XX
|
11
|
-
end
|
12
|
-
end
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
# Module to check if the input is valid or of the correct type
|
4
|
+
module Checker
|
5
|
+
def check_positive(number)
|
6
|
+
raise ArgumentError, 'It must be a positive number' unless number.is_a?(Numeric) && number.positive?
|
7
|
+
end
|
8
|
+
|
9
|
+
def check_time(time_string)
|
10
|
+
raise ArgumentError, 'It must be a valid time in the format XX:XX:XX' unless time_string =~ /^\d{1,2}:\d{2}:\d{2}$/
|
11
|
+
end
|
12
|
+
end
|
data/lib/calcpace/converter.rb
CHANGED
@@ -1,64 +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
|
-
end
|
52
|
-
|
53
|
-
def
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
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,18 +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, time, distance and velocity
|
8
|
-
class Calcpace
|
9
|
-
include Calculator
|
10
|
-
include Checker
|
11
|
-
include Converter
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
def initialize(bigdecimal = false)
|
16
|
-
@bigdecimal = bigdecimal
|
17
|
-
end
|
18
|
-
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,83 +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
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
assert_equal
|
15
|
-
assert_equal
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
assert_raises(
|
22
|
-
assert_raises(
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
assert_raises(
|
34
|
-
assert_raises(
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
end
|
45
|
-
|
46
|
-
def
|
47
|
-
assert_raises(
|
48
|
-
assert_raises(
|
49
|
-
assert_raises(
|
50
|
-
assert_raises(
|
51
|
-
assert_equal
|
52
|
-
assert_equal
|
53
|
-
end
|
54
|
-
|
55
|
-
def
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
assert_raises(
|
74
|
-
assert_raises(
|
75
|
-
|
76
|
-
assert_equal
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
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,59 +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
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
assert_equal
|
22
|
-
assert_equal 1.
|
23
|
-
assert_equal
|
24
|
-
assert_equal 0.
|
25
|
-
assert_equal
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
assert_equal
|
30
|
-
assert_equal
|
31
|
-
assert_equal
|
32
|
-
assert_equal 0.
|
33
|
-
assert_equal
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
assert_equal
|
39
|
-
assert_equal 0.
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
assert_equal
|
44
|
-
assert_equal 0.
|
45
|
-
assert_equal
|
46
|
-
assert_equal
|
47
|
-
assert_equal
|
48
|
-
end
|
49
|
-
|
50
|
-
def
|
51
|
-
assert_equal 0.
|
52
|
-
assert_equal
|
53
|
-
assert_equal 1.
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
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.0
|
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: 2024-
|
11
|
+
date: 2024-10-26 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: minitest
|
@@ -80,9 +80,9 @@ dependencies:
|
|
80
80
|
- - "~>"
|
81
81
|
- !ruby/object:Gem::Version
|
82
82
|
version: '1.66'
|
83
|
-
description:
|
84
|
-
|
85
|
-
|
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: []
|
@@ -115,11 +115,11 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
115
115
|
- !ruby/object:Gem::Version
|
116
116
|
version: '0'
|
117
117
|
requirements: []
|
118
|
-
rubygems_version: 3.
|
118
|
+
rubygems_version: 3.4.6
|
119
119
|
signing_key:
|
120
120
|
specification_version: 4
|
121
|
-
summary: 'Calcpace: calculate total, distance,
|
122
|
-
|
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
|