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
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: 0052fcab4f594eaadb81ddb9c50b5383a1f6ccbe
4
- data.tar.gz: 7dee775c276bad51bfa0b8a926b022278f2c008b
2
+ SHA256:
3
+ metadata.gz: 9a7dad47d0763bd36fc51452be282e6770defd02dd2456d25283f96306183569
4
+ data.tar.gz: 9cfdfe4738323f4e8ad3213fcd07e808cfa9afb9a0b09932ac6fc855a36e10f5
5
5
  SHA512:
6
- metadata.gz: 010b60063558dc2268e38fd1af143492334a37f45a5613e52bfb052a2bee8337305ff1df52ebf5ec8d35aca7db1d92185ca6b7fa9f10aba0aef1d12a75f037c8
7
- data.tar.gz: 4db585b70f9db889c5ff9e39a1afb4793bec6d3d62e2dd710661d29711af67c3b3cbb0874a98057b3ad3675755bc1cbed0969d3cae570050a29c6f0ab06b5067
6
+ metadata.gz: b93ce51d8b7f5f90ca353f001dbd87ec4cefdbc12c008c2a3cb658527ef9199e35ba5dcf6561795251ff1c5c86ba4631c2b6aca781c8ce1dd11a394143ac4cdf
7
+ data.tar.gz: 5c52401f2362f4d16f038634627fc6be09973392e9e33e18cb4415da5a088be04088a603e95d1b618016546e9a6f92a057779ba7cd09dbd7a6f0df7f02027d87
@@ -0,0 +1,18 @@
1
+ ---
2
+ defaults: &defaults
3
+ working_directory: ~/mutant
4
+ steps:
5
+ - checkout
6
+ - run: bundle install
7
+ - run: bundle exec rake ci
8
+ version: 2
9
+ jobs:
10
+ ruby_2_5:
11
+ <<: *defaults
12
+ docker:
13
+ - image: circleci/ruby:2.5.3
14
+ workflows:
15
+ version: 2
16
+ test:
17
+ jobs:
18
+ - ruby_2_5
@@ -1,3 +1,3 @@
1
1
  AllCops:
2
2
  DisplayCopNames: true
3
- TargetRubyVersion: 2.2
3
+ TargetRubyVersion: 2.5
@@ -1,3 +1,8 @@
1
+ # v0.3.0 2018-11-10
2
+
3
+ * [breaking-change] Change to provide all relational operators, remove named ones
4
+ * [breaking-change] Drop support for ruby < 2.5
5
+
1
6
  # v0.2.0 2017-09-29
2
7
 
3
8
  * [breaking-change] Drop support for < 2.4
data/Gemfile CHANGED
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  source 'https://rubygems.org'
2
4
 
3
5
  gemspec
data/Rakefile CHANGED
@@ -1,2 +1,4 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'devtools'
2
4
  Devtools.init_rake_tasks
@@ -1,6 +1,8 @@
1
+ # frozen_string_literal: true
2
+
1
3
  Gem::Specification.new do |gem|
2
4
  gem.name = 'auom'
3
- gem.version = '0.2.0'
5
+ gem.version = '0.3.0'
4
6
 
5
7
  gem.authors = ['Markus Schirp']
6
8
  gem.email = 'mbj@schirp-dso.com'
@@ -10,11 +12,11 @@ Gem::Specification.new do |gem|
10
12
  gem.files = `git ls-files`.split("\n")
11
13
  gem.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
12
14
  gem.require_paths = %w[lib]
13
- gem.extra_rdoc_files = %w[TODO LICENSE]
15
+ gem.extra_rdoc_files = %w[LICENSE]
14
16
 
15
- gem.required_ruby_version = '>= 2.4'
17
+ gem.required_ruby_version = '>= 2.5'
16
18
 
17
19
  gem.add_dependency('equalizer', '~> 0.0.9')
18
20
 
19
- gem.add_development_dependency('devtools', '~> 0.1.12')
21
+ gem.add_development_dependency('devtools', '~> 0.1.21')
20
22
  end
