From 05fb74f9e8bddba3b1e1c206d466c2e73ac75f87 Mon Sep 17 00:00:00 2001 From: top19 Date: Thu, 30 Apr 2020 16:40:19 +0100 Subject: [PATCH 1/2] Fixed and documented JSONTest. --- .../aber/cs22120/group20/test/JSONTest.java | 32 ++++++++++++++----- 1 file changed, 24 insertions(+), 8 deletions(-) diff --git a/src/Welsh Vocabulary Tutor/src/main/java/uk/ac/aber/cs22120/group20/test/JSONTest.java b/src/Welsh Vocabulary Tutor/src/main/java/uk/ac/aber/cs22120/group20/test/JSONTest.java index 0bb4288..28e68ce 100644 --- a/src/Welsh Vocabulary Tutor/src/main/java/uk/ac/aber/cs22120/group20/test/JSONTest.java +++ b/src/Welsh Vocabulary Tutor/src/main/java/uk/ac/aber/cs22120/group20/test/JSONTest.java @@ -3,6 +3,8 @@ package uk.ac.aber.cs22120.group20.test; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.AfterAll; import org.junit.jupiter.api.BeforeAll; +import uk.ac.aber.cs22120.group20.javafx.Application; +import uk.ac.aber.cs22120.group20.javafx.SharedCodeController; import uk.ac.aber.cs22120.group20.json.DictionaryEntry; import uk.ac.aber.cs22120.group20.json.JsonProcessing; @@ -16,10 +18,12 @@ import static org.junit.jupiter.api.Assertions.assertArrayEquals; /** * Class that contains methods which will be used to test that the JSON package classes are * correctly loading and saving to and from the JSON file. - * @Author - * @Version - * @See + * @author Tom Perry [top19] + * @version 0.1 Initial development. + * @see JsonProcessing + * @see DictionaryEntry */ + public class JSONTest { static LinkedList testList; LinkedList loadedList; @@ -27,15 +31,20 @@ public class JSONTest { static JsonProcessing processor = new JsonProcessing(); + /** + * Setup method that is run before all of the tests, setting up a test list of DictionaryEntry's that it saved to a JSON test file. + * @see JsonProcessing + * @see DictionaryEntry + */ @BeforeAll public static void setupTest() { // Populate a test list with DictionaryEntrys that is to be used for the loading/saving tests. - testList = new LinkedList<>(Arrays.asList(new DictionaryEntry("abbey","abaty","nm"), new DictionaryEntry("about to", "ar fin", "other"), - new DictionaryEntry("above","uwchben","other"), new DictionaryEntry("abroad","dramor","other"), - new DictionaryEntry("abstract","haniaethol","other"))); + testList = new LinkedList<>(Arrays.asList(new DictionaryEntry("abbey","abaty", DictionaryEntry.wordTypeEnum.other), new DictionaryEntry("about to", "ar fin", DictionaryEntry.wordTypeEnum.other), + new DictionaryEntry("above","uwchben", DictionaryEntry.wordTypeEnum.other), new DictionaryEntry("abroad","dramor", DictionaryEntry.wordTypeEnum.other), + new DictionaryEntry("abstract","haniaethol", DictionaryEntry.wordTypeEnum.other))); - // Create a JSON test file in the test package + // Create a JSON test file in the test package. testFile = new File("src/main/java/uk/ac/aber/cs22120/group20/test/jsontest.json"); // Save the testList to the testFile. @@ -44,6 +53,8 @@ public class JSONTest { /** * JUnit test to check that the JSON file has been correctly loaded. + * @see JsonProcessing + * @see DictionaryEntry */ @Test public void testLoad(){ @@ -56,10 +67,12 @@ public class JSONTest { /** * JUnit test to check that any changes to the list of definitions are * updated and saved to the JSON file accordingly. + * @see JsonProcessing + * @see DictionaryEntry */ @Test public void testSave(){ // Add an additional word to the testList and save it to jsontest. - testList.add(new DictionaryEntry("beer", "cwrw", "nm")); + testList.add(new DictionaryEntry("beer", "cwrw", DictionaryEntry.wordTypeEnum.nm)); processor.writeOutJson("src/main/java/uk/ac/aber/cs22120/group20/test/jsontest.json", testList); // Load the DictionaryEntry's back from the file and check that they match the testList. @@ -67,6 +80,9 @@ public class JSONTest { assertArrayEquals(testList.toArray(), loadedList.toArray()); } + /** + * Method that is ran after the JUnit tests have finished to remove the JSON test file from program. + */ @AfterAll public static void deleteFile() { testFile.delete(); From 706ff1085dd91a822f802eb9d6184efb7f65dd82 Mon Sep 17 00:00:00 2001 From: top19 Date: Thu, 30 Apr 2020 16:55:42 +0100 Subject: [PATCH 2/2] Updated documentation for Flashcard and SharedCodeController. --- .../group20/javafx/FlashcardController.java | 42 +++++++++---------- .../group20/javafx/SharedCodeController.java | 5 +++ 2 files changed, 26 insertions(+), 21 deletions(-) diff --git a/src/Welsh Vocabulary Tutor/src/main/java/uk/ac/aber/cs22120/group20/javafx/FlashcardController.java b/src/Welsh Vocabulary Tutor/src/main/java/uk/ac/aber/cs22120/group20/javafx/FlashcardController.java index e80bda4..f3eeda8 100644 --- a/src/Welsh Vocabulary Tutor/src/main/java/uk/ac/aber/cs22120/group20/javafx/FlashcardController.java +++ b/src/Welsh Vocabulary Tutor/src/main/java/uk/ac/aber/cs22120/group20/javafx/FlashcardController.java @@ -71,17 +71,17 @@ public class FlashcardController extends SharedCodeController { flashcardIcon.setImage(new Image("file:src/main/resources/assets/icons/black_icons/50px/flashcard-50.png")); flashcardsText.setFill(Color.BLACK); - if(isSortedByEnglish){ + if(isSortedByEnglish){ // If the current language ordering is by english, display the english word first. testWord.setText(Application.practiceList.getFirst().getEnglish()); wordType.setText("English"); - } else{ + } else{ // Else display the word definition first. testWord.setText(Application.practiceList.getFirst().getWelsh()); wordType.setText("Welsh"); } updateCounter(); card = flashcard; - flashcard.setImage(new Image("file:src/main/resources/assets/flashcard/Flashcard.png")); + flashcard.setImage(new Image("file:src/main/resources/assets/flashcard/FlashCard.png")); leftArrow.setImage(new Image("file:src/main/resources/assets/icons/black_icons/50px/left-50.png")); rightArrow.setImage(new Image("file:src/main/resources/assets/icons/black_icons/50px/right-50.png")); } @@ -106,15 +106,15 @@ public class FlashcardController extends SharedCodeController { // If statement to check the start of the practiceList hasn't been reached before moving to the previous card. if (index > 0) { index--; - } - updateCounter(); + updateCounter(); - if(isSortedByEnglish){ - testWord.setText(Application.practiceList.get(index).getEnglish()); - wordType.setText("English"); - } else{ - testWord.setText(Application.practiceList.get(index).getWelsh()); - wordType.setText("Welsh"); + if (isSortedByEnglish) { // If the current language ordering is by english, display the english word first. + testWord.setText(Application.practiceList.get(index).getEnglish()); + wordType.setText("English"); + } else { // Else display the word definition first. + testWord.setText(Application.practiceList.get(index).getWelsh()); + wordType.setText("Welsh"); + } } } @@ -126,19 +126,19 @@ public class FlashcardController extends SharedCodeController { @FXML private void handleNextCard() { // If statement to check the end of the practiceList hasn't been reached before moving to the next card. - if (index < Application.practiceList.size()-1) { + if (index < Application.practiceList.size() - 1) { index++; - } - updateCounter(); + updateCounter(); - if(isSortedByEnglish){ - testWord.setText(Application.practiceList.get(index).getEnglish()); - wordType.setText("English"); - } else{ - testWord.setText(Application.practiceList.get(index).getWelsh()); - wordType.setText("Welsh"); - } + if (isSortedByEnglish) { // If the current language ordering is by english, display the english word first. + testWord.setText(Application.practiceList.get(index).getEnglish()); + wordType.setText("English"); + } else { // Else display the word definition first. + testWord.setText(Application.practiceList.get(index).getWelsh()); + wordType.setText("Welsh"); + } + } } /** diff --git a/src/Welsh Vocabulary Tutor/src/main/java/uk/ac/aber/cs22120/group20/javafx/SharedCodeController.java b/src/Welsh Vocabulary Tutor/src/main/java/uk/ac/aber/cs22120/group20/javafx/SharedCodeController.java index 4b567dc..94ba67c 100644 --- a/src/Welsh Vocabulary Tutor/src/main/java/uk/ac/aber/cs22120/group20/javafx/SharedCodeController.java +++ b/src/Welsh Vocabulary Tutor/src/main/java/uk/ac/aber/cs22120/group20/javafx/SharedCodeController.java @@ -20,6 +20,11 @@ import uk.ac.aber.cs22120.group20.json.DictionaryEntry; * @see AssessmentGenerator */ abstract public class SharedCodeController { + + // //////////////// // + // Class variables. // + // //////////////// // + static boolean isSortedByEnglish = true; static int sideBarWidth = 50;