diff options
author | bluemonk <ceresa@gmail.com> | 2011-05-15 12:04:20 +0200 |
---|---|---|
committer | bluemonk <ceresa@gmail.com> | 2011-05-15 12:04:20 +0200 |
commit | 8599c8736b9902e8e6cd7d53455d8e29815d8187 (patch) | |
tree | 16c8cab8dfb5fab8aaa82e9a963c1ddcc7d2eb8d /test | |
parent | bda1e2bb645cf6dcba6fc65f9c9ef12d8003505e (diff) | |
download | ipaddress-8599c8736b9902e8e6cd7d53455d8e29815d8187.tar.gz |
Added IPv4#split and reworked IPv4#subnet as per RFC3531 (closes #14)
Diffstat (limited to 'test')
-rw-r--r-- | test/ipaddress/ipv4_test.rb | 87 |
1 files changed, 51 insertions, 36 deletions
diff --git a/test/ipaddress/ipv4_test.rb b/test/ipaddress/ipv4_test.rb index c6d6dfb..6d6386f 100644 --- a/test/ipaddress/ipv4_test.rb +++ b/test/ipaddress/ipv4_test.rb @@ -377,42 +377,57 @@ class IPv4Test < Test::Unit::TestCase assert_equal 24, ip.prefix.to_i end - def test_method_subnet - assert_raise(ArgumentError) {@ip.subnet(0)} - assert_raise(ArgumentError) {@ip.subnet(257)} - - arr = ["172.16.10.0/27", "172.16.10.32/27", "172.16.10.64/27", - "172.16.10.96/27", "172.16.10.128/27", "172.16.10.160/27", - "172.16.10.192/27", "172.16.10.224/27"] - assert_equal arr, @network.subnet(8).map {|s| s.to_string} - arr = ["172.16.10.0/27", "172.16.10.32/27", "172.16.10.64/27", - "172.16.10.96/27", "172.16.10.128/27", "172.16.10.160/27", - "172.16.10.192/26"] - assert_equal arr, @network.subnet(7).map {|s| s.to_string} - arr = ["172.16.10.0/27", "172.16.10.32/27", "172.16.10.64/27", - "172.16.10.96/27", "172.16.10.128/26", "172.16.10.192/26"] - assert_equal arr, @network.subnet(6).map {|s| s.to_string} - arr = ["172.16.10.0/27", "172.16.10.32/27", "172.16.10.64/27", - "172.16.10.96/27", "172.16.10.128/25"] - assert_equal arr, @network.subnet(5).map {|s| s.to_string} - arr = ["172.16.10.0/26", "172.16.10.64/26", "172.16.10.128/26", - "172.16.10.192/26"] - assert_equal arr, @network.subnet(4).map {|s| s.to_string} - arr = ["172.16.10.0/26", "172.16.10.64/26", "172.16.10.128/25"] - assert_equal arr, @network.subnet(3).map {|s| s.to_string} - arr = ["172.16.10.0/25", "172.16.10.128/25"] - assert_equal arr, @network.subnet(2).map {|s| s.to_string} - arr = ["172.16.10.0/24"] - assert_equal arr, @network.subnet(1).map {|s| s.to_string} - end - - def test_method_supernet - 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 + def test_method_split + assert_raise(ArgumentError) {@ip.split(0)} + assert_raise(ArgumentError) {@ip.split(257)} + + assert_equal @ip.network, @ip.split(1).first + + arr = ["172.16.10.0/27", "172.16.10.32/27", "172.16.10.64/27", + "172.16.10.96/27", "172.16.10.128/27", "172.16.10.160/27", + "172.16.10.192/27", "172.16.10.224/27"] + assert_equal arr, @network.split(8).map {|s| s.to_string} + arr = ["172.16.10.0/27", "172.16.10.32/27", "172.16.10.64/27", + "172.16.10.96/27", "172.16.10.128/27", "172.16.10.160/27", + "172.16.10.192/26"] + assert_equal arr, @network.split(7).map {|s| s.to_string} + arr = ["172.16.10.0/27", "172.16.10.32/27", "172.16.10.64/27", + "172.16.10.96/27", "172.16.10.128/26", "172.16.10.192/26"] + assert_equal arr, @network.split(6).map {|s| s.to_string} + arr = ["172.16.10.0/27", "172.16.10.32/27", "172.16.10.64/27", + "172.16.10.96/27", "172.16.10.128/25"] + assert_equal arr, @network.split(5).map {|s| s.to_string} + arr = ["172.16.10.0/26", "172.16.10.64/26", "172.16.10.128/26", + "172.16.10.192/26"] + assert_equal arr, @network.split(4).map {|s| s.to_string} + arr = ["172.16.10.0/26", "172.16.10.64/26", "172.16.10.128/25"] + assert_equal arr, @network.split(3).map {|s| s.to_string} + arr = ["172.16.10.0/25", "172.16.10.128/25"] + assert_equal arr, @network.split(2).map {|s| s.to_string} + arr = ["172.16.10.0/24"] + assert_equal arr, @network.split(1).map {|s| s.to_string} + end + + def test_method_subnet + assert_raise(ArgumentError) {@network.subnet(23)} + assert_raise(ArgumentError) {@network.subnet(33)} + assert_nothing_raised {@ip.subnet(30)} + arr = ["172.16.10.0/26", "172.16.10.64/26", "172.16.10.128/26", + "172.16.10.192/26"] + assert_equal arr, @network.subnet(26).map {|s| s.to_string} + arr = ["172.16.10.0/25", "172.16.10.128/25"] + assert_equal arr, @network.subnet(25).map {|s| s.to_string} + arr = ["172.16.10.0/24"] + assert_equal arr, @network.subnet(24).map {|s| s.to_string} + end + + def test_method_supernet + 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 def test_classmethod_parse_u32 @decimal_values.each do |addr,int| |