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"));
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");
}
}
}
/**

View file

@ -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;

View file

@ -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<DictionaryEntry> testList;
LinkedList<DictionaryEntry> 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();