Android Open Source - Wordjambalaya Dictionary Test






From Project

Back to project page Wordjambalaya.

License

The source code is released under:

GNU General Public License

If you think the Android project Wordjambalaya listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.

Java Source Code

package nz.co.martinpaulo.wordjambalaya;
//w  w  w  .  ja v a 2s.  c om
import android.test.AndroidTestCase;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

public class DictionaryTest extends AndroidTestCase {

    private Dictionary dictionary;
    private List<List<String>> columns;

    public void setUp() throws Exception {
        super.setUp();
        dictionary = Dictionary.buildDictionary(getContext());
        columns = new ArrayList<List<String>>();
    }

    public void tearDown() throws Exception {
        super.tearDown();
    }


    public void testOrderCharacters() {
        // shouldn't have build entire dictionary to test this...
        // but we need to know if it works, as we are using it in our tests.
        assertEquals("abeggr", dictionary.orderCharacters("beggar"));
    }

    public void testOrderCharactersOfWords() {
        // shouldn't have build entire dictionary to test this...
        // but we need to know if it works, as we are using it in our tests.
        assertEquals("abeeggmnory", dictionary.orderCharactersOf(Arrays.asList("beggar", "money")));
    }

    public void testGetTwoCandidateWordSets() throws Exception {
        String[] words = {"beggar", "thief"};
        assertDictionaryFindsCandidateWordSets(words);
    }

    public void testGetThreeCandidateWordSets() throws Exception {
        String[] words = {"bag", "of", "bones"};
        assertDictionaryFindsCandidateWordSets(words);
    }

    public void testGetFourCandidateWordSets() throws Exception {
        String[] words = {"broken", "down", "relics", "run"};
        assertDictionaryFindsCandidateWordSets(words);
    }

    private void assertDictionaryFindsCandidateWordSets(String[] words) {
        addWordsToColumns(words);
        String muddledWordsWithOrderedCharacters = dictionary.orderCharactersOf(Arrays.asList(words));
        List<List<String>> candidateAnswerSets = dictionary.getCandidateWordSets(muddledWordsWithOrderedCharacters, columns);
        assertEquals(getAnswer(words), candidateAnswerSets);
    }

    private void addWordsToColumns(String[] words) {
        for (String word : words) {
            columns.add(getColumn(word));
        }
    }

    private List<List<String>> getAnswer(String... words) {
        List<List<String>> result = new ArrayList<List<String>>();
        result.add(getColumn(words));
        return result;
    }

    private List<String> getColumn(String... words) {
        List<String> result = new ArrayList<String>();
        result.addAll(Arrays.asList(words));
        return result;
    }
}




Java Source Code List

nz.co.martinpaulo.wordjambalaya.ActivityJambalaya.java
nz.co.martinpaulo.wordjambalaya.ActivityResult.java
nz.co.martinpaulo.wordjambalaya.ApplicationTest.java
nz.co.martinpaulo.wordjambalaya.DictionaryTest.java
nz.co.martinpaulo.wordjambalaya.Dictionary.java
nz.co.martinpaulo.wordjambalaya.FragmentAnswer.java
nz.co.martinpaulo.wordjambalaya.FragmentResult.java
nz.co.martinpaulo.wordjambalaya.FragmentUnknownWords.java
nz.co.martinpaulo.wordjambalaya.UnknownWord.java
nz.co.martinpaulo.wordjambalaya.UnknownWords.java
nz.co.martinpaulo.wordjambalaya.WordDrawingView.java
nz.co.martinpaulo.wordjambalaya.WordLengthPicker.java