about summary refs log tree commit
path: root/test/test_nodes.rb
diff options
context:
space:
mode:
authorcodeout <goodies@codeout.net>2012-10-03 20:57:13 +0900
committerEric Wong <normalperson@yhbt.net>2012-10-04 03:20:43 -0700
commit523c6a46b06a726d63aa7a27840b79586f356bb5 (patch)
treee1db845c24704b15dda6c4706f58b13744ecc77d /test/test_nodes.rb
parenta5be0f72618bcb2c82ee5131f4899abb3d9db529 (diff)
downloadrpatricia-523c6a46b06a726d63aa7a27840b79586f356bb5.tar.gz
Added a method 'nodes' to return all nodes in ruby's Hash.
This is useful when a ruby code requires nodes list for example,
and also it helps when we sort user data by prefix.

[ew: minor compiler compatibility fixes]
Diffstat (limited to 'test/test_nodes.rb')
-rw-r--r--test/test_nodes.rb29
1 files changed, 29 insertions, 0 deletions
diff --git a/test/test_nodes.rb b/test/test_nodes.rb
new file mode 100644
index 0000000..580a1f9
--- /dev/null
+++ b/test/test_nodes.rb
@@ -0,0 +1,29 @@
+require 'test/unit'
+require 'rpatricia'
+
+class TestShowNodes < Test::Unit::TestCase
+
+  def test_nodes
+    t = Patricia.new
+    string = "pref_10"
+    array = [:something]
+    t.add("127.0.0.0/24")
+    t.add("192.168.1.0/24")
+    t.add("192.168.2.0/24")
+    t.add("192.168.3.100")
+    t.add("10.0.0.0/8", string)
+    t.add("10.0.0.0/9", array)
+
+    assert_equal({"10.0.0.0/8" => "pref_10",
+                  "10.0.0.0/9" => [:something],
+                  "127.0.0.0/24" => "",
+                  "192.168.1.0/24" => "",
+                  "192.168.2.0/24" => "",
+                  "192.168.3.100/32" => ""},
+                  t.nodes)
+
+    assert(string.object_id != t.nodes["10.0.0.0/8"].object_id)
+    assert(array.object_id == t.nodes["10.0.0.0/9"].object_id)
+  end
+
+end