natto 0.9.3 → 0.9.4

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,101 +0,0 @@
1
- # coding: utf-8
2
- require 'rbconfig'
3
- require 'nkf'
4
-
5
- # TestMeCabNode encapsulates tests for the basic
6
- # behavior of Natto::MeCabNode
7
- class TestMeCabNode < Test::Unit::TestCase
8
-
9
- host_os = RbConfig::CONFIG['host_os']
10
- # we need to transfrom from UTF-8 ot SJIS if we are on Windows!
11
- if host_os =~ /mswin|mingw/i
12
- TEST_STR = NKF.nkf("-Ws", '試験ですよ、これが。')
13
- else
14
- TEST_STR = '試験ですよ、これが。'
15
- end
16
-
17
- def setup
18
- nm = Natto::MeCab.new
19
- @nodes = []
20
- nm.parse(TEST_STR) { |n| @nodes << n }
21
- end
22
-
23
- def teardown
24
- @nodes = nil
25
- end
26
-
27
- # Tests the surface and feature accessors methods.
28
- def test_surface_and_feature_accessors
29
- raw = `echo #{TEST_STR} | mecab`.lines.to_a
30
- raw.delete_if {|e| e =~ /^(EOS|BOS|\t)/ }
31
- expected = {}
32
- raw.each do |l|
33
- tokens = l.split("\t")
34
- expected[tokens[0]]=tokens[1].strip
35
- end
36
-
37
- actual = {}
38
- @nodes.each do |n|
39
- actual[n.surface]=n.feature if (n.stat==Natto::MeCabNode::NOR_NODE ||
40
- n.stat==Natto::MeCabNode::UNK_NODE)
41
- end
42
-
43
- assert_equal(expected, actual)
44
- end
45
-
46
- # Tests MeCabNode#surface to show that it is consistent
47
- # no matter how many times it is invoked.
48
- def test_manysurfaces
49
- @nodes.each do |n|
50
- expected = n.surface
51
- 5.times { assert_equal(expected, n.surface) }
52
- end
53
- end
54
-
55
- # Tests MeCabNode#feature to show that it is consistent
56
- # no matter how many times it is invoked.
57
- def test_manyfeature
58
- @nodes.each do |n|
59
- expected = n.feature
60
- 5.times { assert_equal(expected, n.feature) }
61
- end
62
- end
63
-
64
- # Tests that the accessors of Natto::MeCabNode exist.
65
- # Note: Object#id is deprecated in 1.9.n, but comes with a warning
66
- # in 1.8.n
67
- def test_mecabnode_accessors
68
- node = @nodes[0]
69
- [ :prev,
70
- :next,
71
- :enext,
72
- :bnext,
73
- :rpath,
74
- :lpath,
75
- :surface,
76
- :feature,
77
- :id,
78
- :length,
79
- :rlength,
80
- :rcAttr,
81
- :lcAttr,
82
- :posid,
83
- :char_type,
84
- :stat,
85
- :isbest,
86
- :alpha,
87
- :beta,
88
- :prob,
89
- :wcost,
90
- :cost ].each do |nomme|
91
- assert_nothing_raised do
92
- node.send nomme
93
- end
94
- end
95
-
96
- # NoMethodError will be raised for anything else!
97
- assert_raise NoMethodError do
98
- node.send :unknown_attr
99
- end
100
- end
101
- end
data/test/test_natto.rb DELETED
@@ -1,12 +0,0 @@
1
- # coding: utf-8
2
- $: << 'lib'
3
- require 'rubygems' if RUBY_VERSION.to_f < 1.9
4
- require 'test/unit'
5
- require 'natto'
6
-
7
- [ '/test/natto/tc_mecab.rb',
8
- '/test/natto/tc_mecabnode.rb',
9
- '/test/natto/tc_dictionaryinfo.rb',
10
- '/test/natto/tc_binding.rb' ].each do |tc|
11
- require File.join(File.expand_path('.'), tc)
12
- end