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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 3f95d90f68ffe230e0f84e3d16b4221de5ffe61004e76ad2f2d2a18260ad9c30
4
- data.tar.gz: fe206da9ac7d89e6df053fa0b6c6aff02227d06da7e81f48e6955cba183a720d
3
+ metadata.gz: 8d2fca26e59f2126bc2c6912786ea9808f8e73af4bc2860de63c5ab85ccf4b01
4
+ data.tar.gz: 11907a7faff02d37df75a1db8d2540f114f46afe70bdb6a426ed3ed6f6bd1a81
5
5
  SHA512:
6
- metadata.gz: 8e93948a4751a908473f92cf526c09b6c8dc084978cb9c99a3e2a1977bd2ae7da7a14548631c689da95a0e10dcc361a512d1967f610f60cf38297e51fb7cdad6
7
- data.tar.gz: bbf563ced661d193b79d5c90dd77ce63262488ceaf42fba06033b0154cebb0139a2f63f1749d1ed400985e854b1d716e54872a5a7b83756fabd2be16e081f7c8
6
+ metadata.gz: 451d2883e1b75c140bf5fbd85e9d1ec5b03dc770a471a173a8698ad6243b025736221ea157288c0ad23e5796287db4941f9177dfb3c7130deed50ac0bac6e126
7
+ data.tar.gz: 7141e05845a0d88fcd52fb50dfef307ab3f8c73bbc8b332108fb3dfd13d4a3294ae3ae93b1eb983b98b2134ec67407aa8ba49659e38b169eddce342381bfd8c0
@@ -1,42 +1,52 @@
1
- # frozen_string_literal: true
2
-
3
- require 'bigdecimal'
4
-
5
- module Calculator
6
- def pace(time, distance)
7
- pace_in_seconds = pace_seconds(time, distance)
8
- convert_to_clocktime(pace_in_seconds)
9
- end
10
-
11
- def pace_seconds(time, distance)
12
- check_time(time)
13
- check_distance(distance)
14
- seconds = convert_to_seconds(time)
15
- bigdecimal ? seconds / BigDecimal(distance.to_s) : seconds / distance
16
- end
17
-
18
- def total_time(pace, distance)
19
- total_time_in_seconds = total_time_seconds(pace, distance)
20
- convert_to_clocktime(total_time_in_seconds)
21
- end
22
-
23
- def total_time_seconds(pace, distance)
24
- check_time(pace)
25
- check_distance(distance)
26
- pace_seconds = convert_to_seconds(pace)
27
- @bigdecimal ? pace_seconds * BigDecimal(distance.to_s) : pace_seconds * distance
28
- end
29
-
30
- def distance(time, pace)
31
- check_time(time)
32
- check_time(pace)
33
- if bigdecimal
34
- time_seconds = BigDecimal(convert_to_seconds(time).to_s)
35
- pace_seconds = BigDecimal(convert_to_seconds(pace).to_s)
36
- else
37
- time_seconds = convert_to_seconds(time)
38
- pace_seconds = convert_to_seconds(pace)
39
- end
40
- time_seconds / pace_seconds
41
- end
42
- end
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
@@ -1,19 +1,12 @@
1
- # frozen_string_literal: true
2
-
3
- module Checker
4
- def check_distance(distance)
5
- raise 'It must be a X.X positive number' unless distance.positive?
6
- end
7
-
8
- def check_time(time_string)
9
- raise 'It must be a XX:XX:XX time' unless time_string =~ /\d{0,2}(:)*?\d{1,2}(:)\d{1,2}/
10
- end
11
-
12
- def check_integer(second)
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
@@ -1,55 +1,64 @@
1
- # frozen_string_literal: true
2
-
3
- require 'bigdecimal'
4
-
5
- module Converter
6
- KM_TO_MI_BIGDECIMAL = BigDecimal('0.621371')
7
- KM_TO_MI = 0.621371
8
- MI_TO_KM_BIGDECIMAL = BigDecimal('1.60934')
9
- MI_TO_KM = 1.60934
10
-
11
- def to_seconds(time)
12
- check_time(time)
13
- convert_to_seconds(time)
14
- end
15
-
16
- def to_clocktime(seconds)
17
- check_integer(seconds)
18
- convert_to_clocktime(seconds)
19
- end
20
-
21
- def convert_to_miles(distance)
22
- convert(distance, 'mi')
23
- end
24
-
25
- def convert_to_km(distance)
26
- convert(distance, 'km')
27
- end
28
-
29
- def convert(distance, unit)
30
- check_distance(distance)
31
- bigdecimal ? distance_to_convert = BigDecimal(distance.to_s) : distance_to_convert = distance
32
- convert_the_distance(distance_to_convert, unit)
33
- end
34
-
35
- def convert_to_seconds(time)
36
- hour, minute, seconds = time.split(':').map(&:to_i)
37
- (hour * 3600) + (minute * 60) + seconds
38
- end
39
-
40
- def convert_to_clocktime(seconds)
41
- format = seconds >= 86_400 ? '%d %H:%M:%S' : '%H:%M:%S'
42
- Time.at(seconds.to_i).utc.strftime(format)
43
- end
44
-
45
- def convert_the_distance(distance, unit)
46
- case unit
47
- when 'mi'
48
- bigdecimal ? km_to_mi = KM_TO_MI_BIGDECIMAL : km_to_mi = KM_TO_MI
49
- (distance * km_to_mi)
50
- when 'km'
51
- bigdecimal ? mi_to_km = MI_TO_KM_BIGDECIMAL : mi_to_km = MI_TO_KM
52
- (distance * mi_to_km)
53
- end
54
- end
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 Calcpace
8
- include Calculator
9
- include Checker
10
- include Converter
11
-
12
- attr_reader :bigdecimal
13
-
14
- def initialize(bigdecimal = false)
15
- @bigdecimal = bigdecimal
16
- end
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(bigdecimal = true)
11
- end
12
-
13
- def test_pace
14
- assert_raises(RuntimeError) { @checker.pace('', 10) }
15
- assert_raises(RuntimeError) { @checker.pace('invalid', 10) }
16
- assert_raises(RuntimeError) { @checker.pace('00:00:00', 0) }
17
- assert_raises(RuntimeError) { @checker.pace('00:00:00', -1) }
18
- assert_equal '00:06:00', @checker.pace('01:00:00', 10)
19
- assert_equal '00:07:54', @checker.pace('01:37:21', 12.3)
20
- end
21
-
22
- def test_pace_with_bigdecimal_precision
23
- assert_equal '00:07:54', @checker_bigdecimal.pace('01:37:21', 12.3)
24
- end
25
-
26
- def test_pace_without_bigdecimal_precision
27
- assert_equal '00:07:54', @checker.pace('01:37:21', 12.3)
28
- end
29
-
30
- def test_pace_seconds
31
- assert_raises(RuntimeError) { @checker.pace_seconds('', 10) }
32
- assert_raises(RuntimeError) { @checker.pace_seconds('invalid', 10) }
33
- assert_raises(RuntimeError) { @checker.pace_seconds('00:00:00', 0) }
34
- assert_raises(RuntimeError) { @checker.pace_seconds('00:00:00', -1) }
35
- assert_equal 474.8780487804878, @checker.pace_seconds('01:37:21', 12.3)
36
- end
37
-
38
- def test_pace_seconds_with_bigdecimal_precision
39
- assert_equal BigDecimal('0.474878048780487804878048780487804878049e3'), @checker_bigdecimal.pace_seconds('01:37:21', 12.3)
40
- end
41
-
42
- def test_total_time
43
- assert_raises(RuntimeError) { @checker.total_time('', 10) }
44
- assert_raises(RuntimeError) { @checker.total_time('invalid', 10) }
45
- assert_raises(RuntimeError) { @checker.total_time('00:00:00', 0) }
46
- assert_raises(RuntimeError) { @checker.total_time('00:00:00', -1) }
47
- assert_equal '01:00:00', @checker.total_time('00:05:00', 12)
48
- end
49
-
50
- def test_total_time_seconds
51
- assert_raises(RuntimeError) { @checker.total_time_seconds('', 10) }
52
- assert_raises(RuntimeError) { @checker.total_time_seconds('invalid', 10) }
53
- assert_raises(RuntimeError) { @checker.total_time_seconds('00:00:00', 0) }
54
- assert_raises(RuntimeError) { @checker.total_time_seconds('00:00:00', -1) }
55
- assert_equal 3600, @checker.total_time_seconds('00:05:00', 12)
56
- assert_equal 71_844.3, @checker.total_time_seconds('01:37:21', 12.3)
57
- end
58
-
59
- def test_total_time_seconds_with_bigdecimal_precision
60
- assert_equal BigDecimal('0.718443e5'), @checker_bigdecimal.total_time_seconds('01:37:21', 12.3)
61
- end
62
-
63
- def test_distance
64
- assert_raises(RuntimeError) { @checker.distance('', '00:05:00') }
65
- assert_raises(RuntimeError) { @checker.distance('01:00:00', '') }
66
- assert_equal 18.0, @checker.distance('01:30:00', '00:05:00')
67
- assert_equal 15.0, @checker.distance('01:37:21', '00:06:17')
68
- end
69
-
70
- def test_distance_with_bigdecimal_precision
71
- assert_equal BigDecimal('0.15493368700265251989389920424403183024e2'), @checker_bigdecimal.distance('01:37:21', '00:06:17')
72
- end
73
- 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
+ @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 test_check_distance
12
- assert_raises(RuntimeError) { @checker.check_distance(-1) }
13
- assert_raises(RuntimeError) { @checker.check_distance(0) }
14
- assert_nil @checker.check_distance(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
-
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(bigdecimal = 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_to_seconds
17
- assert_equal 3600, @checker.to_seconds('01:00:00')
18
- assert_raises(RuntimeError) { @checker.to_seconds('invalid') }
19
- end
20
-
21
- def test_convert_to_clocktime
22
- assert_equal '01:11:02', @checker.convert_to_clocktime(4262)
23
- end
24
-
25
- def test_to_clocktime
26
- assert_equal '01:00:00', @checker.to_clocktime(3600)
27
- assert_equal '02 01:00:00', @checker.to_clocktime(90_000)
28
- assert_raises(RuntimeError) { @checker.to_clocktime(-1) }
29
- assert_raises(RuntimeError) { @checker.to_clocktime(0) }
30
- assert_raises(RuntimeError) { @checker.to_clocktime('invalid') }
31
- end
32
-
33
- def test_convert_the_distance
34
- assert_equal 6.21, @checker.convert_the_distance(10, 'mi').round(2)
35
- assert_equal 6.2, @checker.convert_the_distance(10, 'mi').round(1)
36
- assert_equal 6.214, @checker.convert_the_distance(10, 'mi').round(3)
37
- assert_equal 16.09, @checker.convert_the_distance(10, 'km').round(2)
38
- end
39
-
40
- def test_convert_the_distance_with_bigdecimal_precision
41
- assert_equal BigDecimal('6.21371'), @checker_bigdecimal.convert_the_distance(10, 'mi')
42
- end
43
-
44
- def test_convert
45
- assert_equal 6.21, @checker.convert(10, 'mi').round(2)
46
- assert_equal 16.09, @checker.convert(10, 'km').round(2)
47
- assert_equal 6.2, @checker.convert(10, 'mi').round(1)
48
- assert_raises(RuntimeError) { @checker.convert(-1, 'km') }
49
- end
50
-
51
- def test_convert_to_miles
52
- assert_equal 6.21, @checker.convert_to_miles(10).round(2)
53
- end
54
-
55
- def test_convert_to_km
56
- assert_equal 16.09, @checker.convert_to_km(10).round(2)
57
- end
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.2.0
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-10 00:00:00.000000000 Z
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: '0.79'
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: '0.79'
83
- - !ruby/object:Gem::Dependency
84
- name: rubocop-minitest
85
- requirement: !ruby/object:Gem::Requirement
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 time, distance, pace, velocity and convert distances
139
- in an easy and precise way.'
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