Skip to content

Commit

Permalink
added bugfix/40 fix with test
Browse files Browse the repository at this point in the history
  • Loading branch information
mikemackintosh committed Mar 23, 2015
1 parent f562a7f commit 09bde2a
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 5 deletions.
7 changes: 2 additions & 5 deletions lib/ipaddress/ipv4.rb
Original file line number Diff line number Diff line change
Expand Up @@ -1026,12 +1026,9 @@ def self.parse_classful(ip)
#
private

# Tweaked to remove the #upto(32)
def newprefix(num)
num.upto(32) do |i|
if (a = Math::log2(i).to_i) == Math::log2(i)
return @prefix + a
end
end
return @prefix + (Math::log2(num).to_i)
end

def sum_first_found(arr)
Expand Down
9 changes: 9 additions & 0 deletions test/ipaddress/ipv4_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -542,6 +542,15 @@ def test_classmethod_parse_classful
assert_raises(ArgumentError){ @klass.parse_classful("192.168.256.257") }
end

def test_network_split
@classful.each do |ip,net|
x = @klass.new("#{ip}/#{net}")
assert_equal x.split(1).length, 1
assert_equal x.split(2).length, 2
assert_equal x.split(32).length, 32
assert_equal x.split(256).length, 256
end
end
end # class IPv4Test


0 comments on commit 09bde2a

Please sign in to comment.