Browse Source

refactoring: rewrote tests

remotes/origin/develop
fdai6499 2 years ago
parent
commit
43607b610b
  1. 6
      src/main/java/src/GameField.java
  2. 85
      src/main/java/src/MainFrame.java
  3. 27
      src/test/java/GameFieldTest.java

6
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(){

85
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();

27
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);
}
}
}
}
}
Loading…
Cancel
Save