2010-07-25 Carlos Alberto Cortez <calberto.cortez@gmail.com>
[mono.git] / mcs / tools / monodoc / Lucene.Net / Test / Analysis / TestStopAnalyzer.cs
1 /*\r
2  * Copyright 2004 The Apache Software Foundation\r
3  * \r
4  * Licensed under the Apache License, Version 2.0 (the "License");\r
5  * you may not use this file except in compliance with the License.\r
6  * You may obtain a copy of the License at\r
7  * \r
8  * http://www.apache.org/licenses/LICENSE-2.0\r
9  * \r
10  * Unless required by applicable law or agreed to in writing, software\r
11  * distributed under the License is distributed on an "AS IS" BASIS,\r
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
13  * See the License for the specific language governing permissions and\r
14  * limitations under the License.\r
15  */\r
16 using System;\r
17 using NUnit.Framework;\r
18 namespace Lucene.Net.Analysis\r
19 {\r
20         [TestFixture]\r
21         public class TestStopAnalyzer\r
22         {\r
23                 private StopAnalyzer stop = new StopAnalyzer();\r
24                 \r
25                 private System.Collections.Hashtable inValidTokens = new System.Collections.Hashtable();\r
26                 \r
27         [TestFixtureSetUp]\r
28                 protected virtual void  SetUp()\r
29                 {\r
30                         for (int i = 0; i < StopAnalyzer.ENGLISH_STOP_WORDS.Length; i++)\r
31                         {\r
32                                 inValidTokens.Add(StopAnalyzer.ENGLISH_STOP_WORDS[i], StopAnalyzer.ENGLISH_STOP_WORDS[i]);\r
33                         }\r
34                 }\r
35                 \r
36         [Test]\r
37                 public virtual void  TestDefaults()\r
38                 {\r
39                         Assert.IsTrue(stop != null);\r
40                         System.IO.StringReader reader = new System.IO.StringReader("This is a test of the english stop analyzer");\r
41                         TokenStream stream = stop.TokenStream("test", reader);\r
42                         Assert.IsTrue(stream != null);\r
43                         Token token = null;\r
44                         try\r
45                         {\r
46                                 while ((token = stream.Next()) != null)\r
47                                 {\r
48                                         Assert.IsTrue(inValidTokens.Contains(token.TermText()) == false);\r
49                                 }\r
50                         }\r
51                         catch (System.IO.IOException e)\r
52                         {\r
53                                 Assert.IsTrue(false);\r
54                         }\r
55                 }\r
56                 \r
57         [Test]\r
58                 public virtual void  TestStopList()\r
59                 {\r
60                         System.Collections.Hashtable stopWordsSet = new System.Collections.Hashtable();\r
61                         stopWordsSet.Add("good", "good");\r
62                         stopWordsSet.Add("test", "test");\r
63                         stopWordsSet.Add("analyzer", "analyzer");\r
64 \r
65             // {{Aroush  how can we copy 'stopWordsSet' to 'System.String[]'?\r
66             System.String[] arrStopWordsSet = new System.String[3];
67             arrStopWordsSet[0] = "good";
68             arrStopWordsSet[1] = "test";
69             arrStopWordsSet[2] = "analyzer";
70             // Aroush}}
71 \r
72                         StopAnalyzer newStop = new StopAnalyzer(arrStopWordsSet);\r
73                         System.IO.StringReader reader = new System.IO.StringReader("This is a good test of the english stop analyzer");\r
74                         TokenStream stream = newStop.TokenStream("test", reader);\r
75                         Assert.IsTrue(stream != null);\r
76                         Token token = null;\r
77                         try\r
78                         {\r
79                                 while ((token = stream.Next()) != null)\r
80                                 {\r
81                                         System.String text = token.TermText();\r
82                                         Assert.IsTrue(stopWordsSet.Contains(text) == false);\r
83                                 }\r
84                         }\r
85                         catch (System.IO.IOException e)\r
86                         {\r
87                                 Assert.IsTrue(false);\r
88                         }\r
89                 }\r
90         }\r
91 }