@@ -0,0 +1,2 @@
1
+ ---
2
+ unit_test_timeout: 2.0
@@ -1,3 +1,3 @@
1
1
  ---
2
2
  threshold: 12
3
- total_score: 88
3
+ total_score: 87
@@ -1,97 +1,96 @@
1
- UncommunicativeParameterName:
2
- accept: []
3
- exclude: []
4
- enabled: true
5
- reject:
6
- - !ruby/regexp /^.$/
7
- - !ruby/regexp /[0-9]$/
8
- - !ruby/regexp /[A-Z]/
9
- TooManyMethods:
10
- max_methods: 14
11
- enabled: true
12
- exclude: []
13
- max_instance_variables: 4
14
- UncommunicativeMethodName:
15
- accept: []
16
- exclude: []
17
- enabled: true
18
- reject:
19
- - !ruby/regexp /^[a-z]$/
20
- - !ruby/regexp /[0-9]$/
21
- - !ruby/regexp /[A-Z]/
22
- LongParameterList:
23
- max_params: 2
24
- exclude:
25
- - "AUOM::Unit#initialize" # 3 params
26
- - "AUOM::Unit#self.new" # 3 params
27
- - "AUOM::Unit#self.resolve" # 3 params
28
- enabled: true
29
- overrides: {}
30
- FeatureEnvy:
31
- exclude: []
32
- enabled: true
33
- ClassVariable:
34
- exclude: []
35
- enabled: true
36
- BooleanParameter:
37
- exclude: []
38
- enabled: true
39
- IrresponsibleModule:
40
- exclude: []
41
- enabled: true
42
- UncommunicativeModuleName:
43
- accept: []
44
- exclude: []
45
- enabled: true
46
- reject:
47
- - !ruby/regexp /^.$/
48
- - !ruby/regexp /[0-9]$/
49
- NestedIterators:
50
- ignore_iterators: []
51
- exclude:
52
- - AUOM::Unit#initialize # 2 levels
53
- enabled: true
54
- max_allowed_nesting: 1
55
- TooManyStatements:
56
- max_statements: 6
57
- exclude:
58
- - AUOM::Inspection#pretty_unit # 7 statements
59
- - AUOM::Unit#initialize # 8 statements
60
- enabled: true
61
- DuplicateMethodCall:
62
- allow_calls: []
63
- exclude:
64
- - "AUOM::ClassMethods#new" # invalid detection
65
- enabled: true
66
- max_calls: 1
67
- UtilityFunction:
68
- max_helper_calls: 0
69
- exclude: []
70
- enabled: true
71
- Attribute:
72
- exclude: []
73
- enabled: false
74
- UncommunicativeVariableName:
75
- accept: []
76
- exclude: []
77
- enabled: true
78
- reject:
79
- - !ruby/regexp /^.$/
80
- - !ruby/regexp /[0-9]$/
81
- - !ruby/regexp /[A-Z]/
82
- RepeatedConditional:
83
- enabled: true
84
- max_ifs: 1
85
- DataClump:
86
- exclude: []
87
- enabled: true
88
- max_copies: 1
89
- min_clump_size: 2
90
- ControlParameter:
91
- exclude:
92
- - AUOM::Unit#assert_same_unit
93
- enabled: true
94
- LongYieldList:
95
- max_params: 0
96
- exclude: []
97
- enabled: true
1
+ detectors:
2
+ UncommunicativeParameterName:
3
+ accept: []
4
+ exclude: []
5
+ enabled: true
6
+ reject:
7
+ - /^.$/
8
+ - /[0-9]$/
9
+ - /[A-Z]/
10
+ TooManyMethods:
11
+ max_methods: 14
12
+ enabled: true
13
+ exclude: []
14
+ UncommunicativeMethodName:
15
+ accept: []
16
+ exclude: []
17
+ enabled: true
18
+ reject:
19
+ - /^[a-z]$/
20
+ - /[0-9]$/
21
+ - /[A-Z]/
22
+ LongParameterList:
23
+ max_params: 2
24
+ exclude:
25
+ - "AUOM::Unit#initialize" # 3 params
26
+ - "AUOM::Unit#self.new" # 3 params
27
+ - "AUOM::Unit#self.resolve" # 3 params
28
+ enabled: true
29
+ overrides: {}
30
+ FeatureEnvy:
31
+ exclude: []
32
+ enabled: true
33
+ ClassVariable:
34
+ exclude: []
35
+ enabled: true
36
+ BooleanParameter:
37
+ exclude: []
38
+ enabled: true
39
+ IrresponsibleModule:
40
+ exclude: []
41
+ enabled: true
42
+ UncommunicativeModuleName:
43
+ accept: []
44
+ exclude: []
45
+ enabled: true
46
+ reject:
47
+ - /^.$/
48
+ - /[0-9]$/
49
+ NestedIterators:
50
+ ignore_iterators: []
51
+ exclude:
52
+ - AUOM::Unit#initialize # 2 levels
53
+ enabled: true
54
+ max_allowed_nesting: 1
55
+ TooManyStatements:
56
+ max_statements: 6
57
+ exclude:
58
+ - AUOM::Inspection#pretty_unit # 7 statements
59
+ - AUOM::Unit#initialize # 8 statements
60
+ enabled: true
61
+ DuplicateMethodCall:
62
+ allow_calls: []
63
+ exclude:
64
+ - "AUOM::ClassMethods#new" # invalid detection
65
+ enabled: true
66
+ max_calls: 1
67
+ UtilityFunction:
68
+ exclude: []
69
+ enabled: true
70
+ Attribute:
71
+ exclude: []
72
+ enabled: false
73
+ UncommunicativeVariableName:
74
+ accept: []
75
+ exclude: []
76
+ enabled: true
77
+ reject:
78
+ - /^.$/
79
+ - /[0-9]$/
80
+ - /[A-Z]/
81
+ RepeatedConditional:
82
+ enabled: true
83
+ max_ifs: 1
84
+ DataClump:
85
+ exclude: []
86
+ enabled: true
87
+ max_copies: 1
88
+ min_clump_size: 2
89
+ ControlParameter:
90
+ exclude:
91
+ - AUOM::Unit#assert_same_unit
92
+ enabled: true
93
+ LongYieldList:
94
+ max_params: 0
95
+ exclude: []
96
+ enabled: true
@@ -183,3 +183,6 @@ Send:
183
183
 
