rpatricia.git  about / heads / tags
see http://www.goto.info.waseda.ac.jp/~tatsuya/rpatricia/
blob 91e6f81a2c4c8b75a535628a0966225dbe298b62 1284 bytes (raw)
$ git show for-tatsuya:test/test_show_nodes.rb	# shows this blob on the CLI

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
 
require 'test/unit'
require 'rpatricia'
require 'stringio'

class TestShowNodes < Test::Unit::TestCase

  def test_show_nodes
    t = Patricia.new
    assert_nothing_raised do
      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", "pref_10")
    end
    begin
      oldout = $stdout
      $stdout = tmpout = StringIO.new
      assert_nothing_raised { t.show_nodes }
    ensure
      $stdout = oldout
    end
    expect = [
      "node: 10.0.0.0/8",
      "node: 127.0.0.0/24",
      "node: 192.168.1.0/24",
      "node: 192.168.2.0/24",
      "node: 192.168.3.100/32"
    ].join("\n") << "\n"
    assert_equal expect, tmpout.string
  end

  def test_show_nodes_specify_io
    t = Patricia.new
    assert_nothing_raised do
      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", "pref_10")
    end
    tmpout = StringIO.new
    assert_nothing_raised { t.show_nodes(tmpout) }
    expect = [
      "node: 10.0.0.0/8",
      "node: 127.0.0.0/24",
      "node: 192.168.1.0/24",
      "node: 192.168.2.0/24",
      "node: 192.168.3.100/32"
    ].join("\n") << "\n"
    assert_equal expect, tmpout.string
  end

end

git clone https://yhbt.net/rpatricia.git