auom 0.2.0 → 0.3.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.
Files changed (52) hide show
  1. checksums.yaml +5 -5
  2. data/.circleci/config.yml +18 -0
  3. data/.rubocop.yml +1 -1
  4. data/Changelog.md +5 -0
  5. data/Gemfile +2 -0
  6. data/Rakefile +2 -0
  7. data/auom.gemspec +6 -4
  8. data/config/devtools.yml +2 -0
  9. data/config/flay.yml +1 -1
  10. data/config/reek.yml +96 -97
  11. data/config/rubocop.yml +3 -0
  12. data/lib/auom.rb +2 -1
  13. data/lib/auom/algebra.rb +2 -0
  14. data/lib/auom/equalization.rb +2 -2
  15. data/lib/auom/inspection.rb +15 -10
  16. data/lib/auom/relational.rb +6 -76
  17. data/lib/auom/unit.rb +6 -8
  18. data/spec/shared/incompatible_operation_behavior.rb +2 -0
  19. data/spec/shared/operation_behavior.rb +3 -0
  20. data/spec/shared/sunits_shared.rb +2 -0
  21. data/spec/spec_helper.rb +2 -0
  22. data/spec/unit/auom/algebra_spec.rb +279 -0
  23. data/spec/unit/auom/{equalization/equality_operator_spec.rb → equalization_spec.rb} +2 -1
  24. data/spec/unit/auom/inspection_spec.rb +73 -0
  25. data/spec/unit/auom/relational_spec.rb +39 -0
  26. data/spec/unit/auom/unit_spec.rb +377 -0
  27. metadata +18 -57
  28. data/.circle.yml +0 -4
  29. data/TODO +0 -1
  30. data/spec/unit/auom/algebra/add_spec.rb +0 -57
  31. data/spec/unit/auom/algebra/divide_spec.rb +0 -83
  32. data/spec/unit/auom/algebra/multiply_spec.rb +0 -80
  33. data/spec/unit/auom/algebra/substract_spec.rb +0 -57
  34. data/spec/unit/auom/inspection/class_methods/prettify_unit_part_spec.rb +0 -29
  35. data/spec/unit/auom/inspection/inspect_spec.rb +0 -39
  36. data/spec/unit/auom/relational/greater_than_or_equal_to_predicate_spec.rb +0 -38
  37. data/spec/unit/auom/relational/greater_than_predicate_spec.rb +0 -38
  38. data/spec/unit/auom/relational/less_than_or_equal_to_predicate_spec.rb +0 -38
  39. data/spec/unit/auom/relational/less_than_predicate_spec.rb +0 -38
  40. data/spec/unit/auom/unit/assert_same_unit_spec.rb +0 -20
  41. data/spec/unit/auom/unit/class_methods/convert_spec.rb +0 -33
  42. data/spec/unit/auom/unit/class_methods/lookup_spec.rb +0 -19
  43. data/spec/unit/auom/unit/class_methods/new_spec.rb +0 -152
  44. data/spec/unit/auom/unit/class_methods/try_convert_spec.rb +0 -35
  45. data/spec/unit/auom/unit/class_methods/units_spec.rb +0 -9
  46. data/spec/unit/auom/unit/denominators_spec.rb +0 -14
  47. data/spec/unit/auom/unit/numerators_spec.rb +0 -14
  48. data/spec/unit/auom/unit/same_unit_predicate_spec.rb +0 -20
  49. data/spec/unit/auom/unit/scalar_spec.rb +0 -14
  50. data/spec/unit/auom/unit/unit +0 -0
  51. data/spec/unit/auom/unit/unit_spec.rb +0 -14
  52. data/spec/unit/auom/unit/unitless_predicate_spec.rb +0 -22
