私は、同じ文字をセットポイントに含む同じ長さの複数の単語を見つけるために辞書を検索する方法を書いています。私。 2番目の文字としてbを持つ長さ5のすべての単語。セットポイントで特定の文字の単語を検索する(Java)
私はTDDで、この方法を書いている日食で、次のようにこれまでのところ、私の方法は次のとおりです。
private OpenQueue openQueue = new OpenQueue();
private boolean value;
private int lengthOfWord, numberFound;
private File inFile = new File("src/src/WordList"); //This is a text file
public Search(int length) {
this.lengthOfWord = length;
}
public boolean examine2(int crossingPoint, char letter) {
try {
Scanner input = new Scanner(inFile);
while (input.hasNextLine()) { //while there are words left to be read
String word = input.nextLine();
if(word.length() == lengthOfWord) { //if the word is of the right length
while(word.charAt(crossingPoint-1) == letter){
numberFound = numberFound + 1; //number of solutions is increased by one
openQueue.add(word);//word is added to the open queue
value = true; //value is true when at least one solution has been found
}
}
}
} catch (FileNotFoundException e) {
System.out.println("They File was not Found");
e.printStackTrace();
}
System.out.println(numberFound); //returns number of words found
return value; //should return true if there is at least one word
}
私のテストのために私は2番目の文字bを持ち、そこにあるすべての5つの文字の単語を検索しようと私が手動でチェックしたようにこれに合ういくつかの言葉。しかし、私がJUnitを実行すると、それは真実を期待していると言われますが、それは誤りです。
以前のようにSystem.out.println( "Here")に追加したように、コードはwhile(word.charAt(crossingPoint-1)== letter)ループまで実行されますが、コードはまで実行されます。
テストを実行しなくてもコードを実行できるようにするには、この問題を解決する方法がわかりません。ご協力いただきありがとうございます。
どのように関数を呼び出していますか?正確な議論は何ですか? –
'lengthOfWord'はどこに定義されていますか? – talnicolas
私はJUnitテストで関数を呼び出しています(formmattingについての謝罪): プライベート検索searchFiveLetterWord = new Search(5); @Test public void findAFiveLetterWordThatHasSecondLetterB(){ assertEquals( "2番目の文字Bを見つけて印刷します"、true、searchFiveLetterWord.examine2(2、b)); \t } – user977100