auom 0.1.0 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.rspec +1 -0
- data/.rubocop.yml +2 -6
- data/.travis.yml +5 -2
- data/Changelog.md +5 -1
- data/Gemfile +0 -5
- data/README.md +17 -22
- data/TODO +1 -1
- data/auom.gemspec +14 -14
- data/circle.yml +3 -0
- data/config/flay.yml +1 -1
- data/config/flog.yml +1 -1
- data/config/reek.yml +2 -1
- data/config/rubocop.yml +130 -34
- data/lib/auom.rb +0 -2
- data/lib/auom/algebra.rb +5 -7
- data/lib/auom/equalization.rb +0 -2
- data/lib/auom/inspection.rb +26 -23
- data/lib/auom/relational.rb +2 -4
- data/lib/auom/unit.rb +15 -17
- data/spec/shared/incompatible_operation_behavior.rb +0 -2
- data/spec/shared/operation_behavior.rb +5 -4
- data/spec/shared/sunits_shared.rb +0 -2
- data/spec/spec_helper.rb +1 -4
- data/spec/unit/auom/algebra/add_spec.rb +12 -16
- data/spec/unit/auom/algebra/divide_spec.rb +50 -52
- data/spec/unit/auom/algebra/multiply_spec.rb +17 -21
- data/spec/unit/auom/algebra/substract_spec.rb +4 -8
- data/spec/unit/auom/equalization/equality_operator_spec.rb +3 -7
- data/spec/unit/auom/inspection/class_methods/prettify_unit_part_spec.rb +7 -7
- data/spec/unit/auom/inspection/inspect_spec.rb +1 -5
- data/spec/unit/auom/relational/greater_than_or_equal_to_predicate_spec.rb +0 -4
- data/spec/unit/auom/relational/greater_than_predicate_spec.rb +0 -4
- data/spec/unit/auom/relational/less_than_or_equal_to_predicate_spec.rb +0 -4
- data/spec/unit/auom/relational/less_than_predicate_spec.rb +0 -4
- data/spec/unit/auom/unit/assert_same_unit_spec.rb +2 -6
- data/spec/unit/auom/unit/class_methods/convert_spec.rb +0 -4
- data/spec/unit/auom/unit/class_methods/lookup_spec.rb +2 -6
- data/spec/unit/auom/unit/class_methods/new_spec.rb +16 -21
- data/spec/unit/auom/unit/class_methods/try_convert_spec.rb +0 -4
- data/spec/unit/auom/unit/class_methods/units_spec.rb +0 -4
- data/spec/unit/auom/unit/denominators_spec.rb +0 -4
- data/spec/unit/auom/unit/numerators_spec.rb +0 -4
- data/spec/unit/auom/unit/same_unit_predicate_spec.rb +1 -5
- data/spec/unit/auom/unit/scalar_spec.rb +0 -4
- data/spec/unit/auom/unit/unit_spec.rb +0 -4
- data/spec/unit/auom/unit/unitless_predicate_spec.rb +0 -4
- metadata +29 -22
- data/Gemfile.devtools +0 -71
- data/Guardfile +0 -8
@@ -1,7 +1,3 @@
|
|
1
|
-
# encoding: UTF-8
|
2
|
-
|
3
|
-
require 'spec_helper'
|
4
|
-
|
5
1
|
describe AUOM::Algebra, '#multiply' do
|
6
2
|
subject { object.multiply(operand) }
|
7
3
|
|
@@ -11,27 +7,27 @@ describe AUOM::Algebra, '#multiply' do
|
|
11
7
|
let(:arguments) { [2] }
|
12
8
|
|
13
9
|
context 'when operand is a fixnum' do
|
14
|
-
let(:operand) {
|
10
|
+
let(:operand) { 3 }
|
15
11
|
|
16
12
|
it_should_behave_like 'an operation'
|
17
13
|
|
18
|
-
it { should eql(AUOM::Unit.new(
|
14
|
+
it { should eql(AUOM::Unit.new(6)) }
|
19
15
|
end
|
20
16
|
|
21
17
|
context 'when operand is a unitless unit' do
|
22
|
-
let(:operand) { AUOM::Unit.new(
|
18
|
+
let(:operand) { AUOM::Unit.new(3) }
|
23
19
|
|
24
20
|
it_should_behave_like 'an operation'
|
25
21
|
|
26
|
-
it { should eql(AUOM::Unit.new(
|
22
|
+
it { should eql(AUOM::Unit.new(6)) }
|
27
23
|
end
|
28
24
|
|
29
25
|
context 'when operand is a unitful unit' do
|
30
|
-
let(:operand) { AUOM::Unit.new(
|
26
|
+
let(:operand) { AUOM::Unit.new(3, :meter) }
|
31
27
|
|
32
28
|
it_should_behave_like 'an operation'
|
33
29
|
|
34
|
-
it { should eql(AUOM::Unit.new(
|
30
|
+
it { should eql(AUOM::Unit.new(6, :meter)) }
|
35
31
|
end
|
36
32
|
end
|
37
33
|
|
@@ -39,45 +35,45 @@ describe AUOM::Algebra, '#multiply' do
|
|
39
35
|
let(:arguments) { [2, :meter, :kilogramm] }
|
40
36
|
|
41
37
|
context 'when operand is a fixnum' do
|
42
|
-
let(:operand) {
|
38
|
+
let(:operand) { 3 }
|
43
39
|
|
44
40
|
it_should_behave_like 'an operation'
|
45
41
|
|
46
|
-
it { should eql(AUOM::Unit.new(
|
42
|
+
it { should eql(AUOM::Unit.new(6, :meter, :kilogramm)) }
|
47
43
|
end
|
48
44
|
|
49
45
|
context 'when operand is a unitless unit' do
|
50
|
-
let(:operand) { AUOM::Unit.new(
|
46
|
+
let(:operand) { AUOM::Unit.new(3) }
|
51
47
|
|
52
48
|
it_should_behave_like 'an operation'
|
53
49
|
|
54
|
-
it { should eql(AUOM::Unit.new(
|
50
|
+
it { should eql(AUOM::Unit.new(6, :meter, :kilogramm)) }
|
55
51
|
end
|
56
52
|
|
57
53
|
context 'when operand is a unitful unit' do
|
58
54
|
|
59
55
|
context 'and units get added to numerator' do
|
60
|
-
let(:operand) { AUOM::Unit.new(
|
56
|
+
let(:operand) { AUOM::Unit.new(3, :meter) }
|
61
57
|
|
62
58
|
it_should_behave_like 'an operation'
|
63
59
|
|
64
|
-
it { should eql(AUOM::Unit.new(
|
60
|
+
it { should eql(AUOM::Unit.new(6, %i[meter meter], :kilogramm)) }
|
65
61
|
end
|
66
62
|
|
67
63
|
context 'and units get added to denominator' do
|
68
|
-
let(:operand) { AUOM::Unit.new(
|
64
|
+
let(:operand) { AUOM::Unit.new(3, [], :euro) }
|
69
65
|
|
70
66
|
it_should_behave_like 'an operation'
|
71
67
|
|
72
|
-
it { should eql(AUOM::Unit.new(
|
68
|
+
it { should eql(AUOM::Unit.new(6, :meter, %i[euro kilogramm])) }
|
73
69
|
end
|
74
70
|
|
75
|
-
context 'and units
|
76
|
-
let(:operand) { AUOM::Unit.new(
|
71
|
+
context 'and units cancel each other' do
|
72
|
+
let(:operand) { AUOM::Unit.new(3, [], :meter) }
|
77
73
|
|
78
74
|
it_should_behave_like 'an operation'
|
79
75
|
|
80
|
-
it { should eql(AUOM::Unit.new(
|
76
|
+
it { should eql(AUOM::Unit.new(6, [], :kilogramm)) }
|
81
77
|
end
|
82
78
|
end
|
83
79
|
end
|
@@ -1,16 +1,12 @@
|
|
1
|
-
#
|
2
|
-
|
3
|
-
require 'spec_helper'
|
4
|
-
|
5
|
-
describe AUOM::Algebra, '#substract' do
|
6
|
-
subject { object.substract(operand) }
|
1
|
+
describe AUOM::Algebra, '#subtract' do
|
2
|
+
subject { object.subtract(operand) }
|
7
3
|
|
8
4
|
let(:object) { AUOM::Unit.new(*arguments) }
|
9
5
|
|
10
6
|
context 'when unit is unitless' do
|
11
7
|
let(:arguments) { [1] }
|
12
8
|
|
13
|
-
context 'and operand is
|
9
|
+
context 'and operand is an Integer' do
|
14
10
|
let(:operand) { 1 }
|
15
11
|
|
16
12
|
it_should_behave_like 'an operation'
|
@@ -34,7 +30,7 @@ describe AUOM::Algebra, '#substract' do
|
|
34
30
|
context 'when unit is unitful' do
|
35
31
|
let(:arguments) { [1, :meter] }
|
36
32
|
|
37
|
-
context 'and operand is
|
33
|
+
context 'and operand is an Integer' do
|
38
34
|
let(:operand) { 1 }
|
39
35
|
|
40
36
|
it_should_behave_like 'an incompatible operation'
|
@@ -1,7 +1,3 @@
|
|
1
|
-
# encoding: UTF-8
|
2
|
-
|
3
|
-
require 'spec_helper'
|
4
|
-
|
5
1
|
describe AUOM::Equalization, '#==' do
|
6
2
|
subject { object == other }
|
7
3
|
|
@@ -40,17 +36,17 @@ describe AUOM::Equalization, '#==' do
|
|
40
36
|
it { should be(true) }
|
41
37
|
end
|
42
38
|
|
43
|
-
context 'and scalar is
|
39
|
+
context 'and scalar is different' do
|
44
40
|
let(:scalar) { 2 }
|
45
41
|
it { should be(false) }
|
46
42
|
end
|
47
43
|
|
48
|
-
context 'and unit is
|
44
|
+
context 'and unit is different' do
|
49
45
|
let(:unit) { [:euro] }
|
50
46
|
it { should be(false) }
|
51
47
|
end
|
52
48
|
|
53
|
-
context 'and scalar and unit is
|
49
|
+
context 'and scalar and unit is different' do
|
54
50
|
let(:scalar) { 2 }
|
55
51
|
let(:unit) { [:euro] }
|
56
52
|
it { should be(false) }
|
@@ -1,7 +1,3 @@
|
|
1
|
-
# encoding: UTF-8
|
2
|
-
|
3
|
-
require 'spec_helper'
|
4
|
-
|
5
1
|
describe AUOM::Inspection, '.prettify_unit_part' do
|
6
2
|
subject { object.prettify_unit_part(part) }
|
7
3
|
|
@@ -9,21 +5,25 @@ describe AUOM::Inspection, '.prettify_unit_part' do
|
|
9
5
|
|
10
6
|
context 'with simple part' do
|
11
7
|
let(:part) { [:meter] }
|
8
|
+
|
12
9
|
it { should eql('meter') }
|
13
10
|
end
|
14
11
|
|
15
12
|
context 'with mixed part' do
|
16
|
-
let(:part) { [
|
13
|
+
let(:part) { %i[meter euro] }
|
14
|
+
|
17
15
|
it { should eql('euro*meter') }
|
18
16
|
end
|
19
17
|
|
20
18
|
context 'with complex part' do
|
21
|
-
let(:part) { [
|
19
|
+
let(:part) { %i[meter meter euro] }
|
20
|
+
|
22
21
|
it { should eql('meter^2*euro') }
|
23
22
|
end
|
24
23
|
|
25
24
|
context 'with very complex part' do
|
26
|
-
let(:part) { [
|
25
|
+
let(:part) { %i[meter meter euro euro kilogramm] }
|
26
|
+
|
27
27
|
it { should eql('euro^2*meter^2*kilogramm') }
|
28
28
|
end
|
29
29
|
end
|
@@ -1,7 +1,3 @@
|
|
1
|
-
# encoding: UTF-8
|
2
|
-
|
3
|
-
require 'spec_helper'
|
4
|
-
|
5
1
|
describe AUOM::Inspection, '#inspect' do
|
6
2
|
subject { object.inspect }
|
7
3
|
|
@@ -36,7 +32,7 @@ describe AUOM::Inspection, '#inspect' do
|
|
36
32
|
|
37
33
|
context 'when has numerator and denominator' do
|
38
34
|
let(:scalar) { Rational(1, 3) }
|
39
|
-
let(:unit)
|
35
|
+
let(:unit) { %i[euro meter] }
|
40
36
|
|
41
37
|
it { should eql('<AUOM::Unit @scalar=~0.3333 euro/meter>') }
|
42
38
|
end
|
@@ -1,13 +1,9 @@
|
|
1
|
-
# encoding: UTF-8
|
2
|
-
|
3
|
-
require 'spec_helper'
|
4
|
-
|
5
1
|
describe AUOM::Unit, '#assert_same_unit' do
|
6
2
|
|
7
3
|
subject { object.assert_same_unit(other) }
|
8
4
|
|
9
5
|
let(:object) { described_class.new(1, *unit) }
|
10
|
-
let(:unit) { [[
|
6
|
+
let(:unit) { [%i[meter], %i[euro]] }
|
11
7
|
|
12
8
|
context 'when units are the same' do
|
13
9
|
let(:other) { AUOM::Unit.new(2, :meter, :euro) }
|
@@ -15,7 +11,7 @@ describe AUOM::Unit, '#assert_same_unit' do
|
|
15
11
|
it { should be(object) }
|
16
12
|
end
|
17
13
|
|
18
|
-
context 'when units
|
14
|
+
context 'when units are not the same' do
|
19
15
|
let(:other) { AUOM::Unit.new(2, :meter) }
|
20
16
|
|
21
17
|
it_should_behave_like 'an incompatible operation'
|
@@ -1,9 +1,5 @@
|
|
1
|
-
# encoding: UTF-8
|
2
|
-
|
3
|
-
require 'spec_helper'
|
4
|
-
|
5
1
|
describe AUOM::Unit, '.lookup' do
|
6
|
-
subject { object.
|
2
|
+
subject { object.__send__(:lookup, value) }
|
7
3
|
|
8
4
|
let(:object) { described_class }
|
9
5
|
|
@@ -13,7 +9,7 @@ describe AUOM::Unit, '.lookup' do
|
|
13
9
|
it { should eql([1, :meter]) }
|
14
10
|
end
|
15
11
|
|
16
|
-
context 'with
|
12
|
+
context 'with inexistent symbol' do
|
17
13
|
let(:value) { :foo }
|
18
14
|
|
19
15
|
it 'should raise error' do
|
@@ -1,8 +1,4 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
require 'spec_helper'
|
4
|
-
|
5
|
-
describe AUOM::Unit, '#new' do
|
1
|
+
describe AUOM::Unit, '.new' do
|
6
2
|
let(:object) { described_class }
|
7
3
|
|
8
4
|
subject do
|
@@ -45,7 +41,7 @@ describe AUOM::Unit, '#new' do
|
|
45
41
|
end
|
46
42
|
end
|
47
43
|
|
48
|
-
context 'when argument is
|
44
|
+
context 'when argument is an Integer' do
|
49
45
|
let(:argument) { 1 }
|
50
46
|
|
51
47
|
it_should_behave_like 'unitless unit'
|
@@ -85,14 +81,14 @@ describe AUOM::Unit, '#new' do
|
|
85
81
|
end
|
86
82
|
|
87
83
|
context 'when argument is an array of valid units' do
|
88
|
-
let(:argument)
|
89
|
-
let(:expected_numerators) { [
|
84
|
+
let(:argument) { %i[kilogramm meter] }
|
85
|
+
let(:expected_numerators) { %i[kilogramm meter] }
|
90
86
|
|
91
87
|
it_should_behave_like 'valid unit'
|
92
88
|
end
|
93
89
|
|
94
90
|
context 'when argument is an array with invalid unit' do
|
95
|
-
let(:argument) { [
|
91
|
+
let(:argument) { %i[kilogramm nonsense] }
|
96
92
|
|
97
93
|
it_should_behave_like 'invalid unit'
|
98
94
|
end
|
@@ -105,8 +101,8 @@ describe AUOM::Unit, '#new' do
|
|
105
101
|
end
|
106
102
|
|
107
103
|
describe 'with scalar, numerator and denominator argument' do
|
108
|
-
let(:arguments)
|
109
|
-
let(:expected_numerators)
|
104
|
+
let(:arguments) { [1, :kilogramm, argument] }
|
105
|
+
let(:expected_numerators) { %i[kilogramm] }
|
110
106
|
|
111
107
|
context 'when argument is a valid unit' do
|
112
108
|
let(:argument) { :meter }
|
@@ -119,20 +115,20 @@ describe AUOM::Unit, '#new' do
|
|
119
115
|
let(:argument) { :kilometer }
|
120
116
|
|
121
117
|
let(:expected_denominators) { [:meter] }
|
122
|
-
let(:expected_scalar) {
|
118
|
+
let(:expected_scalar) { Rational(1, 1000) }
|
123
119
|
|
124
120
|
it_should_behave_like 'valid unit'
|
125
121
|
end
|
126
122
|
|
127
123
|
context 'when argument is an array of valid units' do
|
128
|
-
let(:argument)
|
129
|
-
let(:expected_denominators) { [
|
124
|
+
let(:argument) { %i[euro meter] }
|
125
|
+
let(:expected_denominators) { %i[euro meter] }
|
130
126
|
|
131
127
|
it_should_behave_like 'valid unit'
|
132
128
|
end
|
133
129
|
|
134
130
|
context 'when argument is an array with invalid unit' do
|
135
|
-
let(:argument) { [
|
131
|
+
let(:argument) { %i[euro nonsense] }
|
136
132
|
|
137
133
|
it_should_behave_like 'invalid unit'
|
138
134
|
end
|
@@ -145,12 +141,11 @@ describe AUOM::Unit, '#new' do
|
|
145
141
|
end
|
146
142
|
|
147
143
|
context 'when numerators and denominators overlap' do
|
148
|
-
let(:arguments)
|
149
|
-
let(:numerators)
|
150
|
-
let(:denominators)
|
151
|
-
|
152
|
-
let(:
|
153
|
-
let(:expected_denominators) { [:meter] }
|
144
|
+
let(:arguments) { [1, numerators, denominators] }
|
145
|
+
let(:numerators) { %i[kilogramm meter euro] }
|
146
|
+
let(:denominators) { %i[meter meter] }
|
147
|
+
let(:expected_numerators) { %i[euro kilogramm] }
|
148
|
+
let(:expected_denominators) { [:meter] }
|
154
149
|
|
155
150
|
it_should_behave_like 'valid unit'
|
156
151
|
end
|
@@ -1,7 +1,3 @@
|
|
1
|
-
# encoding: UTF-8
|
2
|
-
|
3
|
-
require 'spec_helper'
|
4
|
-
|
5
1
|
describe AUOM::Unit, '#same_unit?' do
|
6
2
|
|
7
3
|
subject { object.same_unit?(other) }
|
@@ -15,7 +11,7 @@ describe AUOM::Unit, '#same_unit?' do
|
|
15
11
|
it { should be(true) }
|
16
12
|
end
|
17
13
|
|
18
|
-
context 'when units
|
14
|
+
context 'when units are not the same' do
|
19
15
|
let(:other) { AUOM::Unit.new(2, :meter) }
|
20
16
|
|
21
17
|
it { should be(false) }
|