diff options
author | bluemonk <ceresa@gmail.com> | 2011-05-14 01:23:29 +0200 |
---|---|---|
committer | bluemonk <ceresa@gmail.com> | 2011-05-14 01:23:29 +0200 |
commit | c2945c56542c6c4f969782b8e50e039cee9665ca (patch) | |
tree | aa81848768ab701296df01e7118f0b54a29d5544 /test | |
parent | 9120fad3ccee359f07ab0f12f964f7b5a8069676 (diff) | |
download | ipaddress-c2945c56542c6c4f969782b8e50e039cee9665ca.tar.gz |
Added IPv6#<=>, changed IPv4#<=> and IPv4#supernet (closes #13)
Diffstat (limited to 'test')
-rw-r--r-- | test/ipaddress/ipv4_test.rb | 25 | ||||
-rw-r--r-- | test/ipaddress/ipv6_test.rb | 30 |
2 files changed, 45 insertions, 10 deletions
diff --git a/test/ipaddress/ipv4_test.rb b/test/ipaddress/ipv4_test.rb index 8cb3b8f..c6d6dfb 100644 --- a/test/ipaddress/ipv4_test.rb +++ b/test/ipaddress/ipv4_test.rb @@ -304,20 +304,20 @@ class IPv4Test < Test::Unit::TestCase assert_equal "1.10.16.172.in-addr.arpa", @ip.reverse end - def test_method_comparabble + def test_method_compare ip1 = @klass.new("10.1.1.1/8") ip2 = @klass.new("10.1.1.1/16") ip3 = @klass.new("172.16.1.1/14") ip4 = @klass.new("10.1.1.1/8") - # ip1 should be major than ip2 - assert_equal true, ip1 > ip2 - assert_equal false, ip1 < ip2 - assert_equal false, ip2 > ip1 - # ip2 should be minor than ip3 + # ip2 should be greater than ip1 + assert_equal true, ip1 < ip2 + assert_equal false, ip1 > ip2 + assert_equal false, ip2 < ip1 + # ip2 should be less than ip3 assert_equal true, ip2 < ip3 assert_equal false, ip2 > ip3 - # ip1 should be minor than ip3 + # ip1 should be less than ip3 assert_equal true, ip1 < ip3 assert_equal false, ip1 > ip3 assert_equal false, ip3 < ip1 @@ -326,7 +326,13 @@ class IPv4Test < Test::Unit::TestCase # ip1 should be equal to ip4 assert_equal true, ip1 == ip4 # test sorting - arr = ["10.1.1.1/16","10.1.1.1/8","172.16.1.1/14"] + arr = ["10.1.1.1/8","10.1.1.1/16","172.16.1.1/14"] + assert_equal arr, [ip1,ip2,ip3].sort.map{|s| s.to_string} + # test same prefix + ip1 = @klass.new("10.0.0.0/24") + ip2 = @klass.new("10.0.0.0/16") + ip3 = @klass.new("10.0.0.0/8") + arr = ["10.0.0.0/8","10.0.0.0/16","10.0.0.0/24"] assert_equal arr, [ip1,ip2,ip3].sort.map{|s| s.to_string} end @@ -401,8 +407,9 @@ class IPv4Test < Test::Unit::TestCase end def test_method_supernet - assert_raise(ArgumentError) {@ip.supernet(0)} assert_raise(ArgumentError) {@ip.supernet(24)} + assert_equal "0.0.0.0/0", @ip.supernet(0).to_string + assert_equal "0.0.0.0/0", @ip.supernet(-2).to_string assert_equal "172.16.10.0/23", @ip.supernet(23).to_string assert_equal "172.16.8.0/22", @ip.supernet(22).to_string end diff --git a/test/ipaddress/ipv6_test.rb b/test/ipaddress/ipv6_test.rb index 898938f..9d9ff3e 100644 --- a/test/ipaddress/ipv6_test.rb +++ b/test/ipaddress/ipv6_test.rb @@ -224,7 +224,35 @@ class IPv6Test < Test::Unit::TestCase "2001:db8::6","2001:db8::7"] assert_equal expected, arr end - + + def test_method_compare + ip1 = @klass.new("2001:db8:1::1/64") + ip2 = @klass.new("2001:db8:2::1/64") + ip3 = @klass.new("2001:db8:1::2/64") + ip4 = @klass.new("2001:db8:1::1/65") + + # ip2 should be greater than ip1 + assert_equal true, ip2 > ip1 + assert_equal false, ip1 > ip2 + assert_equal false, ip2 < ip1 + # ip3 should be less than ip2 + assert_equal true, ip2 > ip3 + assert_equal false, ip2 < ip3 + # ip1 should be less than ip3 + assert_equal true, ip1 < ip3 + assert_equal false, ip1 > ip3 + assert_equal false, ip3 < ip1 + # ip1 should be equal to itself + assert_equal true, ip1 == ip1 + # ip4 should be greater than ip1 + assert_equal true, ip1 < ip4 + assert_equal false, ip1 > ip4 + # test sorting + arr = ["2001:db8:1::1/64","2001:db8:1::1/65", + "2001:db8:1::2/64","2001:db8:2::1/64"] + assert_equal arr, [ip1,ip2,ip3,ip4].sort.map{|s| s.to_string} + end + def test_classmethod_expand compressed = "2001:db8:0:cd30::" expanded = "2001:0db8:0000:cd30:0000:0000:0000:0000" |