auom 0.1.0 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (50) hide show
  1. checksums.yaml +7 -0
  2. data/.rspec +1 -0
  3. data/.rubocop.yml +2 -6
  4. data/.travis.yml +5 -2
  5. data/Changelog.md +5 -1
  6. data/Gemfile +0 -5
  7. data/README.md +17 -22
  8. data/TODO +1 -1
  9. data/auom.gemspec +14 -14
  10. data/circle.yml +3 -0
  11. data/config/flay.yml +1 -1
  12. data/config/flog.yml +1 -1
  13. data/config/reek.yml +2 -1
  14. data/config/rubocop.yml +130 -34
  15. data/lib/auom.rb +0 -2
  16. data/lib/auom/algebra.rb +5 -7
  17. data/lib/auom/equalization.rb +0 -2
  18. data/lib/auom/inspection.rb +26 -23
  19. data/lib/auom/relational.rb +2 -4
  20. data/lib/auom/unit.rb +15 -17
  21. data/spec/shared/incompatible_operation_behavior.rb +0 -2
  22. data/spec/shared/operation_behavior.rb +5 -4
  23. data/spec/shared/sunits_shared.rb +0 -2
  24. data/spec/spec_helper.rb +1 -4
  25. data/spec/unit/auom/algebra/add_spec.rb +12 -16
  26. data/spec/unit/auom/algebra/divide_spec.rb +50 -52
  27. data/spec/unit/auom/algebra/multiply_spec.rb +17 -21
  28. data/spec/unit/auom/algebra/substract_spec.rb +4 -8
  29. data/spec/unit/auom/equalization/equality_operator_spec.rb +3 -7
  30. data/spec/unit/auom/inspection/class_methods/prettify_unit_part_spec.rb +7 -7
  31. data/spec/unit/auom/inspection/inspect_spec.rb +1 -5
  32. data/spec/unit/auom/relational/greater_than_or_equal_to_predicate_spec.rb +0 -4
  33. data/spec/unit/auom/relational/greater_than_predicate_spec.rb +0 -4
  34. data/spec/unit/auom/relational/less_than_or_equal_to_predicate_spec.rb +0 -4
  35. data/spec/unit/auom/relational/less_than_predicate_spec.rb +0 -4
  36. data/spec/unit/auom/unit/assert_same_unit_spec.rb +2 -6
  37. data/spec/unit/auom/unit/class_methods/convert_spec.rb +0 -4
  38. data/spec/unit/auom/unit/class_methods/lookup_spec.rb +2 -6
  39. data/spec/unit/auom/unit/class_methods/new_spec.rb +16 -21
  40. data/spec/unit/auom/unit/class_methods/try_convert_spec.rb +0 -4
  41. data/spec/unit/auom/unit/class_methods/units_spec.rb +0 -4
  42. data/spec/unit/auom/unit/denominators_spec.rb +0 -4
  43. data/spec/unit/auom/unit/numerators_spec.rb +0 -4
  44. data/spec/unit/auom/unit/same_unit_predicate_spec.rb +1 -5
  45. data/spec/unit/auom/unit/scalar_spec.rb +0 -4
  46. data/spec/unit/auom/unit/unit_spec.rb +0 -4
  47. data/spec/unit/auom/unit/unitless_predicate_spec.rb +0 -4
  48. metadata +29 -22
  49. data/Gemfile.devtools +0 -71
  50. 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) { 2 }
10
+ let(:operand) { 3 }
15
11
 
16
12
  it_should_behave_like 'an operation'
17
13
 
18
- it { should eql(AUOM::Unit.new(4)) }
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(2) }
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(4)) }
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(2, :meter) }
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(4, :meter)) }
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) { 2 }
38
+ let(:operand) { 3 }
43
39
 
44
40
  it_should_behave_like 'an operation'
45
41
 
46
- it { should eql(AUOM::Unit.new(4, :meter, :kilogramm)) }
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(2) }
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(4, :meter, :kilogramm)) }
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(2, :meter) }
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(4, [:meter, :meter], :kilogramm)) }
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(2, [], :euro) }
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(4, :meter, [:euro, :kilogramm])) }
68
+ it { should eql(AUOM::Unit.new(6, :meter, %i[euro kilogramm])) }
73
69
  end
74
70
 