184
184
  Lint/UnifiedInteger:
185
185
  Enabled: false
186
+
187
+ Style/CommentedKeyword:
188
+ Enabled: false
@@ -1,4 +1,5 @@
1
- require 'rational'
1
+ # frozen_string_literal: true
2
+
2
3
  require 'equalizer'
3
4
 
4
5
  # Library namespace
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module AUOM
2
4
  # The AUOM algebra
3
5
  module Algebra
@@ -1,7 +1,8 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module AUOM
2
4
  # Equalization for auom units
3
5
  module Equalization
4
-
5
6
  # Check for equivalent value and try to convert
6
7
  #
7
8
  # @param [Object] other
@@ -29,6 +30,5 @@ module AUOM
29
30
  def ==(other)
30
31
  eql?(self.class.try_convert(other))
31
32
  end
32
-
33
33
  end # Equalization
34
34
  end # AUOM
@@ -1,10 +1,11 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module AUOM
2
4
  # Inspection module for auom units
3
5
  module Inspection
4
-
5
- INSPECT_FORMAT = '<%s @scalar=%s%s>'.freeze
6
- SCALAR_FORMAT = '~%0.4f'.freeze
7
- UNIT_FORMAT = ' %s/%s'.freeze
6
+ INSPECT_FORMAT = '<%s @scalar=%s%s>'
7
+ SCALAR_FORMAT = '~%0.4f'
8
+ UNIT_FORMAT = ' %s/%s'
8
9
 
9
10
  # Return inspectable representation
10
11
  #
@@ -25,7 +26,9 @@ module AUOM
25
26
  # @api private
26
27
  #
