|
What this is
Other links
The source code/* Anagram Game Application */ package com.toy.anagrams.lib; import java.util.Arrays; import junit.framework.TestCase; /** * Test of the functionality of {@link WordLibrary}. */ public class WordLibraryTest extends TestCase { public WordLibraryTest(String testName) { super(testName); } /** * Test of {@link WordLibrary#isCorrect}. */ public void testIsCorrect() { for (int i = 0; i < WordLibrary.getSize(); i++) { String clearWord = WordLibrary.getWord(i); String scrambledWord = WordLibrary.getScrambledWord(i); assertTrue("Scrambled word \"" + scrambledWord + "\" at index: " + i + " does not represent the word \"" + clearWord + "\"", isAnagram(clearWord, scrambledWord)); } } /** * Tests whether given anagram represents the word. * @param clearWord The word in clear text * @param scrambledWord Scrambled version of the word * @return true if the scrambledWord is correct anagram of clearWord */ private boolean isAnagram(String clearWord, String scrambledWord) { char[] clearArray = clearWord.toCharArray(); char[] scrambledArray = scrambledWord.toCharArray(); Arrays.sort(clearArray); Arrays.sort(scrambledArray); return Arrays.equals(clearArray, scrambledArray); } } |
... this post is sponsored by my books ... | |
#1 New Release! |
FP Best Seller |
Copyright 1998-2021 Alvin Alexander, alvinalexander.com
All Rights Reserved.
A percentage of advertising revenue from
pages under the /java/jwarehouse
URI on this website is
paid back to open source projects.