about summary refs log tree commit
path: root/test/test_include.rb
diff options
context:
space:
mode:
authorEric Wong <normalperson@yhbt.net>2010-09-02 13:56:39 -0700
committerEric Wong <normalperson@yhbt.net>2010-09-02 13:56:39 -0700
commit03daddf53a88bf1a3b7890d02577dd8921d70b76 (patch)
treeb98837aa15f79b0ab34cd7fe4bc433223ef6ad9d /test/test_include.rb
parent531c7ee4fade42ff115ba9df9ca1ca7d7ad631d6 (diff)
downloadrpatricia-03daddf53a88bf1a3b7890d02577dd8921d70b76.tar.gz
add Patricia#include? method
This behaves like Patricia#match_best, but is more
efficient as it does not need to allocate a new object
on successful matches.
Diffstat (limited to 'test/test_include.rb')
-rw-r--r--test/test_include.rb25
1 files changed, 25 insertions, 0 deletions
diff --git a/test/test_include.rb b/test/test_include.rb
new file mode 100644
index 0000000..303ad46
--- /dev/null
+++ b/test/test_include.rb
@@ -0,0 +1,25 @@
+require 'test/unit'
+require 'rpatricia'
+
+class TestInclude < Test::Unit::TestCase
+
+  def setup
+    @t = Patricia.new
+  end
+
+  def test_include_exact
+    @t.add '127.0.0.1'
+    assert_equal true, @t.include?('127.0.0.1')
+    assert_equal false, @t.include?('127.0.0.2')
+    @t.clear
+    assert_equal false, @t.include?('127.0.0.1')
+  end
+
+  def test_include_match_prefix
+    @t.add '127.0.0.0/8'
+    assert_equal true, @t.include?('127.0.0.32')
+    assert_equal false, @t.include?('12.0.0.32')
+    @t.clear
+    assert_equal false, @t.include?('127.0.0.32')
+  end
+end