auom 0.2.0 → 0.3.0

Sign up to get free protection for your applications and to get access to all the features.
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,4 +0,0 @@
1
- ---
2
- test:
3
- override:
4
- - bundle exec rake ci
data/TODO DELETED
@@ -1 +0,0 @@
1
- * Make built-in units configurable
@@ -1,57 +0,0 @@
1
- describe AUOM::Algebra, '#add' do
2
- subject { object.add(operand) }
3
-
4
- let(:object) { AUOM::Unit.new(*arguments) }
5
-
6
- context 'when unit is unitless' do
7
- let(:arguments) { [1] }
8
-
9
- context 'and operand is an Integer' do
10
- let(:operand) { 2 }
11
-
12
- it_should_behave_like 'an operation'
13
-
14
- it { should eql(AUOM::Unit.new(3)) }
15
- end
16
-
17
- context 'and operand is a unitless unit' do
18
- let(:operand) { AUOM::Unit.new(2) }
19
-
20
- it { should eql(AUOM::Unit.new(3)) }
21
- end
22
-
23
- context 'and operand is a unitful unit' do
24
- let(:operand) { AUOM::Unit.new(2, :meter) }
25
-
26
- it_should_behave_like 'an incompatible operation'
27
- end
28
- end
29
-
30
- context 'when unit is unitful' do
31
- let(:arguments) { [1, :meter, :euro] }
32
-
33
- context 'and operand is an Integer' do
34
- let(:operand) { 2 }
35
-
36
- it_should_behave_like 'an incompatible operation'
37
- end
38
-
39
- context 'and operand is a unitless unit' do
40
- let(:operand) { AUOM::Unit.new(2) }
41
-
42
- it_should_behave_like 'an incompatible operation'
43
- end
44
-
45
- context 'and operand is a incompatible unit' do
46
- let(:operand) { AUOM::Unit.new(2, :euro) }
47
-
48
- it_should_behave_like 'an incompatible operation'
49
- end
50
-
51
- context 'and operand is a compatible unit' do
52
- let(:operand) { AUOM::Unit.new(2, :meter, :euro) }
53
-
54
- it { should eql(AUOM::Unit.new(3, :meter, :euro)) }
55
- end
56
- end
57
- end
@@ -1,83 +0,0 @@
1
- describe AUOM::Algebra do
2
- describe '#divide' do
3
- subject { object.divide(operand) }
4
-
5
- let(:object) { AUOM::Unit.new(*arguments) }
6
-
7
- context 'with unitless unit' do
8
- let(:arguments) { [4] }
9
-
10
- context 'when operand is a fixnum' do
11
- let(:operand) { 2 }
12
-
13
- it_should_behave_like 'an operation'
14
-
15
- it { should eql(AUOM::Unit.new(2)) }
16
- end
17
-
18
- context 'when operand is a unitless unit' do
19
- let(:operand) { AUOM::Unit.new(2) }
20
-
21
- it_should_behave_like 'an operation'
22
-
23
- it { should eql(AUOM::Unit.new(2)) }
24
- end
25
-
26
- context 'when operand is a unitful unit' do
27
- let(:operand) { AUOM::Unit.new(2, :meter) }
28
-
29
- it_should_behave_like 'an operation'
30
-
31
- it { should eql(AUOM::Unit.new(2, [], :meter)) }
32
- end
33
- end
34
-
35
- context 'with unitful unit' do
36
- let(:arguments) { [2, :meter] }
37
-
38
- context 'when operand is a fixnum' do
39
- let(:operand) { 1 }
40
-
41
- it_should_behave_like 'an operation'
42
-
43
- it { should eql(AUOM::Unit.new(2, :meter)) }
44
- end
45
-
46
- context 'when operand is a unitless unit' do
47
- let(:operand) { AUOM::Unit.new(1) }
48
-
49
- it_should_behave_like 'an operation'
50
-
51
- it { should eql(AUOM::Unit.new(2, :meter)) }
52
- end
53
-
54
- context 'when operand is a unitful unit' do
55
-
56
- context 'and units get added to denominator' do
57
- let(:operand) { AUOM::Unit.new(1, :euro) }
58
-
59
- it_should_behave_like 'an operation'
60
-
61
- it { should eql(AUOM::Unit.new(2, :meter, :euro)) }
62
- end
63
-
64
- context 'and units get added to numerator' do
65
- let(:operand) { AUOM::Unit.new(1, nil, :euro) }
66
-
67
- it_should_behave_like 'an operation'
68
-
69
- it { should eql(AUOM::Unit.new(2, %i[euro meter])) }
70
- end
71
-
72
- context 'and units cancel each other' do
73
- let(:operand) { AUOM::Unit.new(1, :meter) }
74
-
75
- it_should_behave_like 'an operation'
76
-
77
- it { should eql(AUOM::Unit.new(2)) }
78
- end
79
-
80
- end
81
- end
82
- end
83
- end
@@ -1,80 +0,0 @@
1
- describe AUOM::Algebra, '#multiply' do
2
- subject { object.multiply(operand) }
3
-
4
- let(:object) { AUOM::Unit.new(*arguments) }
5
-
6
- context 'with unitless unit' do
7
- let(:arguments) { [2] }
8
-
9
- context 'when operand is a fixnum' do
10
- let(:operand) { 3 }
11
-
12
- it_should_behave_like 'an operation'
13
-
14
- it { should eql(AUOM::Unit.new(6)) }
15
- end
16
-
17
- context 'when operand is a unitless unit' do
18
- let(:operand) { AUOM::Unit.new(3) }
19
-
20
- it_should_behave_like 'an operation'
21
-
22
- it { should eql(AUOM::Unit.new(6)) }
23
- end
24
-
25
- context 'when operand is a unitful unit' do
26
- let(:operand) { AUOM::Unit.new(3, :meter) }
27
-
28
- it_should_behave_like 'an operation'
29
-
30
- it { should eql(AUOM::Unit.new(6, :meter)) }
31
- end
32
- end
33
-
34
- context 'with unitful unit' do
35
- let(:arguments) { [2, :meter, :kilogramm] }
36
-
37
- context 'when operand is a fixnum' do
38
- let(:operand) { 3 }
39
-
40
- it_should_behave_like 'an operation'
41
-
42
- it { should eql(AUOM::Unit.new(6, :meter, :kilogramm)) }
43
- end
44
-
45
- context 'when operand is a unitless unit' do
46
- let(:operand) { AUOM::Unit.new(3) }
47
-
48
- it_should_behave_like 'an operation'
49
-
50
- it { should eql(AUOM::Unit.new(6, :meter, :kilogramm)) }
51
- end
52
-
53
- context 'when operand is a unitful unit' do
54
-
55
- context 'and units get added to numerator' do
56
- let(:operand) { AUOM::Unit.new(3, :meter) }
57
-
58
- it_should_behave_like 'an operation'
59
-
60
- it { should eql(AUOM::Unit.new(6, %i[meter meter], :kilogramm)) }
61
- end
62
-
63
- context 'and units get added to denominator' do
64
- let(:operand) { AUOM::Unit.new(3, [], :euro) }
65
-
66
- it_should_behave_like 'an operation'
67
-
68
- it { should eql(AUOM::Unit.new(6, :meter, %i[euro kilogramm])) }
69
- end
70
-
71
- context 'and units cancel each other' do
72
- let(:operand) { AUOM::Unit.new(3, [], :meter) }
73
-
74
- it_should_behave_like 'an operation'
75
-
76
- it { should eql(AUOM::Unit.new(6, [], :kilogramm)) }
77
- end
78
- end
79
- end
80
- end
@@ -1,57 +0,0 @@
1
- describe AUOM::Algebra, '#subtract' do
2
- subject { object.subtract(operand) }
3
-
4
- let(:object) { AUOM::Unit.new(*arguments) }
5
-
6
- context 'when unit is unitless' do
7
- let(:arguments) { [1] }
8
-
9
- context 'and operand is an Integer' do
10
- let(:operand) { 1 }
11
-
12
- it_should_behave_like 'an operation'
13
-
14
- it { should eql(AUOM::Unit.new(0)) }
15
- end
16
-
17
- context 'and operand is a unitless unit' do
18
- let(:operand) { AUOM::Unit.new(1) }
19
-
20
- it { should eql(AUOM::Unit.new(0)) }
21
- end
22
-
23
- context 'and operand is a unitful unit' do
24
- let(:operand) { AUOM::Unit.new(1, :meter) }
25
-
26
- it_should_behave_like 'an incompatible operation'
27
- end
28
- end
29
-
30
- context 'when unit is unitful' do
31
- let(:arguments) { [1, :meter] }
32
-
33
- context 'and operand is an Integer' do
34
- let(:operand) { 1 }
35
-
36
- it_should_behave_like 'an incompatible operation'
37
- end
38
-
39
- context 'and operand is a unitless unit' do
40
- let(:operand) { AUOM::Unit.new(1) }
41
-
42
- it_should_behave_like 'an incompatible operation'
43
- end
44
-
45
- context 'and operand is a incompatible unit' do
46
- let(:operand) { AUOM::Unit.new(1, :euro) }
47
-
48
- it_should_behave_like 'an incompatible operation'
49
- end
50
-
51
- context 'and operand is a compatible unit' do
52
- let(:operand) { AUOM::Unit.new(1, :meter) }
53
-
54
- it { should eql(AUOM::Unit.new(0, :meter)) }
55
- end
56
- end
57
- end
@@ -1,29 +0,0 @@
1
- describe AUOM::Inspection, '.prettify_unit_part' do
2
- subject { object.prettify_unit_part(part) }
3
-
4
- let(:object) { AUOM::Inspection }
5
-
6
- context 'with simple part' do
7
- let(:part) { [:meter] }
8
-
9
- it { should eql('meter') }
10
- end
11
-
12
- context 'with mixed part' do
13
- let(:part) { %i[meter euro] }
14
-
15
- it { should eql('euro*meter') }
16
- end
17
-
18
- context 'with complex part' do
19
- let(:part) { %i[meter meter euro] }
20
-
21
- it { should eql('meter^2*euro') }
22
- end
23
-
24
- context 'with very complex part' do
25
- let(:part) { %i[meter meter euro euro kilogramm] }
26
-
27
- it { should eql('euro^2*meter^2*kilogramm') }
28
- end
29
- end
@@ -1,39 +0,0 @@
1
- describe AUOM::Inspection, '#inspect' do
2
- subject { object.inspect }
3
-
4
- let(:object) { AUOM::Unit.new(scalar, *unit) }
5
- let(:unit) { [] }
6
-
7
- context 'when scalar is exact in decimal' do
8
- let(:scalar) { 1 }
9
-
10
- it { should eql('<AUOM::Unit @scalar=1>') }
11
- end
12
-
13
- context 'when scalar is NOT exact in decimal' do
14
- let(:scalar) { Rational(1, 2) }
15
-
16
- it { should eql('<AUOM::Unit @scalar=~0.5000>') }
17
- end
18
-
19
- context 'when has only numerator' do
20
- let(:scalar) { Rational(1, 3) }
21
- let(:unit) { [:meter] }
22
-
23
- it { should eql('<AUOM::Unit @scalar=~0.3333 meter>') }
24
- end
25
-
26
- context 'when has only denominator' do
27
- let(:scalar) { Rational(1, 3) }
28
- let(:unit) { [[], :meter] }
29
-
30
- it { should eql('<AUOM::Unit @scalar=~0.3333 1/meter>') }
31
- end
32
-
33
- context 'when has numerator and denominator' do
34
- let(:scalar) { Rational(1, 3) }
35
- let(:unit) { %i[euro meter] }
36
-
37
- it { should eql('<AUOM::Unit @scalar=~0.3333 euro/meter>') }
38
- end
39
- end
@@ -1,38 +0,0 @@
1
- describe AUOM::Relational, '#greater_than_or_equal_to?' do
2
-
3
- subject { object.greater_than_or_equal_to?(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(true) }
17
- end
18
-
19
- context 'and operand scalar is equal to receiver scalar' do
20
- let(:scalar) { 1 }
21
-
22
- it { should be(true) }
23
- end
24
-
25
- context 'and operand scalar is greater than receiver scalar' do
26
- let(:scalar) { 2 }
27
-
28
- it { should be(false) }
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,38 +0,0 @@
1
- describe AUOM::Relational, '#greater_than?' do
2
-
3
- subject { object.greater_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(true) }
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(false) }
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,38 +0,0 @@
1
- describe AUOM::Relational, '#less_than_or_equal_to?' do
2
-
3
- subject { object.less_than_or_equal_to?(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(true) }
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