Skip to content

Commit

Permalink
Merge pull request #24 from Adam21e/find_adjacent
Browse files Browse the repository at this point in the history
Find adjacent
  • Loading branch information
Adam21e authored Jan 22, 2019
2 parents 6d1cb1d + 963c288 commit 9e20ef8
Show file tree
Hide file tree
Showing 7 changed files with 19 additions and 6 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
## [Unreleased]

## 0.11.1

### Bugfix
* Fix prefix change in find\_adjacent

## 0.11.0

### Enhancements
Expand Down
2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
0.11.0
0.11.1
4 changes: 3 additions & 1 deletion lib/ipaddress_2/ipv4.rb
Original file line number Diff line number Diff line change
Expand Up @@ -1164,7 +1164,9 @@ def find_adjacent_subnet
return false if prefix == 0
current_subnet = to_string
self.prefix = @prefix - 1
(split.map{|i| i.to_string} - [current_subnet])[0]
adjacent_subnet = (split.map{|i| i.to_string} - [current_subnet])[0]
self.prefix = @prefix + 1
return adjacent_subnet
end

#
Expand Down
4 changes: 3 additions & 1 deletion lib/ipaddress_2/ipv6.rb
Original file line number Diff line number Diff line change
Expand Up @@ -977,7 +977,9 @@ def find_adjacent_subnet
return false if prefix == 0
current_subnet = to_string
self.prefix = @prefix - 1
(split.map{|i| i.to_string} - [current_subnet])[0]
adjacent_subnet = (split.map{|i| i.to_string} - [current_subnet])[0]
self.prefix = @prefix + 1
return adjacent_subnet
end

private
Expand Down
2 changes: 1 addition & 1 deletion lib/ipaddress_2/version.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
module IPAddress
VERSION = "0.11.0"
VERSION = "0.11.1"
end
1 change: 1 addition & 0 deletions test/ipaddress_2/ipv4_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -689,6 +689,7 @@ def test_allocate_will_raise_stopiteration
def test_finds_adjacent_subnet
ip = @klass.new("10.0.0.0/24")
assert_equal "10.0.1.0/24", ip.find_adjacent_subnet
assert_equal 24, ip.prefix
refute @klass.new("10.0.0.0/0").find_adjacent_subnet
assert_equal "10.0.0.0/8", @klass.new("11.0.0.0/8").find_adjacent_subnet
assert_equal "172.16.0.0/16", @klass.new("172.17.0.0/16").find_adjacent_subnet
Expand Down
7 changes: 5 additions & 2 deletions test/ipaddress_2/ipv6_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -572,11 +572,14 @@ def test_group_updates

def test_finds_adjacent_subnet
refute @klass.new("::/0").find_adjacent_subnet

ip = @klass.new("2001:db8::/32")
assert_equal "2001:db9::/32", ip.find_adjacent_subnet
assert_equal 32, ip.prefix

assert_equal "2001:db9::/32", @klass.new("2001:db8::/32").find_adjacent_subnet
assert_equal "2001:db8:0:1::/64", @klass.new("2001:db8::/64").find_adjacent_subnet
assert_equal "2001:db8:8:2000::/51", @klass.new("2001:db8:8::/51").find_adjacent_subnet
# assert_equal "", @klass.new("").find_adjacent_subnet
# assert_equal "", @klass.new("").find_adjacent_subnet
end

end # class IPv6Test
Expand Down

0 comments on commit 9e20ef8

Please sign in to comment.