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.
- checksums.yaml +5 -5
- data/.circleci/config.yml +18 -0
- data/.rubocop.yml +1 -1
- data/Changelog.md +5 -0
- data/Gemfile +2 -0
- data/Rakefile +2 -0
- data/auom.gemspec +6 -4
- data/config/devtools.yml +2 -0
- data/config/flay.yml +1 -1
- data/config/reek.yml +96 -97
- data/config/rubocop.yml +3 -0
- data/lib/auom.rb +2 -1
- data/lib/auom/algebra.rb +2 -0
- data/lib/auom/equalization.rb +2 -2
- data/lib/auom/inspection.rb +15 -10
- data/lib/auom/relational.rb +6 -76
- data/lib/auom/unit.rb +6 -8
- data/spec/shared/incompatible_operation_behavior.rb +2 -0
- data/spec/shared/operation_behavior.rb +3 -0
- data/spec/shared/sunits_shared.rb +2 -0
- data/spec/spec_helper.rb +2 -0
- data/spec/unit/auom/algebra_spec.rb +279 -0
- data/spec/unit/auom/{equalization/equality_operator_spec.rb → equalization_spec.rb} +2 -1
- data/spec/unit/auom/inspection_spec.rb +73 -0
- data/spec/unit/auom/relational_spec.rb +39 -0
- data/spec/unit/auom/unit_spec.rb +377 -0
- metadata +18 -57
- data/.circle.yml +0 -4
- data/TODO +0 -1
- data/spec/unit/auom/algebra/add_spec.rb +0 -57
- data/spec/unit/auom/algebra/divide_spec.rb +0 -83
- data/spec/unit/auom/algebra/multiply_spec.rb +0 -80
- data/spec/unit/auom/algebra/substract_spec.rb +0 -57
- data/spec/unit/auom/inspection/class_methods/prettify_unit_part_spec.rb +0 -29
- data/spec/unit/auom/inspection/inspect_spec.rb +0 -39
- data/spec/unit/auom/relational/greater_than_or_equal_to_predicate_spec.rb +0 -38
- data/spec/unit/auom/relational/greater_than_predicate_spec.rb +0 -38
- data/spec/unit/auom/relational/less_than_or_equal_to_predicate_spec.rb +0 -38
- data/spec/unit/auom/relational/less_than_predicate_spec.rb +0 -38
- data/spec/unit/auom/unit/assert_same_unit_spec.rb +0 -20
- data/spec/unit/auom/unit/class_methods/convert_spec.rb +0 -33
- data/spec/unit/auom/unit/class_methods/lookup_spec.rb +0 -19
- data/spec/unit/auom/unit/class_methods/new_spec.rb +0 -152
- data/spec/unit/auom/unit/class_methods/try_convert_spec.rb +0 -35
- data/spec/unit/auom/unit/class_methods/units_spec.rb +0 -9
- data/spec/unit/auom/unit/denominators_spec.rb +0 -14
- data/spec/unit/auom/unit/numerators_spec.rb +0 -14
- data/spec/unit/auom/unit/same_unit_predicate_spec.rb +0 -20
- data/spec/unit/auom/unit/scalar_spec.rb +0 -14
- data/spec/unit/auom/unit/unit +0 -0
- data/spec/unit/auom/unit/unit_spec.rb +0 -14
- data/spec/unit/auom/unit/unitless_predicate_spec.rb +0 -22
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 9a7dad47d0763bd36fc51452be282e6770defd02dd2456d25283f96306183569
|
4
|
+
data.tar.gz: 9cfdfe4738323f4e8ad3213fcd07e808cfa9afb9a0b09932ac6fc855a36e10f5
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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
|
data/.rubocop.yml
CHANGED
data/Changelog.md
CHANGED
data/Gemfile
CHANGED
data/Rakefile
CHANGED
data/auom.gemspec
CHANGED
@@ -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.
|
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[
|
15
|
+
gem.extra_rdoc_files = %w[LICENSE]
|
14
16
|
|
15
|
-
gem.required_ruby_version = '>= 2.
|
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.
|
21
|
+
gem.add_development_dependency('devtools', '~> 0.1.21')
|
20
22
|
end
|
data/config/devtools.yml
ADDED
data/config/flay.yml
CHANGED
data/config/reek.yml
CHANGED
@@ -1,97 +1,96 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
UncommunicativeMethodName:
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
LongParameterList:
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
FeatureEnvy:
|
31
|
-
|
32
|
-
|
33
|
-
ClassVariable:
|
34
|
-
|
35
|
-
|
36
|
-
BooleanParameter:
|
37
|
-
|
38
|
-
|
39
|
-
IrresponsibleModule:
|
40
|
-
|
41
|
-
|
42
|
-
UncommunicativeModuleName:
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
NestedIterators:
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
TooManyStatements:
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
DuplicateMethodCall:
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
UtilityFunction:
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
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
|
data/config/rubocop.yml
CHANGED
data/lib/auom.rb
CHANGED
data/lib/auom/algebra.rb
CHANGED
data/lib/auom/equalization.rb
CHANGED
@@ -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
|
data/lib/auom/inspection.rb
CHANGED
@@ -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
|
-
|
6
|
-
|
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
|
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))
|
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
|
data/lib/auom/relational.rb
CHANGED
@@ -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
|
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
|