measured 2.3.0 → 2.6.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/.github/workflows/ci.yml +31 -0
- data/CHANGELOG.md +25 -0
- data/README.md +12 -10
- data/Rakefile +22 -1
- data/cache/.keep +0 -0
- data/cache/length.json +2553 -0
- data/cache/volume.json +4163 -0
- data/cache/weight.json +3195 -0
- data/dev.yml +2 -2
- data/gemfiles/{activesupport-4.2.gemfile → activesupport-5.2.gemfile} +1 -1
- data/gemfiles/activesupport-6.0.gemfile +5 -0
- data/gemfiles/activesupport-6.1.gemfile +5 -0
- data/lib/measured.rb +1 -0
- data/lib/measured/arithmetic.rb +1 -0
- data/lib/measured/base.rb +12 -6
- data/lib/measured/cache/json.rb +49 -0
- data/lib/measured/cache/json_writer.rb +9 -0
- data/lib/measured/cache/null.rb +16 -0
- data/lib/measured/conversion_table_builder.rb +91 -0
- data/lib/measured/measurable.rb +18 -21
- data/lib/measured/missing_conversion_path.rb +12 -0
- data/lib/measured/parser.rb +1 -0
- data/lib/measured/unit.rb +16 -26
- data/lib/measured/unit_already_added.rb +11 -0
- data/lib/measured/unit_error.rb +4 -0
- data/lib/measured/unit_system.rb +26 -21
- data/lib/measured/unit_system_builder.rb +11 -4
- data/lib/measured/units/length.rb +3 -0
- data/lib/measured/units/volume.rb +4 -1
- data/lib/measured/units/weight.rb +3 -0
- data/lib/measured/version.rb +2 -1
- data/measured.gemspec +13 -5
- data/test/arithmetic_test.rb +1 -0
- data/test/cache/json_test.rb +43 -0
- data/test/cache/json_writer_test.rb +23 -0
- data/test/cache/null_test.rb +20 -0
- data/test/cache_consistency_test.rb +19 -0
- data/test/conversion_table_builder_test.rb +137 -0
- data/test/measurable_test.rb +5 -5
- data/test/parser_test.rb +1 -0
- data/test/support/always_true_cache.rb +14 -0
- data/test/support/fake_system.rb +1 -0
- data/test/support/subclasses.rb +7 -0
- data/test/test_helper.rb +5 -3
- data/test/unit_error_test.rb +1 -0
- data/test/unit_system_builder_test.rb +49 -3
- data/test/unit_system_test.rb +15 -0
- data/test/unit_test.rb +5 -0
- data/test/units/length_test.rb +5 -4
- data/test/units/volume_test.rb +6 -5
- data/test/units/weight_test.rb +1 -0
- metadata +45 -18
- data/.travis.yml +0 -17
- data/lib/measured/conversion_table.rb +0 -65
- data/test/conversion_table_test.rb +0 -98
@@ -1,98 +0,0 @@
|
|
1
|
-
require "test_helper"
|
2
|
-
|
3
|
-
class Measured::ConversionTableTest < ActiveSupport::TestCase
|
4
|
-
test ".build should return a hash for the simple case" do
|
5
|
-
expected = {
|
6
|
-
"test" => {"test" => BigDecimal("1")}
|
7
|
-
}
|
8
|
-
|
9
|
-
assert_equal expected, Measured::ConversionTable.build([Measured::Unit.new(:test)])
|
10
|
-
end
|
11
|
-
|
12
|
-
test ".build returns expected nested hashes with BigDecimal conversion factors in a tiny data set" do
|
13
|
-
conversion_table = Measured::ConversionTable.build([
|
14
|
-
Measured::Unit.new(:m),
|
15
|
-
Measured::Unit.new(:cm, value: "0.01 m"),
|
16
|
-
])
|
17
|
-
|
18
|
-
expected = {
|
19
|
-
"m" => {
|
20
|
-
"m" => BigDecimal("1"),
|
21
|
-
"cm" => BigDecimal("100"),
|
22
|
-
},
|
23
|
-
"cm" => {
|
24
|
-
"m" => BigDecimal("0.01"),
|
25
|
-
"cm" => BigDecimal("1"),
|
26
|
-
}
|
27
|
-
}
|
28
|
-
|
29
|
-
assert_equal expected, conversion_table
|
30
|
-
end
|
31
|
-
|
32
|
-
test ".build returns expected nested hashes with BigDecimal conversion factors" do
|
33
|
-
conversion_table = Measured::ConversionTable.build([
|
34
|
-
Measured::Unit.new(:m),
|
35
|
-
Measured::Unit.new(:cm, value: "0.01 m"),
|
36
|
-
Measured::Unit.new(:mm, value: "0.001 m"),
|
37
|
-
])
|
38
|
-
|
39
|
-
expected = {
|
40
|
-
"m" => {
|
41
|
-
"m" => BigDecimal("1"),
|
42
|
-
"cm" => BigDecimal("100"),
|
43
|
-
"mm" => BigDecimal("1000"),
|
44
|
-
},
|
45
|
-
"cm" => {
|
46
|
-
"m" => BigDecimal("0.01"),
|
47
|
-
"cm" => BigDecimal("1"),
|
48
|
-
"mm" => BigDecimal("10"),
|
49
|
-
},
|
50
|
-
"mm" => {
|
51
|
-
"m" => BigDecimal("0.001"),
|
52
|
-
"cm" => BigDecimal("0.1"),
|
53
|
-
"mm" => BigDecimal("1"),
|
54
|
-
}
|
55
|
-
}
|
56
|
-
|
57
|
-
assert_equal expected, conversion_table
|
58
|
-
end
|
59
|
-
|
60
|
-
test ".build returns expected nested hashes with BigDecimal conversion factors in an indrect path" do
|
61
|
-
conversion_table = Measured::ConversionTable.build([
|
62
|
-
Measured::Unit.new(:mm),
|
63
|
-
Measured::Unit.new(:cm, value: "10 mm"),
|
64
|
-
Measured::Unit.new(:dm, value: "10 cm"),
|
65
|
-
Measured::Unit.new(:m, value: "10 dm"),
|
66
|
-
])
|
67
|
-
|
68
|
-
expected = {
|
69
|
-
"m" => {
|
70
|
-
"m" => BigDecimal("1"),
|
71
|
-
"dm" => BigDecimal("10"),
|
72
|
-
"cm" => BigDecimal("100"),
|
73
|
-
"mm" => BigDecimal("1000"),
|
74
|
-
},
|
75
|
-
"cm" => {
|
76
|
-
"m" => BigDecimal("0.01"),
|
77
|
-
"dm" => BigDecimal("0.1"),
|
78
|
-
"cm" => BigDecimal("1"),
|
79
|
-
"mm" => BigDecimal("10"),
|
80
|
-
},
|
81
|
-
"dm" => {
|
82
|
-
"m" => BigDecimal("0.1"),
|
83
|
-
"cm" => BigDecimal("10"),
|
84
|
-
"dm" => BigDecimal("1"),
|
85
|
-
"mm" => BigDecimal("100"),
|
86
|
-
},
|
87
|
-
"mm" => {
|
88
|
-
"m" => BigDecimal("0.001"),
|
89
|
-
"dm" => BigDecimal("0.01"),
|
90
|
-
"cm" => BigDecimal("0.1"),
|
91
|
-
"mm" => BigDecimal("1"),
|
92
|
-
}
|
93
|
-
}
|
94
|
-
|
95
|
-
assert_equal expected, conversion_table
|
96
|
-
end
|
97
|
-
|
98
|
-
end
|