diff --git a/manualtest/game/JTableTest.java b/manualtest/game/JTableTest.java index cae8839326e77b01bcaf506945259e05a744fe8c..40b30b9ca202250ad594f95c1f4afc869c0fde17 100644 --- a/manualtest/game/JTableTest.java +++ b/manualtest/game/JTableTest.java @@ -26,7 +26,7 @@ public class JTableTest { JButton stopButton = new JButton("Stop"); startButton.addActionListener(new StartButtonListener(testModel)); stepButton.addActionListener(new StepButtonListener(testModel)); - stopButton.addActionListener(new StopButtonListener(testModel)); + stopButton.addActionListener(new StopButtonListener(testModel)); JPanel bottomPanel = new JPanel(); bottomPanel.add(stepButton); bottomPanel.add(startButton); diff --git a/test/game/GameLogicTest.java b/test/game/GameLogicTest.java index 3204d883c9b0de5a51252c7a146646a95be3b0b1..97e91e5df4287ce465c4d22bd57056caca0b3bcd 100644 --- a/test/game/GameLogicTest.java +++ b/test/game/GameLogicTest.java @@ -18,23 +18,23 @@ class GameLogicTest { @Test void testStep1() { - testModel.setValueAt(true, 0, 1); //-+ -> +- - testModel.setValueAt(true, 1, 0); //++ -> -- + testModel.setValueAt(true, 0, 1); //-+ -> ++ + testModel.setValueAt(true, 1, 0); //++ -> ++ testModel.setValueAt(true, 1, 1); testModel.step(); assertTrue((boolean) testModel.getValueAt(0, 0)); - assertFalse((boolean) testModel.getValueAt(0, 1)); - assertFalse((boolean) testModel.getValueAt(1, 0)); - assertFalse((boolean) testModel.getValueAt(1, 1)); + assertTrue((boolean) testModel.getValueAt(0, 1)); + assertTrue((boolean) testModel.getValueAt(1, 0)); + assertTrue((boolean) testModel.getValueAt(1, 1)); testModel.step(); - assertFalse((boolean) testModel.getValueAt(0, 0)); - assertFalse((boolean) testModel.getValueAt(0, 1)); - assertFalse((boolean) testModel.getValueAt(1, 0)); - assertFalse((boolean) testModel.getValueAt(1, 1)); + assertTrue((boolean) testModel.getValueAt(0, 0)); + assertTrue((boolean) testModel.getValueAt(0, 1)); + assertTrue((boolean) testModel.getValueAt(1, 0)); + assertTrue((boolean) testModel.getValueAt(1, 1)); } } diff --git a/test/game/JsonTest.java b/test/game/JsonTest.java new file mode 100644 index 0000000000000000000000000000000000000000..4e5e8f7f800ce78e51827c10fcfc03101fb6e638 --- /dev/null +++ b/test/game/JsonTest.java @@ -0,0 +1,58 @@ +package game; + +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; + +import static org.junit.jupiter.api.Assertions.*; + +import junit.framework.Assert.*; + +import javax.swing.*; +import java.io.File; +import java.io.FileNotFoundException; +import java.io.IOException; + +public class JsonTest { + private GameBoard board; + private JFileChooser chooser; + + @BeforeEach + public void setUp() { + board = new GameBoard(10, 10); + chooser = new JFileChooser(); + board.get(5, 5).setAlive(true); + board.get(5, 6).setAlive(true); + board.get(5, 7).setAlive(true); + board.get(5, 8).setAlive(true); + board.get(5, 9).setAlive(true); + } + + @Test + public void saveLoadTest() throws FileNotFoundException { + int returnVal = chooser.showSaveDialog(new JFrame()); + File destination; + if (returnVal == JFileChooser.APPROVE_OPTION) { + destination = chooser.getSelectedFile(); + try { + GameBoardJson.saveToFile(board, destination); + } catch (IOException e) { + e.printStackTrace(); + } + + int returnVal2 = chooser.showOpenDialog(new JFrame()); + File savedFile; + if (returnVal2 == JFileChooser.APPROVE_OPTION) { + savedFile = chooser.getSelectedFile(); + GameBoard loadedBoard; + + loadedBoard = GameBoardJson.loadFromFile(savedFile); + + + for (int i = 0; i < 10; i++) + for (int j = 1; j < 10; j++) { + assertEquals(board.get(i, j).isAlive(), loadedBoard.get(i, j).isAlive()); + } + } + } + } +}