@@ -1,38 +0,0 @@
1
- describe AUOM::Relational, '#less_than?' do
2
-
3
- subject { object.less_than?(operand) }
4
-
5
- let(:object) { AUOM::Unit.new(1, :meter) }
6
-
7
- let(:operand) { AUOM::Unit.new(scalar, unit) }
8
-
9
- context 'when operand unit is the same' do
10
-
11
- let(:unit) { :meter }
12
-
13
- context 'and operand scalar is less than receiver scalar' do
14
- let(:scalar) { 0 }
15
-
16
- it { should be(false) }
17
- end
18
-
19
- context 'and operand scalar is equal to receiver scalar' do
20
- let(:scalar) { 1 }
21
-
22
- it { should be(false) }
23
- end
24
-
25
- context 'and operand scalar is greater than receiver scalar' do
26
- let(:scalar) { 2 }
27
-
28
- it { should be(true) }
29
- end
30
- end
31
-
32
- context 'when operand unit is not the same' do
33
- let(:scalar) { 1 }
34
- let(:unit) { :euro }
35
-
36
- it_should_behave_like 'an incompatible operation'
37
- end
38
- end
@@ -1,20 +0,0 @@
1
- describe AUOM::Unit, '#assert_same_unit' do
2
-
3
- subject { object.assert_same_unit(other) }
4
-
5
- let(:object) { described_class.new(1, *unit) }
6
- let(:unit) { [%i[meter], %i[euro]] }
7
-
8
- context 'when units are the same' do
9
- let(:other) { AUOM::Unit.new(2, :meter, :euro) }
10
-
11
- it { should be(object) }
12
- end
13
-
14
- context 'when units are not the same' do
15
- let(:other) { AUOM::Unit.new(2, :meter) }
16
-
17
- it_should_behave_like 'an incompatible operation'
18
- end
19
-
20
- end
@@ -1,33 +0,0 @@
1
- describe AUOM::Unit, '.convert' do
2
- subject { object.convert(value) }
3
-
4
- let(:object) { AUOM::Unit }
5
-
6
- context 'with nil' do
7
- let(:value) { nil }
8
-
9
- it 'should raise error' do
10
- expect { subject }.to raise_error(ArgumentError, 'Cannot convert nil to AUOM::Unit')
11
- end
12
- end
13
-
14
- context 'with fixnum' do
15
- let(:value) { 1 }
16
-
17
- it { should eql(AUOM::Unit.new(1)) }
18
- end
19
-
20
- context 'with rational' do
21
- let(:value) { Rational(2, 1) }
22
-
23
- it { should eql(AUOM::Unit.new(2)) }
24
- end
25
-
26
- context 'with Object' do
27
- let(:value) { Object.new }
28
-
29
- it 'should raise error' do
30
- expect { subject }.to raise_error(ArgumentError, "Cannot convert #{value.inspect} to AUOM::Unit")
31
- end
32
- end
33
- end
@@ -1,19 +0,0 @@
1
- describe AUOM::Unit, '.lookup' do
2
- subject { object.__send__(:lookup, value) }
3
-
4
- let(:object) { described_class }
5
-
6
- context 'with existing symbol' do
7
- let(:value) { :meter }
8
-
9
- it { should eql([1, :meter]) }
10
- end
11
-
12
- context 'with inexistent symbol' do
13
- let(:value) { :foo }
14
-
15
- it 'should raise error' do
16
- expect { subject }.to raise_error(ArgumentError, 'Unknown unit :foo')
17
- end
18
- end
19
- end
@@ -1,152 +0,0 @@
1
- describe AUOM::Unit, '.new' do
2
- let(:object) { described_class }
3
-
4
- subject do
5
- described_class.new(*arguments)
6
- end
7
-
8
- shared_examples_for 'invalid unit' do
9
- it 'should raise ArgumentError' do
10
- expect { subject }.to raise_error(ArgumentError)
11
- end
12
- end
13
-
14
- let(:expected_scalar) { 1 }
15
- let(:expected_numerators) { [] }
16
- let(:expected_denominators) { [] }
17
-
18
- shared_examples_for 'valid unit' do
19
- it { should be_frozen }
20
-
21
- its(:scalar) { should == expected_scalar }
22
- its(:scalar) { should be_frozen }
23
- its(:numerators) { should == expected_numerators }
24
- its(:numerators) { should be_frozen }
25
- its(:denominators) { should == expected_denominators }
26
- its(:denominators) { should be_frozen }
27
- end
28
-
29
- describe 'without arguments' do
30
- let(:arguments) { [] }
31
- it_should_behave_like 'invalid unit'
32
- end
33
-
34
- describe 'with one scalar argument' do
35
- let(:arguments) { [argument] }
36
-
37
- context 'when scalar is a string' do
38
- let(:argument) { '10.31' }
39
- it 'should raise error' do
40
- expect { subject }.to raise_error(ArgumentError, '"10.31" cannot be converted to rational')
41
- end
42
- end
43
-
44
- context 'when argument is an Integer' do
45
- let(:argument) { 1 }
46
-
47
- it_should_behave_like 'unitless unit'
48
- it_should_behave_like 'valid unit'
49
- end
50
-
51
- context 'when argument is a Rational' do
52
- let(:argument) { Rational(1, 1) }
53
-
54
- it_should_behave_like 'unitless unit'
55
- it_should_behave_like 'valid unit'
56
- end
57
-
58
- context 'when argument is something else' do
59
- let(:argument) { 1.0 }
60
-
61
- it_should_behave_like 'invalid unit'
62
- end
63
- end
64
-
65
- describe 'with scalar and numerator argument' do
66
- let(:arguments) { [1, argument] }
67
-
68
- context 'when argument is a valid unit' do
69
- let(:argument) { :kilogramm }
70
- let(:expected_numerators) { [:kilogramm] }
71
-
72
- it_should_behave_like 'valid unit'
73
- end
74
-
75
- context 'when argument is a valid unit alias' do
76
- let(:argument) { :kilometer }
77
- let(:expected_numerators) { [:meter] }
78
- let(:expected_scalar) { 1000 }
79
-
80
- it_should_behave_like 'valid unit'
81
- end
82
-
83
- context 'when argument is an array of valid units' do
84
- let(:argument) { %i[kilogramm meter] }
85
- let(:expected_numerators) { %i[kilogramm meter] }
86
-
87
- it_should_behave_like 'valid unit'
88
- end
89
-
90
- context 'when argument is an array with invalid unit' do
91
- let(:argument) { %i[kilogramm nonsense] }
92
-
93
- it_should_behave_like 'invalid unit'
94
- end
95
-
96
- context 'when argument is an invalid unit' do
97
- let(:argument) { :nonsense }
98
-
99
- it_should_behave_like 'invalid unit'
100
- end
101
- end
102
-
103
- describe 'with scalar, numerator and denominator argument' do
104
- let(:arguments) { [1, :kilogramm, argument] }
105
- let(:expected_numerators) { %i[kilogramm] }
106
-
107
- context 'when argument is a valid unit' do
108
- let(:argument) { :meter }
109
- let(:expected_denominators) { [:meter] }
110
-
111
- it_should_behave_like 'valid unit'
112
- end
113
-
114
- context 'when argument is a valid unit alias' do
115
- let(:argument) { :kilometer }
116
-
117
- let(:expected_denominators) { [:meter] }
118
- let(:expected_scalar) { Rational(1, 1000) }
119
-
120
- it_should_behave_like 'valid unit'
121
- end
122
-
123
- context 'when argument is an array of valid units' do
124
- let(:argument) { %i[euro meter] }
125
- let(:expected_denominators) { %i[euro meter] }
126
-
127
- it_should_behave_like 'valid unit'
128
- end
129
-
130
- context 'when argument is an array with invalid unit' do
131
- let(:argument) { %i[euro nonsense] }
132
-
133
- it_should_behave_like 'invalid unit'
134
- end
135
-
136
- context 'when argument is an invalid unit' do
137
- let(:argument) { :nonsense }
138
-
139
- it_should_behave_like 'invalid unit'
140
- end
141
- end
142
-
143
- context 'when numerators and denominators overlap' do
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] }
149
-
150
- it_should_behave_like 'valid unit'
151
- end
152
- end
@@ -1,35 +0,0 @@
1
- describe AUOM::Unit, '.try_convert' do
2
- subject { object.try_convert(value) }
3
-
4
- let(:object) { AUOM::Unit }
5
-
6
- context 'with unit' do
7
- let(:value) { AUOM::Unit.new(1) }
8
-
9
- it { should be(value) }
10
- end
11
-
12
- context 'with nil' do
13
- let(:value) { nil }
14
-
15
- it { should be(nil) }
16
- end
17
-
18
- context 'with fixnum' do
19
- let(:value) { 1 }
20
-
21
- it { should eql(AUOM::Unit.new(1)) }
22
- end
23
-
24
- context 'with rational' do
25
- let(:value) { Rational(2, 1) }
26
-
27
- it { should eql(AUOM::Unit.new(2)) }
28
- end
29
-
30
- context 'with Object' do
31
- let(:value) { Object.new }
32
-
33
- it { should be(nil) }
34
- end
35
- end
@@ -1,9 +0,0 @@
1
- describe AUOM::Unit, '.units' do
2
- subject { object.units }
3
-
4
- let(:object) { described_class }
5
-
6
- it { should be_a(Hash) }
7
-
8
- it_should_behave_like 'an idempotent method'
9
- end
@@ -1,14 +0,0 @@
1
- describe AUOM::Unit, '#denominators' do
2
- subject { object.denominators }
3
-
4
- let(:object) { described_class.new(1, *unit) }
5
- let(:unit) { [[:meter], [:euro]] }
6
-
7
- it 'should return denominators' do
8
- should eql([:euro])
9
- end
10
-
11
- it { should be_frozen }
12
-
13
- it_should_behave_like 'an idempotent method'
14
- end
@@ -1,14 +0,0 @@
1
- describe AUOM::Unit, '#numerators' do
2
- subject { object.numerators }
3
-
4
- let(:object) { described_class.new(1, *unit) }
5
- let(:unit) { [[:meter], [:euro]] }
6
-
7
- it 'should return numerators' do
8
- should eql([:meter])
9
- end
10
-
11
- it { should be_frozen }
12
-
13
- it_should_behave_like 'an idempotent method'
14
- end
@@ -1,20 +0,0 @@
1
- describe AUOM::Unit, '#same_unit?' do
2
-
3
- subject { object.same_unit?(other) }
4
-
5
- let(:object) { described_class.new(1, *unit) }
6
- let(:unit) { [[:meter], [:euro]] }
7
-
8
- context 'when units are the same' do
9
- let(:other) { AUOM::Unit.new(2, :meter, :euro) }
10
-
11
- it { should be(true) }
12
- end
13
-
14
- context 'when units are not the same' do
15
- let(:other) { AUOM::Unit.new(2, :meter) }
16
-
17
- it { should be(false) }
18
- end
19
-
20
- end
@@ -1,14 +0,0 @@
1
- describe AUOM::Unit, '#denominators' do
2
- subject { object.scalar }
3
-
4
- let(:object) { described_class.new(scalar) }
5
- let(:scalar) { Rational(1, 2) }
6
-
7
- it 'should return scalar' do
8
- should eql(scalar)
9
- end
10
-
11
- it { should be_frozen }
12
-
13
- it_should_behave_like 'an idempotent method'
14
- end
File without changes
@@ -1,14 +0,0 @@
1
- describe AUOM::Unit, '#unit' do
2
- subject { object.unit }
3
-
4
- let(:object) { described_class.new(1, *unit) }
5
- let(:unit) { [[:meter], [:euro]] }
6
-
7
- it 'should return unit of unit instance' do
8
- should eql(unit)
9
- end
10
-
11
- it { should be_frozen }
12
-
13
- it_should_behave_like 'an idempotent method'
14
- end
@@ -1,22 +0,0 @@
1
- describe AUOM::Unit, '#unitless?' do
2
- subject { object.unitless? }
3
-
4
- let(:object) { described_class.new(1, *unit) }
5
-
6
- context 'when unit is unitless' do
7
- let(:unit) { [] }
8
- it { should be(true) }
9
- end
10
-
11
- context 'when unit has no denominator' do
12
- let(:unit) { [:meter] }
13
-
14
- it { should be(false) }
15
- end
16
-
17
- context 'when unit has no numerator' do
18
- let(:unit) { [[], :meter] }
19
-
20
- it { should be(false) }
21
- end
22
- end