auom 0.0.6 → 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/.circle.yml +4 -0
- data/.rubocop.yml +7 -0
- data/.travis.yml +2 -9
- data/Changelog.md +4 -0
- data/Gemfile +2 -2
- data/Gemfile.devtools +39 -32
- data/auom.gemspec +3 -4
- data/circle.yml +4 -0
- data/config/flay.yml +1 -1
- data/config/{site.reek → reek.yml} +12 -11
- data/config/rubocop.yml +89 -0
- data/lib/auom.rb +7 -325
- data/lib/auom/algebra.rb +13 -10
- data/lib/auom/equalization.rb +6 -2
- data/lib/auom/inspection.rb +22 -57
- data/lib/auom/relational.rb +4 -2
- data/lib/auom/unit.rb +324 -0
- data/spec/shared/incompatible_operation_behavior.rb +3 -1
- data/spec/shared/operation_behavior.rb +3 -2
- data/spec/shared/sunits_shared.rb +3 -1
- data/spec/spec_helper.rb +2 -0
- data/spec/unit/auom/algebra/add_spec.rb +8 -6
- data/spec/unit/auom/algebra/divide_spec.rb +26 -15
- data/spec/unit/auom/algebra/multiply_spec.rb +25 -15
- data/spec/unit/auom/algebra/substract_spec.rb +8 -6
- data/spec/unit/auom/equalization/equality_operator_spec.rb +5 -3
- data/spec/unit/auom/inspection/class_methods/prettify_unit_part_spec.rb +6 -4
- data/spec/unit/auom/inspection/inspect_spec.rb +15 -13
- data/spec/unit/auom/relational/greater_than_or_equal_to_predicate_spec.rb +3 -1
- data/spec/unit/auom/relational/greater_than_predicate_spec.rb +3 -1
- data/spec/unit/auom/relational/less_than_or_equal_to_predicate_spec.rb +3 -1
- data/spec/unit/auom/relational/less_than_predicate_spec.rb +3 -1
- data/spec/unit/auom/unit/assert_same_unit_spec.rb +5 -3
- data/spec/unit/auom/unit/class_methods/convert_spec.rb +8 -6
- data/spec/unit/auom/unit/class_methods/lookup_spec.rb +6 -4
- data/spec/unit/auom/unit/class_methods/new_spec.rb +22 -21
- data/spec/unit/auom/unit/class_methods/try_convert_spec.rb +6 -4
- data/spec/unit/auom/unit/class_methods/units_spec.rb +3 -1
- data/spec/unit/auom/unit/denominators_spec.rb +5 -3
- data/spec/unit/auom/unit/numerators_spec.rb +5 -3
- data/spec/unit/auom/unit/same_unit_predicate_spec.rb +5 -3
- data/spec/unit/auom/unit/scalar_spec.rb +4 -2
- data/spec/unit/auom/unit/unit +0 -0
- data/spec/unit/auom/unit/unit_spec.rb +5 -3
- data/spec/unit/auom/unit/unitless_predicate_spec.rb +9 -1
- metadata +13 -28
@@ -1,11 +1,13 @@
|
|
1
|
+
# encoding: UTF-8
|
2
|
+
|
1
3
|
require 'spec_helper'
|
2
4
|
|
3
|
-
describe AUOM::Unit,'#assert_same_unit' do
|
5
|
+
describe AUOM::Unit, '#assert_same_unit' do
|
4
6
|
|
5
7
|
subject { object.assert_same_unit(other) }
|
6
8
|
|
7
|
-
let(:object) { described_class.new(1
|
8
|
-
let(:unit) { [[:meter],[:euro]] }
|
9
|
+
let(:object) { described_class.new(1, *unit) }
|
10
|
+
let(:unit) { [[:meter], [:euro]] }
|
9
11
|
|
10
12
|
context 'when units are the same' do
|
11
13
|
let(:other) { AUOM::Unit.new(2, :meter, :euro) }
|
@@ -1,6 +1,8 @@
|
|
1
|
+
# encoding: UTF-8
|
2
|
+
|
1
3
|
require 'spec_helper'
|
2
4
|
|
3
|
-
describe AUOM::Unit,'.convert' do
|
5
|
+
describe AUOM::Unit, '.convert' do
|
4
6
|
subject { object.convert(value) }
|
5
7
|
|
6
8
|
let(:object) { AUOM::Unit }
|
@@ -9,27 +11,27 @@ describe AUOM::Unit,'.convert' do
|
|
9
11
|
let(:value) { nil }
|
10
12
|
|
11
13
|
it 'should raise error' do
|
12
|
-
expect { subject }.to raise_error(ArgumentError,'Cannot convert nil to AUOM::Unit')
|
14
|
+
expect { subject }.to raise_error(ArgumentError, 'Cannot convert nil to AUOM::Unit')
|
13
15
|
end
|
14
16
|
end
|
15
17
|
|
16
18
|
context 'with fixnum' do
|
17
|
-
let(:value) { 1 }
|
19
|
+
let(:value) { 1 }
|
18
20
|
|
19
21
|
it { should eql(AUOM::Unit.new(1)) }
|
20
22
|
end
|
21
23
|
|
22
24
|
context 'with rational' do
|
23
|
-
let(:value) { Rational(2,1) }
|
25
|
+
let(:value) { Rational(2, 1) }
|
24
26
|
|
25
27
|
it { should eql(AUOM::Unit.new(2)) }
|
26
28
|
end
|
27
29
|
|
28
30
|
context 'with Object' do
|
29
|
-
let(:value) { Object.new }
|
31
|
+
let(:value) { Object.new }
|
30
32
|
|
31
33
|
it 'should raise error' do
|
32
|
-
expect { subject }.to raise_error(ArgumentError,"Cannot convert #{value.inspect} to AUOM::Unit")
|
34
|
+
expect { subject }.to raise_error(ArgumentError, "Cannot convert #{value.inspect} to AUOM::Unit")
|
33
35
|
end
|
34
36
|
end
|
35
37
|
end
|
@@ -1,21 +1,23 @@
|
|
1
|
+
# encoding: UTF-8
|
2
|
+
|
1
3
|
require 'spec_helper'
|
2
4
|
|
3
|
-
describe AUOM::Unit,'.lookup' do
|
4
|
-
subject { object.send(:lookup,value) }
|
5
|
+
describe AUOM::Unit, '.lookup' do
|
6
|
+
subject { object.send(:lookup, value) }
|
5
7
|
|
6
8
|
let(:object) { described_class }
|
7
9
|
|
8
10
|
context 'with existing symbol' do
|
9
11
|
let(:value) { :meter }
|
10
12
|
|
11
|
-
it { should eql([1
|
13
|
+
it { should eql([1, :meter]) }
|
12
14
|
end
|
13
15
|
|
14
16
|
context 'with inexisting symbol' do
|
15
17
|
let(:value) { :foo }
|
16
18
|
|
17
19
|
it 'should raise error' do
|
18
|
-
expect { subject }.to raise_error(ArgumentError,'Unknown unit :foo')
|
20
|
+
expect { subject }.to raise_error(ArgumentError, 'Unknown unit :foo')
|
19
21
|
end
|
20
22
|
end
|
21
23
|
end
|
@@ -1,6 +1,8 @@
|
|
1
|
-
|
1
|
+
# encoding: UTF-8
|
2
2
|
|
3
|
-
|
3
|
+
require 'spec_helper'
|
4
|
+
|
5
|
+
describe AUOM::Unit, '#new' do
|
4
6
|
let(:object) { described_class }
|
5
7
|
|
6
8
|
subject do
|
@@ -12,7 +14,7 @@ describe AUOM::Unit,'#new' do
|
|
12
14
|
expect { subject }.to raise_error(ArgumentError)
|
13
15
|
end
|
14
16
|
end
|
15
|
-
|
17
|
+
|
16
18
|
let(:expected_scalar) { 1 }
|
17
19
|
let(:expected_numerators) { [] }
|
18
20
|
let(:expected_denominators) { [] }
|
@@ -39,7 +41,7 @@ describe AUOM::Unit,'#new' do
|
|
39
41
|
context 'when scalar is a string' do
|
40
42
|
let(:argument) { '10.31' }
|
41
43
|
it 'should raise error' do
|
42
|
-
expect { subject }.to raise_error(ArgumentError,'"10.31" cannot be converted to rational')
|
44
|
+
expect { subject }.to raise_error(ArgumentError, '"10.31" cannot be converted to rational')
|
43
45
|
end
|
44
46
|
end
|
45
47
|
|
@@ -51,7 +53,7 @@ describe AUOM::Unit,'#new' do
|
|
51
53
|
end
|
52
54
|
|
53
55
|
context 'when argument is a Rational' do
|
54
|
-
let(:argument) { Rational(1,1) }
|
56
|
+
let(:argument) { Rational(1, 1) }
|
55
57
|
|
56
58
|
it_should_behave_like 'unitless unit'
|
57
59
|
it_should_behave_like 'valid unit'
|
@@ -65,9 +67,9 @@ describe AUOM::Unit,'#new' do
|
|
65
67
|
end
|
66
68
|
|
67
69
|
describe 'with scalar and numerator argument' do
|
68
|
-
let(:arguments) { [1,argument] }
|
70
|
+
let(:arguments) { [1, argument] }
|
69
71
|
|
70
|
-
context 'when argument is a valid unit' do
|
72
|
+
context 'when argument is a valid unit' do
|
71
73
|
let(:argument) { :kilogramm }
|
72
74
|
let(:expected_numerators) { [:kilogramm] }
|
73
75
|
|
@@ -83,14 +85,14 @@ describe AUOM::Unit,'#new' do
|
|
83
85
|
end
|
84
86
|
|
85
87
|
context 'when argument is an array of valid units' do
|
86
|
-
let(:argument) { [:kilogramm
|
87
|
-
let(:expected_numerators) { [:kilogramm
|
88
|
+
let(:argument) { [:kilogramm, :meter] }
|
89
|
+
let(:expected_numerators) { [:kilogramm, :meter] }
|
88
90
|
|
89
91
|
it_should_behave_like 'valid unit'
|
90
92
|
end
|
91
93
|
|
92
94
|
context 'when argument is an array with invalid unit' do
|
93
|
-
let(:argument) { [:kilogramm
|
95
|
+
let(:argument) { [:kilogramm, :nonsense] }
|
94
96
|
|
95
97
|
it_should_behave_like 'invalid unit'
|
96
98
|
end
|
@@ -103,10 +105,10 @@ describe AUOM::Unit,'#new' do
|
|
103
105
|
end
|
104
106
|
|
105
107
|
describe 'with scalar, numerator and denominator argument' do
|
106
|
-
let(:arguments) { [1
|
108
|
+
let(:arguments) { [1, :kilogramm, argument] }
|
107
109
|
let(:expected_numerators) { [:kilogramm] }
|
108
110
|
|
109
|
-
context 'when argument is a valid unit' do
|
111
|
+
context 'when argument is a valid unit' do
|
110
112
|
let(:argument) { :meter }
|
111
113
|
let(:expected_denominators) { [:meter] }
|
112
114
|
|
@@ -117,21 +119,20 @@ describe AUOM::Unit,'#new' do
|
|
117
119
|
let(:argument) { :kilometer }
|
118
120
|
|
119
121
|
let(:expected_denominators) { [:meter] }
|
120
|
-
let(:expected_scalar) { Rational(1,1000) }
|
122
|
+
let(:expected_scalar) { Rational(1, 1000) }
|
121
123
|
|
122
124
|
it_should_behave_like 'valid unit'
|
123
125
|
end
|
124
126
|
|
125
|
-
|
126
127
|
context 'when argument is an array of valid units' do
|
127
|
-
let(:argument) { [:euro
|
128
|
-
let(:expected_denominators) { [:euro
|
128
|
+
let(:argument) { [:euro, :meter] }
|
129
|
+
let(:expected_denominators) { [:euro, :meter] }
|
129
130
|
|
130
131
|
it_should_behave_like 'valid unit'
|
131
132
|
end
|
132
133
|
|
133
134
|
context 'when argument is an array with invalid unit' do
|
134
|
-
let(:argument) { [:euro
|
135
|
+
let(:argument) { [:euro, :nonsense] }
|
135
136
|
|
136
137
|
it_should_behave_like 'invalid unit'
|
137
138
|
end
|
@@ -144,11 +145,11 @@ describe AUOM::Unit,'#new' do
|
|
144
145
|
end
|
145
146
|
|
146
147
|
context 'when numerators and denominators overlap' do
|
147
|
-
let(:arguments) { [1,numerators,denominators] }
|
148
|
-
let(:numerators) { [:kilogramm
|
149
|
-
let(:denominators) { [:meter
|
148
|
+
let(:arguments) { [1, numerators, denominators] }
|
149
|
+
let(:numerators) { [:kilogramm, :meter, :euro] }
|
150
|
+
let(:denominators) { [:meter, :meter] }
|
150
151
|
|
151
|
-
let(:expected_numerators) { [:euro
|
152
|
+
let(:expected_numerators) { [:euro, :kilogramm] }
|
152
153
|
let(:expected_denominators) { [:meter] }
|
153
154
|
|
154
155
|
it_should_behave_like 'valid unit'
|
@@ -1,6 +1,8 @@
|
|
1
|
+
# encoding: UTF-8
|
2
|
+
|
1
3
|
require 'spec_helper'
|
2
4
|
|
3
|
-
describe AUOM,'.try_convert' do
|
5
|
+
describe AUOM::Unit, '.try_convert' do
|
4
6
|
subject { object.try_convert(value) }
|
5
7
|
|
6
8
|
let(:object) { AUOM::Unit }
|
@@ -18,19 +20,19 @@ describe AUOM,'.try_convert' do
|
|
18
20
|
end
|
19
21
|
|
20
22
|
context 'with fixnum' do
|
21
|
-
let(:value) { 1 }
|
23
|
+
let(:value) { 1 }
|
22
24
|
|
23
25
|
it { should eql(AUOM::Unit.new(1)) }
|
24
26
|
end
|
25
27
|
|
26
28
|
context 'with rational' do
|
27
|
-
let(:value) { Rational(2,1) }
|
29
|
+
let(:value) { Rational(2, 1) }
|
28
30
|
|
29
31
|
it { should eql(AUOM::Unit.new(2)) }
|
30
32
|
end
|
31
33
|
|
32
34
|
context 'with Object' do
|
33
|
-
let(:value) { Object.new }
|
35
|
+
let(:value) { Object.new }
|
34
36
|
|
35
37
|
it { should be(nil) }
|
36
38
|
end
|
@@ -1,10 +1,12 @@
|
|
1
|
+
# encoding: UTF-8
|
2
|
+
|
1
3
|
require 'spec_helper'
|
2
4
|
|
3
|
-
describe AUOM::Unit,'#denominators' do
|
5
|
+
describe AUOM::Unit, '#denominators' do
|
4
6
|
subject { object.denominators }
|
5
7
|
|
6
|
-
let(:object) { described_class.new(1
|
7
|
-
let(:unit) { [[:meter],[:euro]] }
|
8
|
+
let(:object) { described_class.new(1, *unit) }
|
9
|
+
let(:unit) { [[:meter], [:euro]] }
|
8
10
|
|
9
11
|
it 'should return denominators' do
|
10
12
|
should eql([:euro])
|
@@ -1,10 +1,12 @@
|
|
1
|
+
# encoding: UTF-8
|
2
|
+
|
1
3
|
require 'spec_helper'
|
2
4
|
|
3
|
-
describe AUOM::Unit,'#numerators' do
|
5
|
+
describe AUOM::Unit, '#numerators' do
|
4
6
|
subject { object.numerators }
|
5
7
|
|
6
|
-
let(:object) { described_class.new(1
|
7
|
-
let(:unit) { [[:meter],[:euro]] }
|
8
|
+
let(:object) { described_class.new(1, *unit) }
|
9
|
+
let(:unit) { [[:meter], [:euro]] }
|
8
10
|
|
9
11
|
it 'should return numerators' do
|
10
12
|
should eql([:meter])
|
@@ -1,11 +1,13 @@
|
|
1
|
+
# encoding: UTF-8
|
2
|
+
|
1
3
|
require 'spec_helper'
|
2
4
|
|
3
|
-
describe AUOM::Unit,'#same_unit?' do
|
5
|
+
describe AUOM::Unit, '#same_unit?' do
|
4
6
|
|
5
7
|
subject { object.same_unit?(other) }
|
6
8
|
|
7
|
-
let(:object) { described_class.new(1
|
8
|
-
let(:unit) { [[:meter],[:euro]] }
|
9
|
+
let(:object) { described_class.new(1, *unit) }
|
10
|
+
let(:unit) { [[:meter], [:euro]] }
|
9
11
|
|
10
12
|
context 'when units are the same' do
|
11
13
|
let(:other) { AUOM::Unit.new(2, :meter, :euro) }
|
@@ -1,10 +1,12 @@
|
|
1
|
+
# encoding: UTF-8
|
2
|
+
|
1
3
|
require 'spec_helper'
|
2
4
|
|
3
|
-
describe AUOM::Unit,'#denominators' do
|
5
|
+
describe AUOM::Unit, '#denominators' do
|
4
6
|
subject { object.scalar }
|
5
7
|
|
6
8
|
let(:object) { described_class.new(scalar) }
|
7
|
-
let(:scalar) { Rational(1,2) }
|
9
|
+
let(:scalar) { Rational(1, 2) }
|
8
10
|
|
9
11
|
it 'should return scalar' do
|
10
12
|
should eql(scalar)
|
File without changes
|
@@ -1,10 +1,12 @@
|
|
1
|
+
# encoding: UTF-8
|
2
|
+
|
1
3
|
require 'spec_helper'
|
2
4
|
|
3
|
-
describe AUOM::Unit,'#unit' do
|
5
|
+
describe AUOM::Unit, '#unit' do
|
4
6
|
subject { object.unit }
|
5
7
|
|
6
|
-
let(:object) { described_class.new(1
|
7
|
-
let(:unit) { [[:meter],[:euro]] }
|
8
|
+
let(:object) { described_class.new(1, *unit) }
|
9
|
+
let(:unit) { [[:meter], [:euro]] }
|
8
10
|
|
9
11
|
it 'should return unit of unit instance' do
|
10
12
|
should eql(unit)
|
@@ -1,3 +1,5 @@
|
|
1
|
+
# encoding: UTF-8
|
2
|
+
|
1
3
|
require 'spec_helper'
|
2
4
|
|
3
5
|
describe AUOM::Unit, '#unitless?' do
|
@@ -10,9 +12,15 @@ describe AUOM::Unit, '#unitless?' do
|
|
10
12
|
it { should be(true) }
|
11
13
|
end
|
12
14
|
|
13
|
-
context 'when unit
|
15
|
+
context 'when unit has no denominator' do
|
14
16
|
let(:unit) { [:meter] }
|
15
17
|
|
16
18
|
it { should be(false) }
|
17
19
|
end
|
20
|
+
|
21
|
+
context 'when unit has no numerator' do
|
22
|
+
let(:unit) { [[], :meter] }
|
23
|
+
|
24
|
+
it { should be(false) }
|
25
|
+
end
|
18
26
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: auom
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0
|
4
|
+
version: 0.1.0
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,30 +9,8 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date:
|
12
|
+
date: 2014-03-24 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
|
-
- !ruby/object:Gem::Dependency
|
15
|
-
name: backports
|
16
|
-
requirement: !ruby/object:Gem::Requirement
|
17
|
-
none: false
|
18
|
-
requirements:
|
19
|
-
- - ~>
|
20
|
-
- !ruby/object:Gem::Version
|
21
|
-
version: '3.0'
|
22
|
-
- - ! '>='
|
23
|
-
- !ruby/object:Gem::Version
|
24
|
-
version: 3.0.3
|
25
|
-
type: :runtime
|
26
|
-
prerelease: false
|
27
|
-
version_requirements: !ruby/object:Gem::Requirement
|
28
|
-
none: false
|
29
|
-
requirements:
|
30
|
-
- - ~>
|
31
|
-
- !ruby/object:Gem::Version
|
32
|
-
version: '3.0'
|
33
|
-
- - ! '>='
|
34
|
-
- !ruby/object:Gem::Version
|
35
|
-
version: 3.0.3
|
36
14
|
- !ruby/object:Gem::Dependency
|
37
15
|
name: equalizer
|
38
16
|
requirement: !ruby/object:Gem::Requirement
|
@@ -40,7 +18,7 @@ dependencies:
|
|
40
18
|
requirements:
|
41
19
|
- - ~>
|
42
20
|
- !ruby/object:Gem::Version
|
43
|
-
version: 0.0.
|
21
|
+
version: 0.0.9
|
44
22
|
type: :runtime
|
45
23
|
prerelease: false
|
46
24
|
version_requirements: !ruby/object:Gem::Requirement
|
@@ -48,17 +26,19 @@ dependencies:
|
|
48
26
|
requirements:
|
49
27
|
- - ~>
|
50
28
|
- !ruby/object:Gem::Version
|
51
|
-
version: 0.0.
|
29
|
+
version: 0.0.9
|
52
30
|
description:
|
53
|
-
email: mbj@
|
31
|
+
email: mbj@schirp-dso.com
|
54
32
|
executables: []
|
55
33
|
extensions: []
|
56
34
|
extra_rdoc_files:
|
57
35
|
- TODO
|
58
36
|
- LICENSE
|
59
37
|
files:
|
38
|
+
- .circle.yml
|
60
39
|
- .gitignore
|
61
40
|
- .rspec
|
41
|
+
- .rubocop.yml
|
62
42
|
- .travis.yml
|
63
43
|
- Changelog.md
|
64
44
|
- Gemfile
|
@@ -69,17 +49,20 @@ files:
|
|
69
49
|
- Rakefile
|
70
50
|
- TODO
|
71
51
|
- auom.gemspec
|
52
|
+
- circle.yml
|
72
53
|
- config/flay.yml
|
73
54
|
- config/flog.yml
|
74
55
|
- config/mutant.yml
|
56
|
+
- config/reek.yml
|
75
57
|
- config/roodi.yml
|
76
|
-
- config/
|
58
|
+
- config/rubocop.yml
|
77
59
|
- config/yardstick.yml
|
78
60
|
- lib/auom.rb
|
79
61
|
- lib/auom/algebra.rb
|
80
62
|
- lib/auom/equalization.rb
|
81
63
|
- lib/auom/inspection.rb
|
82
64
|
- lib/auom/relational.rb
|
65
|
+
- lib/auom/unit.rb
|
83
66
|
- spec/rcov.opts
|
84
67
|
- spec/shared/incompatible_operation_behavior.rb
|
85
68
|
- spec/shared/operation_behavior.rb
|
@@ -106,6 +89,7 @@ files:
|
|
106
89
|
- spec/unit/auom/unit/numerators_spec.rb
|
107
90
|
- spec/unit/auom/unit/same_unit_predicate_spec.rb
|
108
91
|
- spec/unit/auom/unit/scalar_spec.rb
|
92
|
+
- spec/unit/auom/unit/unit
|
109
93
|
- spec/unit/auom/unit/unit_spec.rb
|
110
94
|
- spec/unit/auom/unit/unitless_predicate_spec.rb
|
111
95
|
homepage: http://github.com/mbj/auom
|
@@ -159,6 +143,7 @@ test_files:
|
|
159
143
|
- spec/unit/auom/unit/numerators_spec.rb
|
160
144
|
- spec/unit/auom/unit/same_unit_predicate_spec.rb
|
161
145
|
- spec/unit/auom/unit/scalar_spec.rb
|
146
|
+
- spec/unit/auom/unit/unit
|
162
147
|
- spec/unit/auom/unit/unit_spec.rb
|
163
148
|
- spec/unit/auom/unit/unitless_predicate_spec.rb
|
164
149
|
has_rdoc:
|