calcpace 1.2.0 → 1.3.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 +52 -42
- data/lib/calcpace/checker.rb +12 -19
- data/lib/calcpace/converter.rb +64 -55
- data/lib/calcpace.rb +18 -17
- data/test/calcpace/test_calculator.rb +83 -73
- data/test/calcpace/test_checker.rb +21 -27
- data/test/calcpace/test_converter.rb +59 -58
- metadata +11 -28
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 8d2fca26e59f2126bc2c6912786ea9808f8e73af4bc2860de63c5ab85ccf4b01
|
4
|
+
data.tar.gz: 11907a7faff02d37df75a1db8d2540f114f46afe70bdb6a426ed3ed6f6bd1a81
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 451d2883e1b75c140bf5fbd85e9d1ec5b03dc770a471a173a8698ad6243b025736221ea157288c0ad23e5796287db4941f9177dfb3c7130deed50ac0bac6e126
|
7
|
+
data.tar.gz: 7141e05845a0d88fcd52fb50dfef307ab3f8c73bbc8b332108fb3dfd13d4a3294ae3ae93b1eb983b98b2134ec67407aa8ba49659e38b169eddce342381bfd8c0
|
data/lib/calcpace/calculator.rb
CHANGED
@@ -1,42 +1,52 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require 'bigdecimal'
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
end
|
10
|
-
|
11
|
-
def
|
12
|
-
check_time(time)
|
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
|
-
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'bigdecimal'
|
4
|
+
|
5
|
+
# Module to calculate time, distance and velocity
|
6
|
+
module Calculator
|
7
|
+
def velocity(time, distance)
|
8
|
+
time / distance
|
9
|
+
end
|
10
|
+
|
11
|
+
def checked_velocity(time, distance)
|
12
|
+
check_time(time)
|
13
|
+
check_positive(distance)
|
14
|
+
distance_to_calc = convert_to_bigdecimal(distance)
|
15
|
+
seconds = convert_to_bigdecimal(convert_to_seconds(time))
|
16
|
+
velocity(seconds, distance_to_calc)
|
17
|
+
end
|
18
|
+
|
19
|
+
def clock_velocity(time, distance)
|
20
|
+
velocity_in_seconds = checked_velocity(time, distance)
|
21
|
+
convert_to_clocktime(velocity_in_seconds)
|
22
|
+
end
|
23
|
+
|
24
|
+
def time(velocity, distance)
|
25
|
+
velocity * distance
|
26
|
+
end
|
27
|
+
|
28
|
+
def checked_time(velocity, distance)
|
29
|
+
check_time(velocity)
|
30
|
+
check_positive(distance)
|
31
|
+
distance_to_calc = convert_to_bigdecimal(distance)
|
32
|
+
velocity_seconds = convert_to_bigdecimal(convert_to_seconds(velocity))
|
33
|
+
time(velocity_seconds, distance_to_calc)
|
34
|
+
end
|
35
|
+
|
36
|
+
def clock_time(velocity, distance)
|
37
|
+
total_time_in_seconds = checked_time(velocity, distance)
|
38
|
+
convert_to_clocktime(total_time_in_seconds)
|
39
|
+
end
|
40
|
+
|
41
|
+
def distance(time, velocity)
|
42
|
+
time / velocity
|
43
|
+
end
|
44
|
+
|
45
|
+
def checked_distance(time, velocity)
|
46
|
+
check_time(time)
|
47
|
+
check_time(velocity)
|
48
|
+
time_seconds = convert_to_bigdecimal(convert_to_seconds(time))
|
49
|
+
velocity_seconds = convert_to_bigdecimal(convert_to_seconds(velocity))
|
50
|
+
distance(time_seconds, velocity_seconds)
|
51
|
+
end
|
52
|
+
end
|
data/lib/calcpace/checker.rb
CHANGED
@@ -1,19 +1,12 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
raise 'It must be a positive number' unless second.is_a?(Integer) && second.positive?
|
14
|
-
end
|
15
|
-
|
16
|
-
def check_unit(unit)
|
17
|
-
raise 'It must be km or mi' unless %w[km mi].include?(unit)
|
18
|
-
end
|
19
|
-
end
|
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 X.X positive number' unless number.positive?
|
7
|
+
end
|
8
|
+
|
9
|
+
def check_time(time_string)
|
10
|
+
raise 'It must be a XX:XX:XX time' unless time_string =~ /\d{0,2}(:)*?\d{1,2}(:)\d{1,2}/
|
11
|
+
end
|
12
|
+
end
|
data/lib/calcpace/converter.rb
CHANGED
@@ -1,55 +1,64 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require 'bigdecimal'
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
KM_TO_MI = 0.621371
|
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
|
-
def
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
end
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'bigdecimal'
|
4
|
+
|
5
|
+
# Module to convert units
|
6
|
+
module Converter
|
7
|
+
KM_TO_MI = 0.621371
|
8
|
+
MI_TO_KM = 1.60934
|
9
|
+
NAUTICAL_MI_TO_KM = 1.852
|
10
|
+
KM_TO_NAUTICAL_MI = 0.539957
|
11
|
+
METERS_TO_KM = 0.001
|
12
|
+
KM_TO_METERS = 1000
|
13
|
+
METERS_TO_MI = 0.000621371
|
14
|
+
MI_TO_METERS = 1609.34
|
15
|
+
METERS_TO_FEET = 3.28084
|
16
|
+
FEET_TO_METERS = 0.3048
|
17
|
+
METERS_TO_YARDS = 1.09361
|
18
|
+
YARDS_TO_METERS = 0.9144
|
19
|
+
METERS_TO_INCHES = 39.3701
|
20
|
+
INCHES_TO_METERS = 0.0254
|
21
|
+
|
22
|
+
M_S_TO_KM_H = 3.6
|
23
|
+
KM_H_TO_M_S = 0.277778
|
24
|
+
M_S_TO_MI_H = 2.23694
|
25
|
+
MI_H_TO_M_S = 0.44704
|
26
|
+
M_S_TO_NAUTICAL_MI_H = 1.94384
|
27
|
+
NAUTICAL_MI_H_TO_M_S = 0.514444
|
28
|
+
M_S_TO_FEET_S = 3.28084
|
29
|
+
FEET_S_TO_M_S = 0.3048
|
30
|
+
M_S_TO_KNOTS = 1.94384
|
31
|
+
KNOTS_TO_M_S = 0.514444
|
32
|
+
KM_H_TO_MI_H = 0.621371
|
33
|
+
MI_H_TO_KM_H = 1.60934
|
34
|
+
|
35
|
+
def convert(value, unit)
|
36
|
+
check_positive(value)
|
37
|
+
unit_constant = constant(unit)
|
38
|
+
value_to_convert = convert_to_bigdecimal(value)
|
39
|
+
unit_to_convert = convert_to_bigdecimal(unit_constant)
|
40
|
+
value_to_convert * unit_to_convert
|
41
|
+
end
|
42
|
+
|
43
|
+
def convert_to_seconds(time)
|
44
|
+
hour, minute, seconds = time.split(':').map(&:to_i)
|
45
|
+
(hour * 3600) + (minute * 60) + seconds
|
46
|
+
end
|
47
|
+
|
48
|
+
def convert_to_clocktime(seconds)
|
49
|
+
format = seconds >= 86_400 ? '%d %H:%M:%S' : '%H:%M:%S'
|
50
|
+
Time.at(seconds.to_i).utc.strftime(format)
|
51
|
+
end
|
52
|
+
|
53
|
+
def convert_to_bigdecimal(value)
|
54
|
+
bigdecimal ? BigDecimal(value.to_s) : value
|
55
|
+
end
|
56
|
+
|
57
|
+
def constant(string)
|
58
|
+
Converter.const_get(string.upcase.gsub(' ', '_'))
|
59
|
+
end
|
60
|
+
|
61
|
+
def list_constants
|
62
|
+
Converter.constants
|
63
|
+
end
|
64
|
+
end
|
data/lib/calcpace.rb
CHANGED
@@ -1,17 +1,18 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require_relative 'calcpace/calculator'
|
4
|
-
require_relative 'calcpace/checker'
|
5
|
-
require_relative 'calcpace/converter'
|
6
|
-
|
7
|
-
class
|
8
|
-
|
9
|
-
include
|
10
|
-
include
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
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, time, distance and velocity
|
8
|
+
class Calcpace
|
9
|
+
include Calculator
|
10
|
+
include Checker
|
11
|
+
include Converter
|
12
|
+
|
13
|
+
attr_reader :bigdecimal
|
14
|
+
|
15
|
+
def initialize(bigdecimal = false)
|
16
|
+
@bigdecimal = bigdecimal
|
17
|
+
end
|
18
|
+
end
|
@@ -1,73 +1,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
|
-
@checker_bigdecimal = Calcpace.new(
|
11
|
-
end
|
12
|
-
|
13
|
-
def
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
assert_equal
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
assert_raises(RuntimeError) { @checker.
|
34
|
-
assert_raises(RuntimeError) { @checker.
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
assert_equal
|
57
|
-
end
|
58
|
-
|
59
|
-
def
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
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
|
+
@checker_bigdecimal = Calcpace.new(true)
|
11
|
+
end
|
12
|
+
|
13
|
+
def test_velocity
|
14
|
+
assert_equal 300, @checker.velocity(3600, 12)
|
15
|
+
assert_equal 122.81076923076924, @checker.velocity(71_844.3, 585.0)
|
16
|
+
end
|
17
|
+
|
18
|
+
def test_checked_velocity
|
19
|
+
assert_raises(RuntimeError) { @checker.checked_velocity('', 10) }
|
20
|
+
assert_raises(RuntimeError) { @checker.checked_velocity('invalid', 10) }
|
21
|
+
assert_raises(RuntimeError) { @checker.checked_velocity('00:00:00', 0) }
|
22
|
+
assert_raises(RuntimeError) { @checker.checked_velocity('00:00:00', -1) }
|
23
|
+
assert_equal 360, @checker.checked_velocity('01:00:00', 10)
|
24
|
+
assert_equal 474.8780487804878, @checker.checked_velocity('01:37:21', 12.3)
|
25
|
+
end
|
26
|
+
|
27
|
+
def test_checked_velocity_with_bigdecimal_precision
|
28
|
+
assert_equal BigDecimal('0.474878048780487804878048780487804878049e3'),
|
29
|
+
@checker_bigdecimal.checked_velocity('01:37:21', 12.3)
|
30
|
+
end
|
31
|
+
|
32
|
+
def test_clock_velocity
|
33
|
+
assert_raises(RuntimeError) { @checker.clock_velocity('', 10) }
|
34
|
+
assert_raises(RuntimeError) { @checker.clock_velocity('invalid', 10) }
|
35
|
+
assert_raises(RuntimeError) { @checker.clock_velocity('00:00:00', 0) }
|
36
|
+
assert_raises(RuntimeError) { @checker.clock_velocity('00:00:00', -1) }
|
37
|
+
assert_equal '00:06:00', @checker.clock_velocity('01:00:00', 10)
|
38
|
+
assert_equal '00:07:54', @checker.clock_velocity('01:37:21', 12.3)
|
39
|
+
end
|
40
|
+
|
41
|
+
def test_time
|
42
|
+
assert_equal 43_200, @checker.time(3600, 12)
|
43
|
+
assert_equal 5841.0, @checker.time(12.3, 474.8780487804878)
|
44
|
+
end
|
45
|
+
|
46
|
+
def test_checked_time
|
47
|
+
assert_raises(RuntimeError) { @checker.checked_time('', 10) }
|
48
|
+
assert_raises(RuntimeError) { @checker.checked_time('invalid', 10) }
|
49
|
+
assert_raises(RuntimeError) { @checker.checked_time('00:00:00', 0) }
|
50
|
+
assert_raises(RuntimeError) { @checker.checked_time('00:00:00', -1) }
|
51
|
+
assert_equal 3600, @checker.checked_time('00:05:00', 12)
|
52
|
+
assert_equal 71_844.3, @checker.checked_time('01:37:21', 12.3)
|
53
|
+
end
|
54
|
+
|
55
|
+
def test_checked_time_with_bigdecimal_precision
|
56
|
+
assert_equal BigDecimal('0.718443e5'), @checker_bigdecimal.checked_time('01:37:21', 12.3)
|
57
|
+
end
|
58
|
+
|
59
|
+
def test_clock_time
|
60
|
+
assert_raises(RuntimeError) { @checker.clock_time('', 10) }
|
61
|
+
assert_raises(RuntimeError) { @checker.clock_time('invalid', 10) }
|
62
|
+
assert_raises(RuntimeError) { @checker.clock_time('00:00:00', 0) }
|
63
|
+
assert_raises(RuntimeError) { @checker.clock_time('00:00:00', -1) }
|
64
|
+
assert_equal '01:00:00', @checker.clock_time('00:05:00', 12)
|
65
|
+
end
|
66
|
+
|
67
|
+
def test_distance
|
68
|
+
assert_equal 30, @checker.distance(3600, 120)
|
69
|
+
assert_equal 12.3, @checker.distance(5841.0, 474.8780487804878)
|
70
|
+
end
|
71
|
+
|
72
|
+
def test_checked_distance
|
73
|
+
assert_raises(RuntimeError) { @checker.checked_distance('', '00:05:00') }
|
74
|
+
assert_raises(RuntimeError) { @checker.checked_distance('01:00:00', '') }
|
75
|
+
assert_equal 18.0, @checker.checked_distance('01:30:00', '00:05:00')
|
76
|
+
assert_equal 15.0, @checker.checked_distance('01:37:21', '00:06:17')
|
77
|
+
end
|
78
|
+
|
79
|
+
def test_checked_distance_with_bigdecimal_precision
|
80
|
+
assert_equal BigDecimal('0.15493368700265251989389920424403183024e2'),
|
81
|
+
@checker_bigdecimal.checked_distance('01:37:21', '00:06:17')
|
82
|
+
end
|
83
|
+
end
|
@@ -1,27 +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
|
12
|
-
assert_raises(RuntimeError) { @checker.
|
13
|
-
assert_raises(RuntimeError) { @checker.
|
14
|
-
assert_nil @checker.
|
15
|
-
end
|
16
|
-
|
17
|
-
def test_check_time
|
18
|
-
assert_raises(RuntimeError) { @checker.check_time('') }
|
19
|
-
assert_nil @checker.check_time('00:00:00')
|
20
|
-
end
|
21
|
-
|
22
|
-
def test_check_integer
|
23
|
-
assert_raises(RuntimeError) { @checker.check_integer(-1) }
|
24
|
-
assert_raises(RuntimeError) { @checker.check_integer(0) }
|
25
|
-
assert_nil @checker.check_integer(1)
|
26
|
-
end
|
27
|
-
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(RuntimeError) { @checker.check_positive(-1) }
|
13
|
+
assert_raises(RuntimeError) { @checker.check_positive(0) }
|
14
|
+
assert_nil @checker.check_positive(1)
|
15
|
+
end
|
16
|
+
|
17
|
+
def test_check_time
|
18
|
+
assert_raises(RuntimeError) { @checker.check_time('') }
|
19
|
+
assert_nil @checker.check_time('00:00:00')
|
20
|
+
end
|
21
|
+
end
|
@@ -1,58 +1,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
|
-
@checker_bigdecimal = Calcpace.new(
|
10
|
-
end
|
11
|
-
|
12
|
-
def test_convert_to_seconds
|
13
|
-
assert_equal 4262, @checker.convert_to_seconds('01:11:02')
|
14
|
-
end
|
15
|
-
|
16
|
-
def
|
17
|
-
assert_equal
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
assert_equal
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
assert_equal
|
27
|
-
assert_equal
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
assert_equal
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
assert_equal
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
assert_equal
|
46
|
-
assert_equal
|
47
|
-
assert_equal
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
assert_equal
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
end
|
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
|
+
@checker_bigdecimal = Calcpace.new(true)
|
10
|
+
end
|
11
|
+
|
12
|
+
def test_convert_to_seconds
|
13
|
+
assert_equal 4262, @checker.convert_to_seconds('01:11:02')
|
14
|
+
end
|
15
|
+
|
16
|
+
def test_convert_to_clocktime
|
17
|
+
assert_equal '01:11:02', @checker.convert_to_clocktime(4262)
|
18
|
+
end
|
19
|
+
|
20
|
+
def test_convert_distance
|
21
|
+
assert_equal 0.621371, @checker.convert(1, 'KM_TO_MI')
|
22
|
+
assert_equal 1.60934, @checker.convert(1, 'MI_TO_KM')
|
23
|
+
assert_equal 1.852, @checker.convert(1, 'NAUTICAL_MI_TO_KM')
|
24
|
+
assert_equal 0.539957, @checker.convert(1, 'KM_TO_NAUTICAL_MI')
|
25
|
+
assert_equal 0.001, @checker.convert(1, 'METERS_TO_KM')
|
26
|
+
assert_equal 1000, @checker.convert(1, 'KM_TO_METERS')
|
27
|
+
assert_equal 0.000621371, @checker.convert(1, 'METERS_TO_MI')
|
28
|
+
assert_equal 1609.34, @checker.convert(1, 'MI_TO_METERS')
|
29
|
+
assert_equal 3.28084, @checker.convert(1, 'METERS_TO_FEET')
|
30
|
+
assert_equal 0.3048, @checker.convert(1, 'FEET_TO_METERS')
|
31
|
+
assert_equal 1.09361, @checker.convert(1, 'METERS_TO_YARDS')
|
32
|
+
assert_equal 0.9144, @checker.convert(1, 'YARDS_TO_METERS')
|
33
|
+
assert_equal 39.3701, @checker.convert(1, 'METERS_TO_INCHES')
|
34
|
+
assert_equal 0.0254, @checker.convert(1, 'INCHES_TO_METERS')
|
35
|
+
end
|
36
|
+
|
37
|
+
def test_convert_velocity
|
38
|
+
assert_equal 3.60, @checker.convert(1, 'M_S_TO_KM_H')
|
39
|
+
assert_equal 0.277778, @checker.convert(1, 'KM_H_TO_M_S')
|
40
|
+
assert_equal 2.23694, @checker.convert(1, 'M_S_TO_MI_H')
|
41
|
+
assert_equal 0.44704, @checker.convert(1, 'MI_H_TO_M_S')
|
42
|
+
assert_equal 1.94384, @checker.convert(1, 'M_S_TO_NAUTICAL_MI_H')
|
43
|
+
assert_equal 0.514444, @checker.convert(1, 'NAUTICAL_MI_H_TO_M_S')
|
44
|
+
assert_equal 0.621371, @checker.convert(1, 'KM_H_TO_MI_H')
|
45
|
+
assert_equal 1.60934, @checker.convert(1, 'MI_H_TO_KM_H')
|
46
|
+
assert_equal 1.94384, @checker.convert(1, 'M_S_TO_KNOTS')
|
47
|
+
assert_equal 0.514444, @checker.convert(1, 'KNOTS_TO_M_S')
|
48
|
+
end
|
49
|
+
|
50
|
+
def test_constant
|
51
|
+
assert_equal 0.621371, @checker.constant('KM_TO_MI')
|
52
|
+
assert_equal 1.60934, @checker.constant('MI_TO_KM')
|
53
|
+
assert_equal 1.852, @checker.constant('NAUTICAL_MI_TO_KM')
|
54
|
+
end
|
55
|
+
|
56
|
+
def test_list_constants
|
57
|
+
assert_equal 26, @checker.list_constants.size
|
58
|
+
end
|
59
|
+
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.3.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Joao Gilberto Saraiva
|
8
|
-
autorequire:
|
8
|
+
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2024-08
|
11
|
+
date: 2024-09-08 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: minitest
|
@@ -72,34 +72,17 @@ dependencies:
|
|
72
72
|
requirements:
|
73
73
|
- - "~>"
|
74
74
|
- !ruby/object:Gem::Version
|
75
|
-
version: '
|
75
|
+
version: '1.66'
|
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: '
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
requirements:
|
87
|
-
- - "~>"
|
88
|
-
- !ruby/object:Gem::Version
|
89
|
-
version: '0.11'
|
90
|
-
type: :development
|
91
|
-
prerelease: false
|
92
|
-
version_requirements: !ruby/object:Gem::Requirement
|
93
|
-
requirements:
|
94
|
-
- - "~>"
|
95
|
-
- !ruby/object:Gem::Version
|
96
|
-
version: '0.11'
|
97
|
-
description: Calcpace is a Ruby gem that helps with calculations related to running/cycling
|
98
|
-
activities or general purposes involving distance and time. It can calculate pace,
|
99
|
-
total time, and distance. It also converts distances between miles and kilometers
|
100
|
-
and check formats of time and distance. The results are provided in a readable format,
|
101
|
-
with times in HH:MM:SS or seconds and distances in X.X format. If you need, the
|
102
|
-
gem supports BigDecimal to handle the calculations with more precision.
|
82
|
+
version: '1.66'
|
83
|
+
description: Calcpace is a Ruby gem that helps with calculations related to distance
|
84
|
+
and time. It can calculate velocity, total time, and distance. It also converts
|
85
|
+
distance and velocity, check formats of time and can handle calculus with BigDecimal.
|
103
86
|
email: joaogilberto@tuta.io
|
104
87
|
executables: []
|
105
88
|
extensions: []
|
@@ -133,10 +116,10 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
133
116
|
version: '0'
|
134
117
|
requirements: []
|
135
118
|
rubygems_version: 3.5.16
|
136
|
-
signing_key:
|
119
|
+
signing_key:
|
137
120
|
specification_version: 4
|
138
|
-
summary: 'Calcpace: calculate
|
139
|
-
|
121
|
+
summary: 'Calcpace: calculate total, distance, velocity and convert distances in an
|
122
|
+
easy and precise way.'
|
140
123
|
test_files:
|
141
124
|
- test/calcpace/test_calculator.rb
|
142
125
|
- test/calcpace/test_checker.rb
|