75
- context 'and units cancle each other' do
76
- let(:operand) { AUOM::Unit.new(2, [], :meter) }
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(4, [], :kilogramm)) }
76
+ it { should eql(AUOM::Unit.new(6, [], :kilogramm)) }
81
77
  end
82
78
  end
83
79
  end
@@ -1,16 +1,12 @@
1
- # encoding: UTF-8
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 a Fixnum' do
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 a Fixnum' do
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 differend' do
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 differend' do
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 differend' do
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) { [:meter, :euro] }
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) { [:meter, :meter, :euro] }
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) { [:meter, :meter, :euro, :euro, :kilogramm] }
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) { [:euro, :meter] }
35
+ let(:unit) { %i[euro meter] }
40
36
 
41
37
  it { should eql('<AUOM::Unit @scalar=~0.3333 euro/meter>') }
42
38
  end
@@ -1,7 +1,3 @@
1
- # encoding: UTF-8
2
-
3
- require 'spec_helper'
4
-
5
1
  describe AUOM::Relational, '#greater_than_or_equal_to?' do
6
2
 
7
3
  subject { object.greater_than_or_equal_to?(operand) }
@@ -1,7 +1,3 @@
1
- # encoding: UTF-8
2
-
3
- require 'spec_helper'
4
-
5
1
  describe AUOM::Relational, '#greater_than?' do
6
2
 
7
3
  subject { object.greater_than?(operand) }
@@ -1,7 +1,3 @@
1
- # encoding: UTF-8
2
-
3
- require 'spec_helper'
4
-
5
1
  describe AUOM::Relational, '#less_than_or_equal_to?' do
6
2
 
7
3
  subject { object.less_than_or_equal_to?(operand) }
@@ -1,7 +1,3 @@
1
- # encoding: UTF-8
2
-
3
- require 'spec_helper'
4
-
5
1
  describe AUOM::Relational, '#less_than?' do
6
2
 
7
3
  subject { object.less_than?(operand) }
@@ -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) { [[:meter], [:euro]] }
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 arent the same' do
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,7 +1,3 @@
1
- # encoding: UTF-8
2
-
3
- require 'spec_helper'
4
-
5
1
  describe AUOM::Unit, '.convert' do
6
2
  subject { object.convert(value) }
7
3
 
@@ -1,9 +1,5 @@
1
- # encoding: UTF-8
2
-
3
- require 'spec_helper'
4
-
5
1
  describe AUOM::Unit, '.lookup' do
6
- subject { object.send(:lookup, value) }
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 inexisting symbol' do
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
- # encoding: UTF-8
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 a Fixnum' do
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) { [:kilogramm, :meter] }
89
- let(:expected_numerators) { [:kilogramm, :meter] }
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) { [:kilogramm, :nonsense] }
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) { [1, :kilogramm, argument] }
109
- let(:expected_numerators) { [:kilogramm] }
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) { Rational(1, 1000) }
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) { [:euro, :meter] }
129
- let(:expected_denominators) { [:euro, :meter] }
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) { [:euro, :nonsense] }
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) { [1, numerators, denominators] }
149
- let(:numerators) { [:kilogramm, :meter, :euro] }
150
- let(:denominators) { [:meter, :meter] }
151
-
152
- let(:expected_numerators) { [:euro, :kilogramm] }
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, '.try_convert' do
6
2
  subject { object.try_convert(value) }
7
3
 
@@ -1,7 +1,3 @@
1
- # encoding: UTF-8
2
-
3
- require 'spec_helper'
4
-
5
1
  describe AUOM::Unit, '.units' do
6
2
  subject { object.units }
7
3
 
@@ -1,7 +1,3 @@
1
- # encoding: UTF-8
2
-
3
- require 'spec_helper'
4
-
5
1
  describe AUOM::Unit, '#denominators' do
6
2
  subject { object.denominators }
7
3
 
@@ -1,7 +1,3 @@
1
- # encoding: UTF-8
2
-
3
- require 'spec_helper'
4
-
5
1
  describe AUOM::Unit, '#numerators' do
6
2
  subject { object.numerators }
7
3
 
@@ -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 arent the same' do
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) }
@@ -1,7 +1,3 @@
1
- # encoding: UTF-8
2
-
3
- require 'spec_helper'
4
-
5
1
  describe AUOM::Unit, '#denominators' do
6
2
  subject { object.scalar }
7
3