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,5 +1,7 @@
|
|
1
|
+
# encoding: UTF-8
|
2
|
+
|
1
3
|
shared_examples_for 'an incompatible operation' do
|
2
4
|
it 'should raise ArgumentError' do
|
3
|
-
expect { subject }.to raise_error(ArgumentError,'Incompatible units')
|
5
|
+
expect { subject }.to raise_error(ArgumentError, 'Incompatible units')
|
4
6
|
end
|
5
7
|
end
|
@@ -1,3 +1,5 @@
|
|
1
|
+
# encoding: UTF-8
|
2
|
+
|
1
3
|
shared_examples_for 'an operation' do
|
2
4
|
it 'returns a new object' do
|
3
5
|
object.should_not equal(subject)
|
@@ -8,7 +10,6 @@ shared_examples_for 'an operation' do
|
|
8
10
|
__memoized.delete(:subject)
|
9
11
|
should eql(first)
|
10
12
|
end
|
11
|
-
|
13
|
+
|
12
14
|
its(:scalar) { should be_kind_of(::Rational) }
|
13
15
|
end
|
14
|
-
|
data/spec/spec_helper.rb
CHANGED
@@ -1,6 +1,8 @@
|
|
1
|
+
# encoding: UTF-8
|
2
|
+
|
1
3
|
require 'spec_helper'
|
2
4
|
|
3
|
-
describe AUOM::Algebra,'#add' do
|
5
|
+
describe AUOM::Algebra, '#add' do
|
4
6
|
subject { object.add(operand) }
|
5
7
|
|
6
8
|
let(:object) { AUOM::Unit.new(*arguments) }
|
@@ -23,14 +25,14 @@ describe AUOM::Algebra,'#add' do
|
|
23
25
|
end
|
24
26
|
|
25
27
|
context 'and operand is a unitful unit' do
|
26
|
-
let(:operand) { AUOM::Unit.new(1
|
28
|
+
let(:operand) { AUOM::Unit.new(1, :meter) }
|
27
29
|
|
28
30
|
it_should_behave_like 'an incompatible operation'
|
29
31
|
end
|
30
32
|
end
|
31
33
|
|
32
34
|
context 'when unit is unitful' do
|
33
|
-
let(:arguments) { [1
|
35
|
+
let(:arguments) { [1, :meter, :euro] }
|
34
36
|
|
35
37
|
context 'and operand is a Fixnum' do
|
36
38
|
let(:operand) { 1 }
|
@@ -45,15 +47,15 @@ describe AUOM::Algebra,'#add' do
|
|
45
47
|
end
|
46
48
|
|
47
49
|
context 'and operand is a incompatible unit' do
|
48
|
-
let(:operand) { AUOM::Unit.new(1
|
50
|
+
let(:operand) { AUOM::Unit.new(1, :euro) }
|
49
51
|
|
50
52
|
it_should_behave_like 'an incompatible operation'
|
51
53
|
end
|
52
54
|
|
53
55
|
context 'and operand is a compatible unit' do
|
54
|
-
let(:operand) { AUOM::Unit.new(1
|
56
|
+
let(:operand) { AUOM::Unit.new(1, :meter, :euro) }
|
55
57
|
|
56
|
-
it { should eql(AUOM::Unit.new(2
|
58
|
+
it { should eql(AUOM::Unit.new(2, :meter, :euro)) }
|
57
59
|
end
|
58
60
|
end
|
59
61
|
end
|
@@ -1,15 +1,17 @@
|
|
1
|
+
# encoding: UTF-8
|
2
|
+
|
1
3
|
require 'spec_helper'
|
2
4
|
|
3
|
-
describe AUOM::Algebra,'#divide' do
|
5
|
+
describe AUOM::Algebra, '#divide' do
|
4
6
|
subject { object.divide(operand) }
|
5
7
|
|
6
8
|
let(:object) { AUOM::Unit.new(*arguments) }
|
7
9
|
|
8
10
|
context 'with unitless unit' do
|
9
|
-
let(:arguments) { [
|
11
|
+
let(:arguments) { [4] }
|
10
12
|
|
11
13
|
context 'when operand is a fixnum' do
|
12
|
-
let(:operand) {
|
14
|
+
let(:operand) { 2 }
|
13
15
|
|
14
16
|
it_should_behave_like 'an operation'
|
15
17
|
|
@@ -17,7 +19,7 @@ describe AUOM::Algebra,'#divide' do
|
|
17
19
|
end
|
18
20
|
|
19
21
|
context 'when operand is a unitless unit' do
|
20
|
-
let(:operand) { AUOM::Unit.new(
|
22
|
+
let(:operand) { AUOM::Unit.new(2) }
|
21
23
|
|
22
24
|
it_should_behave_like 'an operation'
|
23
25
|
|
@@ -25,23 +27,23 @@ describe AUOM::Algebra,'#divide' do
|
|
25
27
|
end
|
26
28
|
|
27
29
|
context 'when operand is a unitful unit' do
|
28
|
-
let(:operand) { AUOM::Unit.new(
|
30
|
+
let(:operand) { AUOM::Unit.new(2, :meter) }
|
29
31
|
|
30
32
|
it_should_behave_like 'an operation'
|
31
33
|
|
32
|
-
it { should eql(AUOM::Unit.new(2,[]
|
34
|
+
it { should eql(AUOM::Unit.new(2, [], :meter)) }
|
33
35
|
end
|
34
36
|
end
|
35
|
-
|
37
|
+
|
36
38
|
context 'with unitful unit' do
|
37
|
-
let(:arguments) { [2
|
39
|
+
let(:arguments) { [2, :meter] }
|
38
40
|
|
39
41
|
context 'when operand is a fixnum' do
|
40
42
|
let(:operand) { 1 }
|
41
43
|
|
42
44
|
it_should_behave_like 'an operation'
|
43
45
|
|
44
|
-
it { should eql(AUOM::Unit.new(2
|
46
|
+
it { should eql(AUOM::Unit.new(2, :meter)) }
|
45
47
|
end
|
46
48
|
|
47
49
|
context 'when operand is a unitless unit' do
|
@@ -49,26 +51,35 @@ describe AUOM::Algebra,'#divide' do
|
|
49
51
|
|
50
52
|
it_should_behave_like 'an operation'
|
51
53
|
|
52
|
-
it { should eql(AUOM::Unit.new(2
|
54
|
+
it { should eql(AUOM::Unit.new(2, :meter)) }
|
53
55
|
end
|
54
56
|
|
55
57
|
context 'when operand is a unitful unit' do
|
56
58
|
|
57
|
-
context 'and units
|
58
|
-
let(:operand) { AUOM::Unit.new(1
|
59
|
+
context 'and units get added to denominator' do
|
60
|
+
let(:operand) { AUOM::Unit.new(1, :euro) }
|
61
|
+
|
62
|
+
it_should_behave_like 'an operation'
|
63
|
+
|
64
|
+
it { should eql(AUOM::Unit.new(2, :meter, :euro)) }
|
65
|
+
end
|
66
|
+
|
67
|
+
context 'and units get added to numerator' do
|
68
|
+
let(:operand) { AUOM::Unit.new(1, nil, :euro) }
|
59
69
|
|
60
70
|
it_should_behave_like 'an operation'
|
61
71
|
|
62
|
-
it { should eql(AUOM::Unit.new(2
|
72
|
+
it { should eql(AUOM::Unit.new(2, [:euro, :meter])) }
|
63
73
|
end
|
64
74
|
|
65
|
-
context 'and
|
66
|
-
let(:operand) { AUOM::Unit.new(1
|
75
|
+
context 'and units cancle each other' do
|
76
|
+
let(:operand) { AUOM::Unit.new(1, :meter) }
|
67
77
|
|
68
78
|
it_should_behave_like 'an operation'
|
69
79
|
|
70
80
|
it { should eql(AUOM::Unit.new(2)) }
|
71
81
|
end
|
82
|
+
|
72
83
|
end
|
73
84
|
end
|
74
85
|
end
|
@@ -1,19 +1,21 @@
|
|
1
|
+
# encoding: UTF-8
|
2
|
+
|
1
3
|
require 'spec_helper'
|
2
4
|
|
3
|
-
describe AUOM::Algebra,'#multiply' do
|
5
|
+
describe AUOM::Algebra, '#multiply' do
|
4
6
|
subject { object.multiply(operand) }
|
5
7
|
|
6
8
|
let(:object) { AUOM::Unit.new(*arguments) }
|
7
9
|
|
8
10
|
context 'with unitless unit' do
|
9
|
-
let(:arguments) { [
|
11
|
+
let(:arguments) { [2] }
|
10
12
|
|
11
13
|
context 'when operand is a fixnum' do
|
12
14
|
let(:operand) { 2 }
|
13
15
|
|
14
16
|
it_should_behave_like 'an operation'
|
15
17
|
|
16
|
-
it { should eql(AUOM::Unit.new(
|
18
|
+
it { should eql(AUOM::Unit.new(4)) }
|
17
19
|
end
|
18
20
|
|
19
21
|
context 'when operand is a unitless unit' do
|
@@ -21,27 +23,27 @@ describe AUOM::Algebra,'#multiply' do
|
|
21
23
|
|
22
24
|
it_should_behave_like 'an operation'
|
23
25
|
|
24
|
-
it { should eql(AUOM::Unit.new(
|
26
|
+
it { should eql(AUOM::Unit.new(4)) }
|
25
27
|
end
|
26
28
|
|
27
29
|
context 'when operand is a unitful unit' do
|
28
|
-
let(:operand) { AUOM::Unit.new(2
|
30
|
+
let(:operand) { AUOM::Unit.new(2, :meter) }
|
29
31
|
|
30
32
|
it_should_behave_like 'an operation'
|
31
33
|
|
32
|
-
it { should eql(AUOM::Unit.new(
|
34
|
+
it { should eql(AUOM::Unit.new(4, :meter)) }
|
33
35
|
end
|
34
36
|
end
|
35
|
-
|
37
|
+
|
36
38
|
context 'with unitful unit' do
|
37
|
-
let(:arguments) { [
|
39
|
+
let(:arguments) { [2, :meter, :kilogramm] }
|
38
40
|
|
39
41
|
context 'when operand is a fixnum' do
|
40
42
|
let(:operand) { 2 }
|
41
43
|
|
42
44
|
it_should_behave_like 'an operation'
|
43
45
|
|
44
|
-
it { should eql(AUOM::Unit.new(
|
46
|
+
it { should eql(AUOM::Unit.new(4, :meter, :kilogramm)) }
|
45
47
|
end
|
46
48
|
|
47
49
|
context 'when operand is a unitless unit' do
|
@@ -49,25 +51,33 @@ describe AUOM::Algebra,'#multiply' do
|
|
49
51
|
|
50
52
|
it_should_behave_like 'an operation'
|
51
53
|
|
52
|
-
it { should eql(AUOM::Unit.new(
|
54
|
+
it { should eql(AUOM::Unit.new(4, :meter, :kilogramm)) }
|
53
55
|
end
|
54
56
|
|
55
57
|
context 'when operand is a unitful unit' do
|
56
58
|
|
57
|
-
context 'and units
|
58
|
-
let(:operand) { AUOM::Unit.new(2
|
59
|
+
context 'and units get added to numerator' do
|
60
|
+
let(:operand) { AUOM::Unit.new(2, :meter) }
|
61
|
+
|
62
|
+
it_should_behave_like 'an operation'
|
63
|
+
|
64
|
+
it { should eql(AUOM::Unit.new(4, [:meter, :meter], :kilogramm)) }
|
65
|
+
end
|
66
|
+
|
67
|
+
context 'and units get added to denominator' do
|
68
|
+
let(:operand) { AUOM::Unit.new(2, [], :euro) }
|
59
69
|
|
60
70
|
it_should_behave_like 'an operation'
|
61
71
|
|
62
|
-
it { should eql(AUOM::Unit.new(
|
72
|
+
it { should eql(AUOM::Unit.new(4, :meter, [:euro, :kilogramm])) }
|
63
73
|
end
|
64
74
|
|
65
75
|
context 'and units cancle each other' do
|
66
|
-
let(:operand) { AUOM::Unit.new(2,[]
|
76
|
+
let(:operand) { AUOM::Unit.new(2, [], :meter) }
|
67
77
|
|
68
78
|
it_should_behave_like 'an operation'
|
69
79
|
|
70
|
-
it { should eql(AUOM::Unit.new(
|
80
|
+
it { should eql(AUOM::Unit.new(4, [], :kilogramm)) }
|
71
81
|
end
|
72
82
|
end
|
73
83
|
end
|
@@ -1,6 +1,8 @@
|
|
1
|
+
# encoding: UTF-8
|
2
|
+
|
1
3
|
require 'spec_helper'
|
2
4
|
|
3
|
-
describe AUOM::Algebra,'#substract' do
|
5
|
+
describe AUOM::Algebra, '#substract' do
|
4
6
|
subject { object.substract(operand) }
|
5
7
|
|
6
8
|
let(:object) { AUOM::Unit.new(*arguments) }
|
@@ -23,14 +25,14 @@ describe AUOM::Algebra,'#substract' do
|
|
23
25
|
end
|
24
26
|
|
25
27
|
context 'and operand is a unitful unit' do
|
26
|
-
let(:operand) { AUOM::Unit.new(1
|
28
|
+
let(:operand) { AUOM::Unit.new(1, :meter) }
|
27
29
|
|
28
30
|
it_should_behave_like 'an incompatible operation'
|
29
31
|
end
|
30
32
|
end
|
31
33
|
|
32
34
|
context 'when unit is unitful' do
|
33
|
-
let(:arguments) { [1
|
35
|
+
let(:arguments) { [1, :meter] }
|
34
36
|
|
35
37
|
context 'and operand is a Fixnum' do
|
36
38
|
let(:operand) { 1 }
|
@@ -45,15 +47,15 @@ describe AUOM::Algebra,'#substract' do
|
|
45
47
|
end
|
46
48
|
|
47
49
|
context 'and operand is a incompatible unit' do
|
48
|
-
let(:operand) { AUOM::Unit.new(1
|
50
|
+
let(:operand) { AUOM::Unit.new(1, :euro) }
|
49
51
|
|
50
52
|
it_should_behave_like 'an incompatible operation'
|
51
53
|
end
|
52
54
|
|
53
55
|
context 'and operand is a compatible unit' do
|
54
|
-
let(:operand) { AUOM::Unit.new(1
|
56
|
+
let(:operand) { AUOM::Unit.new(1, :meter) }
|
55
57
|
|
56
|
-
it { should eql(AUOM::Unit.new(0
|
58
|
+
it { should eql(AUOM::Unit.new(0, :meter)) }
|
57
59
|
end
|
58
60
|
end
|
59
61
|
end
|
@@ -1,9 +1,11 @@
|
|
1
|
+
# encoding: UTF-8
|
2
|
+
|
1
3
|
require 'spec_helper'
|
2
4
|
|
3
|
-
describe AUOM::Equalization,'#==' do
|
5
|
+
describe AUOM::Equalization, '#==' do
|
4
6
|
subject { object == other }
|
5
7
|
|
6
|
-
let(:object) { AUOM::Unit.new(1
|
8
|
+
let(:object) { AUOM::Unit.new(1, :meter) }
|
7
9
|
|
8
10
|
context 'when is other kind of object' do
|
9
11
|
|
@@ -29,7 +31,7 @@ describe AUOM::Equalization,'#==' do
|
|
29
31
|
end
|
30
32
|
|
31
33
|
context 'when is same kind of object' do
|
32
|
-
let(:other) { AUOM::Unit.new(scalar
|
34
|
+
let(:other) { AUOM::Unit.new(scalar, *unit) }
|
33
35
|
|
34
36
|
let(:scalar) { 1 }
|
35
37
|
let(:unit) { [:meter] }
|
@@ -1,6 +1,8 @@
|
|
1
|
+
# encoding: UTF-8
|
2
|
+
|
1
3
|
require 'spec_helper'
|
2
4
|
|
3
|
-
describe AUOM::Inspection,'.prettify_unit_part' do
|
5
|
+
describe AUOM::Inspection, '.prettify_unit_part' do
|
4
6
|
subject { object.prettify_unit_part(part) }
|
5
7
|
|
6
8
|
let(:object) { AUOM::Inspection }
|
@@ -11,17 +13,17 @@ describe AUOM::Inspection,'.prettify_unit_part' do
|
|
11
13
|
end
|
12
14
|
|
13
15
|
context 'with mixed part' do
|
14
|
-
let(:part) { [:meter
|
16
|
+
let(:part) { [:meter, :euro] }
|
15
17
|
it { should eql('euro*meter') }
|
16
18
|
end
|
17
19
|
|
18
20
|
context 'with complex part' do
|
19
|
-
let(:part) { [:meter
|
21
|
+
let(:part) { [:meter, :meter, :euro] }
|
20
22
|
it { should eql('meter^2*euro') }
|
21
23
|
end
|
22
24
|
|
23
25
|
context 'with very complex part' do
|
24
|
-
let(:part) { [:meter
|
26
|
+
let(:part) { [:meter, :meter, :euro, :euro, :kilogramm] }
|
25
27
|
it { should eql('euro^2*meter^2*kilogramm') }
|
26
28
|
end
|
27
29
|
end
|
@@ -1,41 +1,43 @@
|
|
1
|
+
# encoding: UTF-8
|
2
|
+
|
1
3
|
require 'spec_helper'
|
2
4
|
|
3
|
-
describe AUOM::Inspection,'#inspect' do
|
5
|
+
describe AUOM::Inspection, '#inspect' do
|
4
6
|
subject { object.inspect }
|
5
7
|
|
6
|
-
let(:object) { AUOM::Unit.new(scalar
|
8
|
+
let(:object) { AUOM::Unit.new(scalar, *unit) }
|
7
9
|
let(:unit) { [] }
|
8
10
|
|
9
11
|
context 'when scalar is exact in decimal' do
|
10
12
|
let(:scalar) { 1 }
|
11
13
|
|
12
|
-
it { should eql(
|
14
|
+
it { should eql('<AUOM::Unit @scalar=1>') }
|
13
15
|
end
|
14
16
|
|
15
17
|
context 'when scalar is NOT exact in decimal' do
|
16
|
-
let(:scalar) { Rational(1,
|
18
|
+
let(:scalar) { Rational(1, 2) }
|
17
19
|
|
18
|
-
it { should eql(
|
20
|
+
it { should eql('<AUOM::Unit @scalar=~0.5000>') }
|
19
21
|
end
|
20
22
|
|
21
23
|
context 'when has only numerator' do
|
22
|
-
let(:scalar) { Rational(1,3) }
|
24
|
+
let(:scalar) { Rational(1, 3) }
|
23
25
|
let(:unit) { [:meter] }
|
24
26
|
|
25
|
-
it { should eql(
|
27
|
+
it { should eql('<AUOM::Unit @scalar=~0.3333 meter>') }
|
26
28
|
end
|
27
29
|
|
28
30
|
context 'when has only denominator' do
|
29
|
-
let(:scalar) { Rational(1,3) }
|
30
|
-
let(:unit) { [[]
|
31
|
+
let(:scalar) { Rational(1, 3) }
|
32
|
+
let(:unit) { [[], :meter] }
|
31
33
|
|
32
|
-
it { should eql(
|
34
|
+
it { should eql('<AUOM::Unit @scalar=~0.3333 1/meter>') }
|
33
35
|
end
|
34
36
|
|
35
37
|
context 'when has numerator and denominator' do
|
36
|
-
let(:scalar) { Rational(1,3) }
|
37
|
-
let(:unit) { [:euro
|
38
|
+
let(:scalar) { Rational(1, 3) }
|
39
|
+
let(:unit) { [:euro, :meter] }
|
38
40
|
|
39
|
-
it { should eql(
|
41
|
+
it { should eql('<AUOM::Unit @scalar=~0.3333 euro/meter>') }
|
40
42
|
end
|
41
43
|
end
|