27
28
  def self.prettify_unit_part(base)
28
- counts(base).map { |unit, length| length > 1 ? "#{unit}^#{length}" : unit }.join('*')
29
+ counts(base).map do |unit, length|
30
+ length > 1 ? "#{unit}^#{length}" : unit
31
+ end.join('*')
29
32
  end
30
33
 
31
34
  private
@@ -61,9 +64,7 @@ module AUOM
61
64
  denominator = Inspection.prettify_unit_part(denominators)
62
65
 
63
66
  numerator = '1' if numerator.empty?
64
- if denominator.empty?
65
- return " #{numerator}"
66
- end
67
+ return " #{numerator}" if denominator.empty?
67
68
 
68
69
  format(UNIT_FORMAT, numerator, denominator)
69
70
  end
@@ -90,8 +91,12 @@ module AUOM
90
91
  #
91
92
  # @api private
92
93
  #
94
+ # rubocop:disable Metrics/MethodLength
93
95
  def self.counts(base)
94
- counts = base.each_with_object(Hash.new(0)) { |unit, hash| hash[unit] += 1 }
96
+ counts = base.each_with_object(Hash.new(0)) do |unit, hash|
97
+ hash[unit] += 1
98
+ end
99
+
95
100
  counts.sort do |left, right|
96
101
  result = right.last <=> left.last
97
102
  if result.equal?(0)
@@ -101,8 +106,8 @@ module AUOM
101
106
  end
102
107
  end
103
108
  end
104
-
105
109
  private_class_method :counts
110
+ # rubocop:enable Metrics/MethodLength
106
111
 
107
112
  end # Inspection
108
113
  end # AUOM
@@ -1,90 +1,20 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module AUOM
2
4
  # Mixin to add relational operators
3
5
  module Relational
4
-
5
- # Test if unit is less than or equal to other
6
- #
7
- # @param [Unit] other
8
- #
9
- # @return [true]
10
- # if unit is less than other
11
- #
12
- # @return [false]
13
- # otherwise
14
- #
15
- # @api private
16
- #
17
- def less_than_or_equal_to?(other)
18
- relational_operation(other, :<=)
19
- end
20
- alias_method :<=, :less_than_or_equal_to?
21
-
22
- # Test if unit is greater than or equal to other
6
+ # Perform comparison operation
23
7
  #
24
8
  # @param [Unit] other
25
9
  #
26
- # @return [true]
27
- # if unit is greater than other
28
- #
29
- # @return [false]
30
- # otherwise
31
- #
32
- # @api private
33
- #
34
- def greater_than_or_equal_to?(other)
35
- relational_operation(other, :>=)
36
- end
37
- alias_method :>=, :greater_than_or_equal_to?
38
-
39
- # Test if unit is less than other
40
- #
41
- # @param [Unit] other
42
- #
43
- # @return [true]
44
- # if unit is less than other
45
- #
46
- # @return [false]
47
- # otherwise
48
- #
49
- # @api private
50
- #
51
- def less_than?(other)
52
- relational_operation(other, :<)
53
- end
54
- alias_method :<, :less_than?
55
-
56
- # Test if unit is greater than other
57
- #
58
- # @param [Unit] other
59
- #
60
- # @return [true]
61
- # if unit is greater than other
62
- #
63
- # @return [false]
64
- # otherwise
65
- #
66
- # @api private
67
- #
68
- def greater_than?(other)
69
- relational_operation(other, :>)
70
- end
71
- alias_method :<, :less_than?
72
-
73
- private
74
-
75
- # Perform relational operation
76
- #
77
- # @param [Unit] other
78
- # @param [Symbol] operation
79
- #
80
10
  # @return [Object]
81
11
  #
82
12
  # @api private
83
13
  #
84
- def relational_operation(other, operation)
14
+ def <=>(other)
85
15
  assert_same_unit(other)
86
- scalar.public_send(operation, other.scalar)
87
- end
88
16
 
17
+ scalar <=> other.scalar
18
+ end
89
19
  end # Relational
90
20
  end # AUOM