Skip to content

Commit 576bcb6

Browse files
authored
Bump: Upgrade to 0.4.0 (#24)
* Bump: Upgrade to 0.4.0 * Update CI matrix * Upgrade development dependencies
1 parent 6513ec0 commit 576bcb6

12 files changed

Lines changed: 69 additions & 46 deletions

File tree

.github/workflows/ruby.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ jobs:
1818
runs-on: ubuntu-latest
1919
strategy:
2020
matrix:
21-
ruby-version: ['2.6']
21+
ruby-version: ['3.0']
2222
steps:
2323
- uses: actions/checkout@v2
2424
- name: Set up Ruby
@@ -32,7 +32,7 @@ jobs:
3232
runs-on: ubuntu-latest
3333
strategy:
3434
matrix:
35-
ruby-version: ['2.6', '2.7', '3.0', '3.1']
35+
ruby-version: ['3.0', '3.1', '3.2']
3636

3737
steps:
3838
- uses: actions/checkout@v2

.rubocop.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ require:
66
- rubocop-rake
77

88
AllCops:
9-
TargetRubyVersion: 2.6
9+
TargetRubyVersion: 3.0
1010
NewCops: enable
1111
DefaultFormatter: progress
1212
DisplayCopNames: true

Gemfile

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@ gemspec
77

88
gem "debug", ">= 1.0.0", require: false
99
gem "minitest", "~> 5.0"
10-
gem "rake", "~> 13.0", ">= 13.0.6"
11-
gem "rubocop", "~> 1.23"
12-
gem "rubocop-minitest", "~> 0.17.0"
13-
gem "rubocop-performance", "~> 1.12"
10+
gem "rake", "~> 13.0.0", ">= 13.0.6"
11+
gem "rubocop", "~> 1.48.0"
12+
gem "rubocop-minitest", "~> 0.29.0"
13+
gem "rubocop-performance", "~> 1.16.0"
1414
gem "rubocop-rake", "~> 0.6.0"

Gemfile.lock

Lines changed: 30 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
PATH
22
remote: .
33
specs:
4-
annealing (0.3.0)
4+
annealing (0.4.0)
55

66
GEM
77
remote: https://rubygems.org/
@@ -10,40 +10,42 @@ GEM
1010
debug (1.4.0)
1111
irb (>= 1.3.6)
1212
reline (>= 0.2.7)
13-
io-console (0.5.11)
14-
irb (1.4.1)
13+
io-console (0.6.0)
14+
irb (1.6.3)
1515
reline (>= 0.3.0)
16-
minitest (5.14.4)
17-
parallel (1.21.0)
18-
parser (3.0.3.2)
16+
json (2.6.3)
17+
minitest (5.18.0)
18+
parallel (1.22.1)
19+
parser (3.2.1.1)
1920
ast (~> 2.4.1)
20-
rainbow (3.0.0)
21+
rainbow (3.1.1)
2122
rake (13.0.6)
22-
regexp_parser (2.2.0)
23-
reline (0.3.1)
23+
regexp_parser (2.7.0)
24+
reline (0.3.2)
2425
io-console (~> 0.5)
2526
rexml (3.2.5)
26-
rubocop (1.23.0)
27+
rubocop (1.48.0)
28+
json (~> 2.3)
2729
parallel (~> 1.10)
28-
parser (>= 3.0.0.0)
30+
parser (>= 3.2.0.0)
2931
rainbow (>= 2.2.2, < 4.0)
3032
regexp_parser (>= 1.8, < 3.0)
31-
rexml
32-
rubocop-ast (>= 1.12.0, < 2.0)
33+
rexml (>= 3.2.5, < 4.0)
34+
rubocop-ast (>= 1.26.0, < 2.0)
3335
ruby-progressbar (~> 1.7)
34-
unicode-display_width (>= 1.4.0, < 3.0)
35-
rubocop-ast (1.14.0)
36-
parser (>= 3.0.1.1)
37-
rubocop-minitest (0.17.0)
38-
rubocop (>= 0.90, < 2.0)
39-
rubocop-performance (1.12.0)
36+
unicode-display_width (>= 2.4.0, < 3.0)
37+
rubocop-ast (1.27.0)
38+
parser (>= 3.2.1.0)
39+
rubocop-minitest (0.29.0)
40+
rubocop (>= 1.39, < 2.0)
41+
rubocop-performance (1.16.0)
4042
rubocop (>= 1.7.0, < 2.0)
4143
rubocop-ast (>= 0.4.0)
4244
rubocop-rake (0.6.0)
4345
rubocop (~> 1.0)
44-
ruby-prof (1.4.3)
45-
ruby-progressbar (1.11.0)
46-
unicode-display_width (2.1.0)
46+
ruby-prof (1.6.1)
47+
ruby-progressbar (1.13.0)
48+
unicode-display_width (2.4.2)
4749

4850
PLATFORMS
4951
ruby
@@ -52,12 +54,12 @@ DEPENDENCIES
5254
annealing!
5355
debug (>= 1.0.0)
5456
minitest (~> 5.0)
55-
rake (~> 13.0, >= 13.0.6)
56-
rubocop (~> 1.23)
57-
rubocop-minitest (~> 0.17.0)
58-
rubocop-performance (~> 1.12)
57+
rake (~> 13.0.0, >= 13.0.6)
58+
rubocop (~> 1.48.0)
59+
rubocop-minitest (~> 0.29.0)
60+
rubocop-performance (~> 1.16.0)
5961
rubocop-rake (~> 0.6.0)
60-
ruby-prof (~> 1.4, >= 1.4.3)
62+
ruby-prof (~> 1.6, >= 1.6.1)
6163

6264
BUNDLED WITH
63-
2.1.4
65+
2.4.4

annealing.gemspec

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ Gem::Specification.new do |spec|
1212
spec.summary = "Simulated Annealing"
1313
spec.description = "Simulated Annealing algoritm implementation."
1414
spec.homepage = "https://github.com/3zcurdia/annealing"
15-
spec.required_ruby_version = Gem::Requirement.new(">= 2.6.0")
15+
spec.required_ruby_version = Gem::Requirement.new(">= 3.0.0")
1616

1717
# spec.metadata["allowed_push_host"] = "TODO: Set to 'http://mygemserver.com'"
1818

@@ -29,6 +29,6 @@ Gem::Specification.new do |spec|
2929
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
3030
spec.require_paths = ["lib"]
3131

32-
spec.add_development_dependency "ruby-prof", "~> 1.4", ">= 1.4.3"
32+
spec.add_development_dependency "ruby-prof", "~> 1.6", ">= 1.6.1"
3333
spec.metadata["rubygems_mfa_required"] = "true"
3434
end

bin/run

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,13 +45,13 @@ solution = simulator.run(locations,
4545
state_change: state_change)
4646

4747
puts "\nInitial itinerary:"
48-
locations.each_cons(2).each_with_index do |(location1, location2), index|
48+
locations.each_cons(2).with_index do |(location1, location2), index|
4949
puts "Stop ##{index + 1}: #{location1.name} -> #{location2.name} (#{location1.distance(location2)})"
5050
end
5151
puts "-------\nEnergy: #{energy_calculator.call(locations)}"
5252

5353
puts "\nAnnealed itinerary:"
54-
solution.state.each_cons(2).each_with_index do |(location1, location2), index|
54+
solution.state.each_cons(2).with_index do |(location1, location2), index|
5555
puts "Stop ##{index + 1}: #{location1.name} -> #{location2.name} (#{location1.distance(location2)})"
5656
end
5757
puts "-------\nEnergy: #{solution.energy}"

lib/annealing/version.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# frozen_string_literal: true
22

33
module Annealing
4-
VERSION = "0.3.0"
4+
VERSION = "0.4.0"
55
end

test/annealing/configuration/coolers_test.rb

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,15 @@ def setup
1515
def test_linear_cooler_reduces_temperature_linearly
1616
cooler = @coolers.linear
1717
cooled_temp = cooler.call(nil, @temperature, @cooling_rate, @step)
18+
1819
assert_in_delta @temperature - @cooling_rate,
1920
cooled_temp
2021
end
2122

2223
def test_exponential_cooler_reduces_temperature_exponentially
2324
cooler = @coolers.exponential
2425
cooled_temp = cooler.call(nil, @temperature, @cooling_rate, @step)
26+
2527
assert_in_delta @temperature - (Math.exp(@step - 1) * @cooling_rate),
2628
cooled_temp
2729
end
@@ -30,6 +32,7 @@ def test_geometric_cooler_reduces_temperature_geometrically
3032
ratio = 3
3133
cooler = @coolers.geometric(ratio)
3234
cooled_temp = cooler.call(nil, @temperature, @cooling_rate, @step)
35+
3336
assert_in_delta @temperature - (@cooling_rate * (ratio**(@step - 1))),
3437
cooled_temp
3538
end

test/annealing/configuration/terminators_test.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,15 @@ def setup
1111

1212
def test_zero_temperature_terminator_true_when_temperature_is_zero
1313
terminator = @terminators.temp_is_zero?
14+
1415
assert terminator.call(nil, nil, 0)
1516
assert terminator.call(nil, nil, -1)
1617
refute terminator.call(nil, nil, 1)
1718
end
1819

1920
def test_zero_energy_terminator_true_when_energy_or_temperature_is_zero
2021
terminator = @terminators.energy_or_temp_is_zero?
22+
2123
assert terminator.call(nil, 0, 0)
2224
assert terminator.call(nil, 0, 1)
2325
assert terminator.call(nil, 1, 0)

test/annealing/configuration_test.rb

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ def setup
1515

1616
def test_sets_a_default_linear_cool_down_function
1717
cool_down = @subject.new.cool_down
18+
1819
assert_respond_to cool_down, :call
1920
assert_equal 1, cool_down.call(nil, 2, 1, nil)
2021
end
@@ -31,6 +32,7 @@ def test_sets_a_default_initial_temperature
3132

3233
def test_sets_a_default_termination_condition_function
3334
termination_condition = @subject.new.termination_condition
35+
3436
assert_respond_to termination_condition, :call
3537
refute termination_condition.call(nil, nil, 1)
3638
assert termination_condition.call(nil, nil, 0)
@@ -47,26 +49,30 @@ def test_does_not_set_a_default_state_change_function
4749

4850
def test_forces_cooling_rate_to_float
4951
configuration = @subject.new(cooling_rate: 99)
52+
5053
assert_kind_of Float, configuration.cooling_rate
5154
assert_in_delta 99.0, configuration.cooling_rate
5255
end
5356

5457
def test_forces_temperature_to_float
5558
configuration = @subject.new(temperature: 999)
59+
5660
assert_kind_of Float, configuration.temperature
5761
assert_in_delta 999.0, configuration.temperature
5862
end
5963

6064
def test_merge_creates_new_configuration_from_config_hash
6165
new_temperature = 3000
6266
new_config = @valid_configuration.merge(temperature: new_temperature)
67+
6368
refute_equal @valid_configuration.object_id, new_config.object_id
6469
assert_equal new_config.temperature, new_temperature
6570
refute_equal @valid_configuration.temperature, new_config.temperature
6671
end
6772

6873
def test_merge_inherits_current_configuration_attributes
6974
new_config = @valid_configuration.merge({})
75+
7076
assert_equal @valid_configuration.cool_down,
7177
new_config.cool_down
7278
assert_equal @valid_configuration.cooling_rate,
@@ -85,6 +91,7 @@ def test_merge_changing_new_configuration_does_not_affect_original
8591
new_config = @valid_configuration.merge({})
8692
new_config.cooling_rate += 0.005
8793
new_config.temperature -= 100
94+
8895
refute_equal @valid_configuration.cooling_rate,
8996
new_config.cooling_rate
9097
refute_equal @valid_configuration.temperature,
@@ -93,48 +100,48 @@ def test_merge_changing_new_configuration_does_not_affect_original
93100

94101
def test_validates_temperature_is_not_negative
95102
@valid_configuration.validate!
103+
@valid_configuration.temperature = -100
96104
assert_raises(@error_class, "Initial temperature cannot be negative") do
97-
@valid_configuration.temperature = -100
98105
@valid_configuration.validate!
99106
end
100107
end
101108

102109
def test_validates_cooling_rate_is_not_negative
103110
@valid_configuration.validate!
111+
@valid_configuration.cooling_rate = -0.005
104112
assert_raises(@error_class, "Cooling rate cannot be negative") do
105-
@valid_configuration.cooling_rate = -0.005
106113
@valid_configuration.validate!
107114
end
108115
end
109116

110117
def test_validates_cool_down_funtion_is_callable
111118
@valid_configuration.validate!
119+
@valid_configuration.cool_down = nil
112120
assert_raises(@error_class, "Missing cool down function") do
113-
@valid_configuration.cool_down = nil
114121
@valid_configuration.validate!
115122
end
116123
end
117124

118125
def test_validates_energy_calculator_is_callable
119126
@valid_configuration.validate!
127+
@valid_configuration.termination_condition = nil
120128
assert_raises(@error_class, "Missing energy calculator function") do
121-
@valid_configuration.termination_condition = nil
122129
@valid_configuration.validate!
123130
end
124131
end
125132

126133
def test_validates_state_change_is_callable
127134
@valid_configuration.validate!
135+
@valid_configuration.energy_calculator = nil
128136
assert_raises(@error_class, "Missing state change function") do
129-
@valid_configuration.energy_calculator = nil
130137
@valid_configuration.validate!
131138
end
132139
end
133140

134141
def test_validates_termination_condition_is_callable
135142
@valid_configuration.validate!
143+
@valid_configuration.state_change = nil
136144
assert_raises(@error_class, "Missing termination condition function") do
137-
@valid_configuration.state_change = nil
138145
@valid_configuration.validate!
139146
end
140147
end

0 commit comments

Comments
 (0)