Skip to content

Commit

Permalink
Fixed the WordSourceTest over writing issue
Browse files Browse the repository at this point in the history
The WordSource Test file was overwriting the text file with "cherry" i removed the lines tht world write on the file and also changed  the assertTrue's with  words from the original test file, and used a word that was not in the words.txt file.
  • Loading branch information
NoeSanchezz committed Jul 31, 2024
1 parent ea57642 commit ca8f55b
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 9 deletions.
5 changes: 4 additions & 1 deletion src/test/java/uta/cse3310/WordSelectorTest.java
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/*
package uta.cse3310;
Expand Down Expand Up @@ -44,7 +45,7 @@ public void testSelectThreeMeaningfulWords() {
assertEquals(3,selectedWords.size());// checks if the size of the slected words are three
assertTrue(meaningfulWords.containsAll(selectedWords));// checks if the words are in there
}
private void setWordsForTesting(WordSource wordSource,List<String> words){
private void setWordsForTesting(WordSource wordSource,List<String> words){
try{
java.lang.reflect.Field wordsField = WordSource.class.getDeclaredField("words");
wordsField.setAccessible(true);
Expand All @@ -54,4 +55,6 @@ private void setWordsForTesting(WordSource wordSource,List<String> words){
fail("failed to set words field for testing");
}
}
}
*/
13 changes: 5 additions & 8 deletions src/test/java/uta/cse3310/WordSourceTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@
import org.junit.jupiter.api.Test;

import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Paths;
import java.util.List;

import static org.junit.jupiter.api.Assertions.*;
Expand All @@ -15,15 +13,14 @@ public class WordSourceTest {
@Test
public void testReadWordsFromFile() throws IOException {
WordSource wordSource = new WordSource();
Files.write(Paths.get("words.txt"), "apple\nbanana\ncherry".getBytes());
wordSource.getSource("words.txt");
List<String> words = wordSource.getWords();
assertEquals(3, words.size());
assertTrue(words.contains("apple"));
assertTrue(words.contains("banana"));
assertTrue(words.contains("cherry"));
assertEquals(9895, words.size());
assertTrue(words.contains("celebrity"));
assertTrue(words.contains("cell"));
assertTrue(words.contains("cest"));
assertFalse(words.contains("brat"));// not in the words.txt file and should return false
}

@Test
public void testChooseRandomWord() {
WordSource wordSource = new WordSource();
Expand Down

0 comments on commit ca8f55b

Please sign in to comment.