test/ipaddress/ipv4_test.rb in ipaddress-0.7.0 vs test/ipaddress/ipv4_test.rb in ipaddress-0.7.5
- old
+ new
@@ -4,10 +4,11 @@
def setup
@klass = IPAddress::IPv4
@valid_ipv4 = {
+ "0.0.0.0/0" => ["0.0.0.0", 0],
"10.0.0.0" => ["10.0.0.0", 32],
"10.0.0.1" => ["10.0.0.1", 32],
"10.0.0.1/24" => ["10.0.0.1", 24],
"10.0.0.1/255.255.255.0" => ["10.0.0.1", 24]}
@@ -19,16 +20,18 @@
@valid_ipv4_range = ["10.0.0.1-254",
"10.0.1-254.0",
"10.1-254.0.0"]
@netmask_values = {
+ "0.0.0.0/0" => "0.0.0.0",
"10.0.0.0/8" => "255.0.0.0",
"172.16.0.0/16" => "255.255.0.0",
"192.168.0.0/24" => "255.255.255.0",
"192.168.100.4/30" => "255.255.255.252"}
@decimal_values ={
+ "0.0.0.0/0" => 0,
"10.0.0.0/8" => 167772160,
"172.16.0.0/16" => 2886729728,
"192.168.0.0/24" => 3232235520,
"192.168.100.4/30" => 3232261124}
@@ -235,10 +238,26 @@
assert_equal false, ip.include?(@klass.new("11.0.0.0/8"))
ip = @klass.new("13.13.0.0/13")
assert_equal false, ip.include?(@klass.new("13.16.0.0/32"))
end
+ def test_method_include_all?
+ ip = @klass.new("192.168.10.100/24")
+ addr1 = @klass.new("192.168.10.102/24")
+ addr2 = @klass.new("192.168.10.103/24")
+ assert_equal true, ip.include_all?(addr1,addr2)
+ assert_equal false, ip.include_all?(addr1, @klass.new("13.16.0.0/32"))
+ end
+
+ def test_method_ipv4?
+ assert_equal true, @ip.ipv4?
+ end
+
+ def test_method_ipv6?
+ assert_equal false, @ip.ipv6?
+ end
+
def test_method_private?
assert_equal true, @klass.new("192.168.10.50/24").private?
assert_equal true, @klass.new("192.168.10.50/16").private?
assert_equal true, @klass.new("172.16.77.40/24").private?
assert_equal true, @klass.new("172.16.10.50/14").private?
@@ -450,9 +469,24 @@
ip2 = @klass.new("10.10.2.1/24")
ip3 = @klass.new("172.16.0.1/24")
ip4 = @klass.new("172.16.1.1/24")
result = ["10.0.1.0/24","10.10.2.0/24","172.16.0.0/23"]
assert_equal result, @klass.summarize(ip1,ip2,ip3,ip4).map{|i| i.to_string}
+
+ ips = [@klass.new("10.0.0.12/30"),
+ @klass.new("10.0.100.0/24")]
+ result = ["10.0.0.12/30", "10.0.100.0/24"]
+ assert_equal result, @klass.summarize(*ips).map{|i| i.to_string}
+
+ ips = [@klass.new("172.16.0.0/31"),
+ @klass.new("10.10.2.1/32")]
+ result = ["10.10.2.1/32", "172.16.0.0/31"]
+ assert_equal result, @klass.summarize(*ips).map{|i| i.to_string}
+
+ ips = [@klass.new("172.16.0.0/32"),
+ @klass.new("10.10.2.1/32")]
+ result = ["10.10.2.1/32", "172.16.0.0/32"]
+ assert_equal result, @klass.summarize(*ips).map{|i| i.to_string}
end
def test_classmethod_parse_data
ip = @klass.parse_data "\254\020\n\001"