morphological_metrics 1.2.0 → 1.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 +4 -4
- data/.autotest +30 -30
- data/.gemtest +0 -0
- data/.minitest.rb +3 -3
- data/.travis.yml +10 -10
- data/Gemfile +0 -0
- data/Gemfile.lock +0 -0
- data/History.txt +6 -6
- data/Manifest.txt +27 -27
- data/README.rdoc +65 -66
- data/ROADMAP.txt +63 -63
- data/Rakefile +32 -32
- data/bin/mm +3 -3
- data/lib/mm/deltas.rb +35 -35
- data/lib/mm/metric.rb +180 -191
- data/lib/mm/pairs.rb +12 -11
- data/lib/mm/ratio.rb +145 -148
- data/lib/mm/scaling.rb +30 -27
- data/lib/mm/search.rb +81 -81
- data/lib/mm.rb +10 -11
- data/lib/shortcuts.yml +49 -49
- data/test/helpers.rb +19 -22
- data/test/mm/test_deltas.rb +5 -0
- data/test/mm/test_metric.rb +160 -168
- data/test/mm/test_mm.rb +5 -6
- data/test/mm/test_pairs.rb +24 -27
- data/test/mm/test_ratio.rb +130 -132
- data/test/mm/test_scaling.rb +3 -0
- data/test/mm/test_search.rb +83 -89
- metadata +4 -4
data/test/mm/test_search.rb
CHANGED
@@ -1,89 +1,83 @@
|
|
1
|
-
require 'mm/search'
|
2
|
-
require_relative '../helpers.rb'
|
3
|
-
|
4
|
-
class TestMM < Minitest::Test; end
|
5
|
-
|
6
|
-
class TestMM::TestSearch < Minitest::Test
|
7
|
-
include TestHelpers
|
8
|
-
|
9
|
-
def setup
|
10
|
-
@starting_point = 0.4
|
11
|
-
@search = MM::Search.new(@starting_point)
|
12
|
-
end
|
13
|
-
|
14
|
-
def test_search_exists
|
15
|
-
refute @search.nil?
|
16
|
-
end
|
17
|
-
|
18
|
-
def test_cost_function_accessor
|
19
|
-
@search.cost_function = ->(){0.5}
|
20
|
-
assert_equal 0.5, @search.cost_function
|
21
|
-
end
|
22
|
-
|
23
|
-
def test_calculate_cost_gets_cost_for_candidates
|
24
|
-
@search.cost_function = ->(x){x - 0.1}
|
25
|
-
candidates = [0.3, 0.5]
|
26
|
-
assert_nested_in_delta [0.2, 0.4], @search.calculate_cost(candidates)
|
27
|
-
end
|
28
|
-
|
29
|
-
def test_current_cost_initially_gets_cost_of_starting_point
|
30
|
-
@search.cost_function = ->(x){x - 0.1}
|
31
|
-
assert_in_delta 0.3, @search.current_cost
|
32
|
-
end
|
33
|
-
|
34
|
-
def test_current_cost_gets_cost_of_current_point
|
35
|
-
@search.cost_function = ->(x){x - 0.1}
|
36
|
-
@search.instance_variable_set(:@current_point, 0.3)
|
37
|
-
assert_in_delta 0.2, @search.current_cost
|
38
|
-
end
|
39
|
-
|
40
|
-
def test_adjacent_points_function_accessor
|
41
|
-
@search.adjacent_points_function = ->(current) {[-0.1, 0.1].map {|x| current + x}}
|
42
|
-
assert_nested_in_delta [0.3, 0.5], @search.get_adjacent_points
|
43
|
-
end
|
44
|
-
|
45
|
-
# Testing the final #find method!
|
46
|
-
def test_find
|
47
|
-
@search.adjacent_points_function = ->(current) {[-0.1, 0.1].map {|x| current + x}}
|
48
|
-
@search.cost_function = ->(x){x - 0.1}
|
49
|
-
assert_in_delta 0.1, @search.find
|
50
|
-
end
|
51
|
-
|
52
|
-
def test_find_returns_nil_when_nothing_found
|
53
|
-
@starting_point = [0.1, 0.2, 0.3]
|
54
|
-
@search = MM::Search.new(@starting_point)
|
55
|
-
@search.delta = 0.001
|
56
|
-
@search.starting_point = [0.1, 0.2, 0.3]
|
57
|
-
@search.adjacent_points_function = ->(current) {current.repeated_combination(3)}
|
58
|
-
@search.cost_function = ->(x) { x.inject(0, :+) / x.size }
|
59
|
-
assert_equal nil, @search.find
|
60
|
-
end
|
61
|
-
|
62
|
-
def test_backtrack_removes_point_and_adds_it_to_banned
|
63
|
-
@search.path = [0.1, 0.2]
|
64
|
-
@search.backtrack
|
65
|
-
assert_equal [0.1], @search.path
|
66
|
-
assert_equal [0.2], @search.banned
|
67
|
-
end
|
68
|
-
|
69
|
-
# Stack overflows at (approximately)
|
70
|
-
# 9000 - for integer
|
71
|
-
# 9000 - for Rational
|
72
|
-
# 9000 - for MM::Ratio
|
73
|
-
def test_find_stack_overflow
|
74
|
-
skip # because it takes *forever*
|
75
|
-
@starting_point = MM::Ratio.new(1,1)
|
76
|
-
@search = MM::Search.new(@starting_point)
|
77
|
-
@search.delta = 0.001
|
78
|
-
@search.adjacent_points_function = ->(current) {
|
79
|
-
[MM::Ratio.new(1,1), MM::Ratio.new(-1,1)].map {|m| m + current}
|
80
|
-
}
|
81
|
-
goal = MM::Ratio.new(9000,1)
|
82
|
-
@search.cost_function = ->(x) {
|
83
|
-
(x -
|
84
|
-
}
|
85
|
-
assert_equal goal, @search.find
|
86
|
-
puts @search.iterations
|
87
|
-
end
|
88
|
-
end
|
89
|
-
|
1
|
+
require 'mm/search'
|
2
|
+
require_relative '../helpers.rb'
|
3
|
+
|
4
|
+
class TestMM < Minitest::Test; end
|
5
|
+
|
6
|
+
class TestMM::TestSearch < Minitest::Test
|
7
|
+
include TestHelpers
|
8
|
+
|
9
|
+
def setup
|
10
|
+
@starting_point = 0.4
|
11
|
+
@search = MM::Search.new(@starting_point)
|
12
|
+
end
|
13
|
+
|
14
|
+
def test_search_exists
|
15
|
+
refute @search.nil?
|
16
|
+
end
|
17
|
+
|
18
|
+
def test_cost_function_accessor
|
19
|
+
@search.cost_function = ->(){0.5}
|
20
|
+
assert_equal 0.5, @search.cost_function
|
21
|
+
end
|
22
|
+
|
23
|
+
def test_calculate_cost_gets_cost_for_candidates
|
24
|
+
@search.cost_function = ->(x){x - 0.1}
|
25
|
+
candidates = [0.3, 0.5]
|
26
|
+
assert_nested_in_delta [0.2, 0.4], @search.calculate_cost(candidates)
|
27
|
+
end
|
28
|
+
|
29
|
+
def test_current_cost_initially_gets_cost_of_starting_point
|
30
|
+
@search.cost_function = ->(x){x - 0.1}
|
31
|
+
assert_in_delta 0.3, @search.current_cost
|
32
|
+
end
|
33
|
+
|
34
|
+
def test_current_cost_gets_cost_of_current_point
|
35
|
+
@search.cost_function = ->(x){x - 0.1}
|
36
|
+
@search.instance_variable_set(:@current_point, 0.3)
|
37
|
+
assert_in_delta 0.2, @search.current_cost
|
38
|
+
end
|
39
|
+
|
40
|
+
def test_adjacent_points_function_accessor
|
41
|
+
@search.adjacent_points_function = ->(current) {[-0.1, 0.1].map {|x| current + x}}
|
42
|
+
assert_nested_in_delta [0.3, 0.5], @search.get_adjacent_points
|
43
|
+
end
|
44
|
+
|
45
|
+
# Testing the final #find method!
|
46
|
+
def test_find
|
47
|
+
@search.adjacent_points_function = ->(current) {[-0.1, 0.1].map {|x| current + x}}
|
48
|
+
@search.cost_function = ->(x){x - 0.1}
|
49
|
+
assert_in_delta 0.1, @search.find
|
50
|
+
end
|
51
|
+
|
52
|
+
def test_find_returns_nil_when_nothing_found
|
53
|
+
@starting_point = [0.1, 0.2, 0.3]
|
54
|
+
@search = MM::Search.new(@starting_point)
|
55
|
+
@search.delta = 0.001
|
56
|
+
@search.starting_point = [0.1, 0.2, 0.3]
|
57
|
+
@search.adjacent_points_function = ->(current) {current.repeated_combination(3)}
|
58
|
+
@search.cost_function = ->(x) { x.inject(0, :+) / x.size }
|
59
|
+
assert_equal nil, @search.find
|
60
|
+
end
|
61
|
+
|
62
|
+
def test_backtrack_removes_point_and_adds_it_to_banned
|
63
|
+
@search.path = [0.1, 0.2]
|
64
|
+
@search.backtrack
|
65
|
+
assert_equal [0.1], @search.path
|
66
|
+
assert_equal [0.2], @search.banned
|
67
|
+
end
|
68
|
+
|
69
|
+
# Stack overflows at (approximately)
|
70
|
+
# 9000 - for integer
|
71
|
+
# 9000 - for Rational
|
72
|
+
# 9000 - for MM::Ratio
|
73
|
+
def test_find_stack_overflow
|
74
|
+
skip # because it takes *forever*
|
75
|
+
@starting_point = MM::Ratio.new(1,1)
|
76
|
+
@search = MM::Search.new(@starting_point)
|
77
|
+
@search.delta = 0.001
|
78
|
+
@search.adjacent_points_function = ->(current) {
|
79
|
+
[MM::Ratio.new(1,1), MM::Ratio.new(-1,1)].map {|m| m + current}
|
80
|
+
}
|
81
|
+
goal = MM::Ratio.new(9000,1)
|
82
|
+
@search.cost_function = ->(x) {
|
83
|
+
(x - go
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: morphological_metrics
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.3.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Andrew C. Smith
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2017-10-29 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: RubyInline
|
@@ -106,7 +106,7 @@ files:
|
|
106
106
|
- test/mm/test_ratio.rb
|
107
107
|
- test/mm/test_scaling.rb
|
108
108
|
- test/mm/test_search.rb
|
109
|
-
homepage: https://
|
109
|
+
homepage: https://github.com/andrewcsmith/mm
|
110
110
|
licenses:
|
111
111
|
- MIT
|
112
112
|
metadata: {}
|
@@ -128,7 +128,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
128
128
|
version: '1.4'
|
129
129
|
requirements: []
|
130
130
|
rubyforge_project:
|
131
|
-
rubygems_version: 2.
|
131
|
+
rubygems_version: 2.6.13
|
132
132
|
signing_key:
|
133
133
|
specification_version: 4
|
134
134
|
summary: Implements some Morphological Metrics, described by Larry Polansky.
|