test/ipaddress/ipv4_test.rb in ipaddress-0.6.0 vs test/ipaddress/ipv4_test.rb in ipaddress-0.7.0

- old
+ new

@@ -4,12 +4,12 @@ def setup @klass = IPAddress::IPv4 @valid_ipv4 = { - "10.0.0.0" => ["10.0.0.0", 8], - "10.0.0.1" => ["10.0.0.1", 8], + "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]} @invalid_ipv4 = ["10.0.0.256", "10.0.0.0.0", @@ -48,10 +48,15 @@ "192.168.100.5/30" => "192.168.100.4/30"} @class_a = @klass.new("10.0.0.1/8") @class_b = @klass.new("172.16.0.1/16") @class_c = @klass.new("192.168.0.1/24") + + @classful = { + "10.1.1.1" => 8, + "150.1.1.1" => 16, + "200.1.1.1" => 24 } end def test_initialize @valid_ipv4.keys.each do |i| @@ -78,10 +83,11 @@ assert_nothing_raised do @klass.new("10.10.0.0") end ip = @klass.new("10.10.0.0") assert_instance_of IPAddress::Prefix32, ip.prefix + assert_equal 32, ip.prefix.to_i end def test_attributes @valid_ipv4.each do |arg,attr| ip = @klass.new(arg) @@ -229,10 +235,25 @@ 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_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? + assert_equal true, @klass.new("10.10.10.10/10").private? + assert_equal true, @klass.new("10.0.0.0/8").private? + assert_equal false, @klass.new("192.168.10.50/12").private? + assert_equal false, @klass.new("3.3.3.3").private? + assert_equal false, @klass.new("10.0.0.0/7").private? + assert_equal false, @klass.new("172.32.0.0/12").private? + assert_equal false, @klass.new("172.16.0.0/11").private? + assert_equal false, @klass.new("192.0.0.2/24").private? + end + def test_method_octet assert_equal 172, @ip[0] assert_equal 16, @ip[1] assert_equal 10, @ip[2] assert_equal 1, @ip[3] @@ -436,10 +457,19 @@ def test_classmethod_parse_data ip = @klass.parse_data "\254\020\n\001" assert_instance_of @klass, ip assert_equal "172.16.10.1", ip.address - assert_equal "172.16.10.1/16", ip.to_string + assert_equal "172.16.10.1/32", ip.to_string + end + + def test_classmethod_parse_classful + @classful.each do |ip,prefix| + res = @klass.parse_classful(ip) + assert_equal prefix, res.prefix + assert_equal "#{ip}/#{prefix}", res.to_string + end + assert_raise(ArgumentError){ @klass.parse_classful("192.168.256.257") } end end # class IPv4Test