• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2011 The Android Open Source Project
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 package com.android.inputmethod.latin.makedict;
18 
19 import com.android.inputmethod.latin.makedict.FormatSpec.DictionaryOptions;
20 import com.android.inputmethod.latin.makedict.FusionDictionary.PtNodeArray;
21 
22 import junit.framework.TestCase;
23 
24 import java.util.ArrayList;
25 import java.util.HashMap;
26 
27 /**
28  * Unit tests for BinaryDictEncoderUtils.flattenTree().
29  */
30 public class BinaryDictEncoderFlattenTreeTests extends TestCase {
31     // Test the flattened array contains the expected number of nodes, and
32     // that it does not contain any duplicates.
testFlattenNodes()33     public void testFlattenNodes() {
34         final FusionDictionary dict = new FusionDictionary(new PtNodeArray(),
35                 new DictionaryOptions(new HashMap<String, String>()));
36         dict.add("foo", new ProbabilityInfo(1), false /* isNotAWord */,
37                 false /* isPossiblyOffensive */);
38         dict.add("fta", new ProbabilityInfo(1), false /* isNotAWord */,
39                 false /* isPossiblyOffensive */);
40         dict.add("ftb", new ProbabilityInfo(1), false /* isNotAWord */,
41                 false /* isPossiblyOffensive */);
42         dict.add("bar", new ProbabilityInfo(1), false /* isNotAWord */,
43                 false /* isPossiblyOffensive */);
44         dict.add("fool", new ProbabilityInfo(1), false /* isNotAWord */,
45                 false /* isPossiblyOffensive */);
46         final ArrayList<PtNodeArray> result =
47                 BinaryDictEncoderUtils.flattenTree(dict.mRootNodeArray);
48         assertEquals(4, result.size());
49         while (!result.isEmpty()) {
50             final PtNodeArray n = result.remove(0);
51             assertFalse("Flattened array contained the same node twice", result.contains(n));
52         }
53     }
54 }
55