This commit is contained in:
osp1 2020-04-30 17:06:10 +01:00
commit b515c12bf8
3 changed files with 50 additions and 29 deletions

View file

@ -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")); flashcardIcon.setImage(new Image("file:src/main/resources/assets/icons/black_icons/50px/flashcard-50.png"));
flashcardsText.setFill(Color.BLACK); 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()); testWord.setText(Application.practiceList.getFirst().getEnglish());
wordType.setText("English"); wordType.setText("English");
} else{ } else{ // Else display the word definition first.
testWord.setText(Application.practiceList.getFirst().getWelsh()); testWord.setText(Application.practiceList.getFirst().getWelsh());
wordType.setText("Welsh"); wordType.setText("Welsh");
} }
updateCounter(); updateCounter();
card = flashcard; 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")); 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")); 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 statement to check the start of the practiceList hasn't been reached before moving to the previous card.
if (index > 0) { if (index > 0) {
index--; index--;
} updateCounter();
updateCounter();
if(isSortedByEnglish){ if (isSortedByEnglish) { // If the current language ordering is by english, display the english word first.
testWord.setText(Application.practiceList.get(index).getEnglish()); testWord.setText(Application.practiceList.get(index).getEnglish());
wordType.setText("English"); wordType.setText("English");
} else{ } else { // Else display the word definition first.
testWord.setText(Application.practiceList.get(index).getWelsh()); testWord.setText(Application.practiceList.get(index).getWelsh());
wordType.setText("Welsh"); wordType.setText("Welsh");
}
} }
} }
@ -126,19 +126,19 @@ public class FlashcardController extends SharedCodeController {
@FXML @FXML
private void handleNextCard() { private void handleNextCard() {
// If statement to check the end of the practiceList hasn't been reached before moving to the next card. // 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++; index++;
} updateCounter();
updateCounter();
if(isSortedByEnglish){ if (isSortedByEnglish) { // If the current language ordering is by english, display the english word first.
testWord.setText(Application.practiceList.get(index).getEnglish()); testWord.setText(Application.practiceList.get(index).getEnglish());
wordType.setText("English"); wordType.setText("English");
} else{ } else { // Else display the word definition first.
testWord.setText(Application.practiceList.get(index).getWelsh()); testWord.setText(Application.practiceList.get(index).getWelsh());
wordType.setText("Welsh"); wordType.setText("Welsh");
} }
}
} }
/** /**

View file

@ -20,6 +20,11 @@ import uk.ac.aber.cs22120.group20.json.DictionaryEntry;
* @see AssessmentGenerator * @see AssessmentGenerator
*/ */
abstract public class SharedCodeController { abstract public class SharedCodeController {
// //////////////// //
// Class variables. //
// //////////////// //
static boolean isSortedByEnglish = true; static boolean isSortedByEnglish = true;
static int sideBarWidth = 50; static int sideBarWidth = 50;

View file

@ -3,6 +3,8 @@ package uk.ac.aber.cs22120.group20.test;
import org.junit.jupiter.api.Test; import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.AfterAll; import org.junit.jupiter.api.AfterAll;
import org.junit.jupiter.api.BeforeAll; 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.DictionaryEntry;
import uk.ac.aber.cs22120.group20.json.JsonProcessing; 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 * 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. * correctly loading and saving to and from the JSON file.
* @Author * @author Tom Perry [top19]
* @Version * @version 0.1 Initial development.
* @See * @see JsonProcessing
* @see DictionaryEntry
*/ */
public class JSONTest { public class JSONTest {
static LinkedList<DictionaryEntry> testList; static LinkedList<DictionaryEntry> testList;
LinkedList<DictionaryEntry> loadedList; LinkedList<DictionaryEntry> loadedList;
@ -27,15 +31,20 @@ public class JSONTest {
static JsonProcessing processor = new JsonProcessing(); 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 @BeforeAll
public static void setupTest() { public static void setupTest() {
// Populate a test list with DictionaryEntrys that is to be used for the loading/saving tests. // 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"), 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","other"), new DictionaryEntry("abroad","dramor","other"), new DictionaryEntry("above","uwchben", DictionaryEntry.wordTypeEnum.other), new DictionaryEntry("abroad","dramor", DictionaryEntry.wordTypeEnum.other),
new DictionaryEntry("abstract","haniaethol","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"); testFile = new File("src/main/java/uk/ac/aber/cs22120/group20/test/jsontest.json");
// Save the testList to the testFile. // 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. * JUnit test to check that the JSON file has been correctly loaded.
* @see JsonProcessing
* @see DictionaryEntry
*/ */
@Test @Test
public void testLoad(){ public void testLoad(){
@ -56,10 +67,12 @@ public class JSONTest {
/** /**
* JUnit test to check that any changes to the list of definitions are * JUnit test to check that any changes to the list of definitions are
* updated and saved to the JSON file accordingly. * updated and saved to the JSON file accordingly.
* @see JsonProcessing
* @see DictionaryEntry
*/ */
@Test public void testSave(){ @Test public void testSave(){
// Add an additional word to the testList and save it to jsontest. // 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); 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. // 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()); assertArrayEquals(testList.toArray(), loadedList.toArray());
} }
/**
* Method that is ran after the JUnit tests have finished to remove the JSON test file from program.
*/
@AfterAll @AfterAll
public static void deleteFile() { public static void deleteFile() {
testFile.delete(); testFile.delete();