From 43607b610ba3dab678d3625e94415e3796dda68f Mon Sep 17 00:00:00 2001 From: fdai6499 Date: Fri, 20 Jan 2023 14:29:21 +0100 Subject: [PATCH] refactoring: rewrote tests --- src/main/java/src/GameField.java | 6 +-- src/main/java/src/MainFrame.java | 85 ++++++++++---------------------- src/test/java/GameFieldTest.java | 27 ++++------ 3 files changed, 35 insertions(+), 83 deletions(-) diff --git a/src/main/java/src/GameField.java b/src/main/java/src/GameField.java index 0cd80f7..653f516 100644 --- a/src/main/java/src/GameField.java +++ b/src/main/java/src/GameField.java @@ -159,11 +159,7 @@ public class GameField extends JPanel { public void unsetAllHintsFromField(int x, int y) { - for (int j = 1; j < 10; j++) { - - gameField[x][y].unsetHints(); - - } + gameField[y][x].unsetHints(); } public JLabel getActiveLabel(){ diff --git a/src/main/java/src/MainFrame.java b/src/main/java/src/MainFrame.java index 44b0884..7a57b6e 100644 --- a/src/main/java/src/MainFrame.java +++ b/src/main/java/src/MainFrame.java @@ -30,76 +30,31 @@ public class MainFrame extends JFrame { header.setBounds(125, 5, 250, 50); rootPanel.add(header); - GameField gameField = new GameField(360); gameField.setBounds(70, 50, 360, 360); rootPanel.add(gameField); int j = 0; + double d = 1.0; + String str = "Hallo"; - JPanel boxPanel = new JPanel(); - boxPanel.setBounds(100, 450, 300, 30); - boxPanel.setVisible(true); - boxPanel.setBackground(Color.GREEN); + JPanel boxPanel = setupJPanel(); boxPanel.setLayout(new BoxLayout(boxPanel, BoxLayout.X_AXIS)); rootPanel.add(boxPanel); - JPanel panel1 = new JPanel(); - panel1.setBackground(Color.BLUE); - panel1.setVisible(true); - panel1.setBorder(new LineBorder(Color.PINK, 1)); - boxPanel.add(panel1); - boxPanel.add(Box.createHorizontalStrut(5)); - panel1.addMouseListener(new MouseListener() { - @Override - public void mouseClicked(MouseEvent e) { - - } - - @Override - public void mousePressed(MouseEvent e) { - if (gameField.getActivePanel() != null) { - gameField.getActivePanel().setValue(1); - } - } - - @Override - public void mouseReleased(MouseEvent e) { - - } - - @Override - public void mouseEntered(MouseEvent e) { - - } - - @Override - public void mouseExited(MouseEvent e) { - - } - }); - - JLabel numLabel1 = new JLabel(); - numLabel1.setText("1"); - numLabel1.setLayout(null); - numLabel1.setVisible(true); - panel1.add(numLabel1); - - - - JPanel panel2 = new JPanel(); - panel2.setBackground(Color.BLUE); - panel2.setVisible(true); - panel2.setBorder(new LineBorder(Color.PINK, 1)); - boxPanel.add(panel2); - boxPanel.add(Box.createHorizontalStrut(5)); - - JLabel numLabel2 = new JLabel(); - numLabel2.setText("2"); - numLabel2.setLayout(null); - numLabel2.setVisible(true); - panel2.add(numLabel2); +// JPanel panel2 = new JPanel(); +// panel2.setBackground(Color.BLUE); +// panel2.setVisible(true); +// panel2.setBorder(new LineBorder(Color.PINK, 1)); +// boxPanel.add(panel2); +// boxPanel.add(Box.createHorizontalStrut(5)); +// +// JLabel numLabel2 = new JLabel(); +// numLabel2.setText("2"); +// numLabel2.setLayout(null); +// numLabel2.setVisible(true); +// panel2.add(numLabel2); @@ -129,6 +84,16 @@ public class MainFrame extends JFrame { rootPanel.add(correctButton); } + + + public JPanel setupJPanel() { + JPanel panel = new JPanel(); + panel.setBounds(100, 450, 300, 30); + panel.setVisible(true); + panel.setBackground(Color.GREEN); + return panel; + } + private JPanel setupHeader(int headerSize, int subheaderSize) { JPanel jPanel = new JPanel(); diff --git a/src/test/java/GameFieldTest.java b/src/test/java/GameFieldTest.java index cf65920..823bb5b 100644 --- a/src/test/java/GameFieldTest.java +++ b/src/test/java/GameFieldTest.java @@ -137,29 +137,20 @@ public class GameFieldTest { for (int i = 0; i < 9; i++) { for (int j = 0; j < 9; j++) { + gameField.setValue(i, j, i); + } + } - for (int k = 1; k < 10; k++) { - gameField.setHint(i, j, k); - } + Model model = new Model(gameField); + System.out.println(model); - gameField.unsetAllHintsFromField(i, j); + gameField.setHint(2, 2, 1); - Notes notes = gameField.getGameField()[i][j].getNote(); + boolean visible = gameField.getGameField()[2][2].getNote().getNotes()[0][0].isVisible(); - boolean a = true; - for (int k = 0, count = 1; k < 3; k++) { - for (int l = 0; l < 3; l++, count += 1) { - boolean visible = notes.getNotes()[l][k].isVisible(); - if (visible) { - a = false; - } - } - } + assertTrue(visible); - assertTrue(a); - } - } - } + } } \ No newline at end of file