diff --git a/.idea/.gitignore b/.idea/.gitignore
new file mode 100644
index 00000000..13566b81
--- /dev/null
+++ b/.idea/.gitignore
@@ -0,0 +1,8 @@
+# Default ignored files
+/shelf/
+/workspace.xml
+# Editor-based HTTP Client requests
+/httpRequests/
+# Datasource local storage ignored files
+/dataSources/
+/dataSources.local.xml
diff --git a/.idea/.name b/.idea/.name
new file mode 100644
index 00000000..38a05237
--- /dev/null
+++ b/.idea/.name
@@ -0,0 +1 @@
+jogo-do-oito-do-estagiario-gpt
\ No newline at end of file
diff --git a/.idea/misc.xml b/.idea/misc.xml
new file mode 100644
index 00000000..d972cff6
--- /dev/null
+++ b/.idea/misc.xml
@@ -0,0 +1,6 @@
+
+
+
+
+
+
\ No newline at end of file
diff --git a/.idea/modules.xml b/.idea/modules.xml
new file mode 100644
index 00000000..24b10e54
--- /dev/null
+++ b/.idea/modules.xml
@@ -0,0 +1,8 @@
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/.idea/vcs.xml b/.idea/vcs.xml
new file mode 100644
index 00000000..35eb1ddf
--- /dev/null
+++ b/.idea/vcs.xml
@@ -0,0 +1,6 @@
+
+
+
+
+
+
\ No newline at end of file
diff --git a/jogo-oito/src/main/java/controller/Controller.java b/jogo-oito/src/main/java/controller/Controller.java
new file mode 100644
index 00000000..add77001
--- /dev/null
+++ b/jogo-oito/src/main/java/controller/Controller.java
@@ -0,0 +1,40 @@
+package controller;
+
+import service.interfaces.Cell;
+import java.util.List;
+import service.GraphImpl;
+
+public class Controller {
+
+ private final service.interfaces.Graph graph;
+
+ public Controller() {
+ this.graph = new GraphImpl();
+ }
+
+ public void feedback() {
+ this.graph.feedback();
+ }
+
+ public void setter() {
+ this.graph.setter();
+ }
+
+ public List getCells() {
+ return this.graph.getCells();
+ }
+
+ public void swap(Integer keyCode) {
+ this.graph.swap(keyCode);
+ }
+
+ public Boolean checkGameOver() {
+ return this.graph.checkGameOver();
+
+ }
+
+ public void click(Integer cellValue) {
+ this.graph.click(cellValue);
+ }
+
+}
diff --git a/jogo-oito/src/main/java/facade/Controller.java b/jogo-oito/src/main/java/facade/Controller.java
deleted file mode 100644
index 28c6df1b..00000000
--- a/jogo-oito/src/main/java/facade/Controller.java
+++ /dev/null
@@ -1,41 +0,0 @@
-package facade;
-
-import interfaces.Graph;
-import interfaces.Vertex;
-import java.util.List;
-import util.Board;
-
-public class Controller {
-
- private final Graph board;
-
- public Controller() {
- this.board = new Board();
- }
-
- public void feedback() {
- this.board.feedback();
- }
-
- public void setting() {
- this.board.setting();
- }
-
- public List getCells() {
- return this.board.getCells();
- }
-
- public void swap(Integer keyCode) {
- this.board.swap(keyCode);
- }
-
- public Boolean checkGameOver() {
- return this.board.checkGameOver();
-
- }
-
- public void click(Integer cellValue) {
- this.board.click(cellValue);
- }
-
-}
diff --git a/jogo-oito/src/main/java/model/Matrix.java b/jogo-oito/src/main/java/model/Matrix.java
index 29586eaa..0745f371 100644
--- a/jogo-oito/src/main/java/model/Matrix.java
+++ b/jogo-oito/src/main/java/model/Matrix.java
@@ -4,7 +4,8 @@
*/
package model;
-import interfaces.Vertex;
+import service.CellImpl;
+import service.interfaces.Cell;
import java.util.ArrayList;
import java.util.List;
@@ -17,12 +18,12 @@ public final class Matrix {
private final Row firstRow;
private final Row secondRow;
private final Row thirdRow;
- public static List cells;
+ public static List cells;
public Matrix() {
Matrix.cells = new ArrayList<>();
- Cell.content = 1;
+ CellImpl.content = 1;
this.firstRow = new Row();
this.secondRow = new Row();
this.thirdRow = new Row();
@@ -30,14 +31,14 @@ public Matrix() {
}
private void defineAdjacent() {
- this.firstRow.initial.creatingVerticalAdjacent(secondRow.initial);
- this.secondRow.initial.creatingVerticalAdjacent(thirdRow.initial);
+ this.firstRow.initial.createVerticalAdjacent(secondRow.initial);
+ this.secondRow.initial.createVerticalAdjacent(thirdRow.initial);
- this.firstRow.center.creatingVerticalAdjacent(secondRow.center);
- this.secondRow.center.creatingVerticalAdjacent(thirdRow.center);
+ this.firstRow.center.createVerticalAdjacent(secondRow.center);
+ this.secondRow.center.createVerticalAdjacent(thirdRow.center);
- this.firstRow.last.creatingVerticalAdjacent(secondRow.last);
- this.secondRow.last.creatingVerticalAdjacent(thirdRow.last);
+ this.firstRow.last.createVerticalAdjacent(secondRow.last);
+ this.secondRow.last.createVerticalAdjacent(thirdRow.last);
this.changePositionToValidateTemplate();
}
@@ -47,20 +48,20 @@ private void changePositionToValidateTemplate(){
}
- public List getCells() {
+ public List getCells() {
return Matrix.cells;
}
- private final class Row {
+ private static final class Row {
- public final Cell initial;
- public final Cell center;
- public final Cell last;
+ public final CellImpl initial;
+ public final CellImpl center;
+ public final CellImpl last;
public Row() {
- this.initial = new Cell();
- this.center = new Cell();
- this.last = new Cell();
+ this.initial = new CellImpl();
+ this.center = new CellImpl();
+ this.last = new CellImpl();
this.defineAdjacent();
this.loadCells();
}
@@ -72,8 +73,8 @@ public void loadCells() {
}
public void defineAdjacent() {
- this.initial.creatingHorizontalAdjacent(this.center);
- this.center.creatingHorizontalAdjacent(this.last);
+ this.initial.createHorizontalAdjacent(this.center);
+ this.center.createHorizontalAdjacent(this.last);
}
}
diff --git a/jogo-oito/src/main/java/model/Cell.java b/jogo-oito/src/main/java/service/CellImpl.java
similarity index 64%
rename from jogo-oito/src/main/java/model/Cell.java
rename to jogo-oito/src/main/java/service/CellImpl.java
index 744d8d39..ea5e3ae2 100644
--- a/jogo-oito/src/main/java/model/Cell.java
+++ b/jogo-oito/src/main/java/service/CellImpl.java
@@ -1,25 +1,27 @@
-package model;
+package service;
+
+import service.interfaces.Cell;
+import service.interfaces.Edge;
+import util.Keyboard;
-import interfaces.Edge;
-import interfaces.Vertex;
import java.util.ArrayList;
import java.util.List;
import java.util.Objects;
import java.util.Optional;
-public class Cell implements Vertex {
+public class CellImpl implements Cell {
private Integer value;
private final List adjacents;
public static Integer content;
- public Cell(Integer value) {
+ public CellImpl(Integer value) {
this.value = value;
this.adjacents = new ArrayList<>();
}
- public Cell() {
- this.value = Cell.content++;
+ public CellImpl() {
+ this.value = CellImpl.content++;
this.adjacents = new ArrayList<>();
}
@@ -34,15 +36,15 @@ public Integer getValue() {
}
@Override
- public void creatingHorizontalAdjacent(Vertex cell) {
- this.adjacents.add(new Adjacent(Keyboard.LEFT, cell));
- cell.getAdjacents().add(new Adjacent(Keyboard.RIGHT, this));
+ public void createHorizontalAdjacent(service.interfaces.Cell cell) {
+ this.adjacents.add(new EdgeImpl(Keyboard.LEFT, cell));
+ cell.getAdjacents().add(new EdgeImpl(Keyboard.RIGHT, this));
}
@Override
- public void creatingVerticalAdjacent(Vertex cell) {
- this.adjacents.add(new Adjacent(Keyboard.UP, cell));
- cell.getAdjacents().add(new Adjacent(Keyboard.DOWN, this));
+ public void createVerticalAdjacent(service.interfaces.Cell cell) {
+ this.adjacents.add(new EdgeImpl(Keyboard.UP, cell));
+ cell.getAdjacents().add(new EdgeImpl(Keyboard.DOWN, this));
}
@Override
@@ -55,7 +57,7 @@ public String valueToText() {
@Override
public Edge getAdjacentByKeyCode(Keyboard key) {
- Adjacent edge = new Adjacent(key, null);
+ EdgeImpl edge = new EdgeImpl(key, null);
Integer indexEdge = this.adjacents.indexOf(edge);
return Optional.of(indexEdge)
.filter(index -> index != -1)
@@ -64,26 +66,26 @@ public Edge getAdjacentByKeyCode(Keyboard key) {
}
@Override
- public Vertex click(Keyboard key) {
+ public service.interfaces.Cell click(Keyboard key) {
Edge adjacent = this.getAdjacentByKeyCode(key);
return this.movement(adjacent);
}
- private Vertex movement(Edge adjacent) {
+ private service.interfaces.Cell movement(Edge adjacent) {
return Optional.ofNullable(adjacent)
.map(Edge::getCell)
.map(this::swapCells)
.orElse(this);
}
- private Vertex swapCells(Vertex movementCell) {
+ private service.interfaces.Cell swapCells(service.interfaces.Cell movementCell) {
this.setValue(movementCell.getValue());
movementCell.setValue(0);
return movementCell;
}
@Override
- public Vertex swapCells(Integer value) {
+ public service.interfaces.Cell swapCells(Integer value) {
return this.adjacents.stream()
.filter(adjacent -> Objects.equals(adjacent.getCell().getValue(), value))
.findFirst()
@@ -97,13 +99,13 @@ public List getAdjacents() {
}
@Override
- public void addAdjacents(Edge edge) {
+ public void addAdjacent(Edge edge) {
this.adjacents.add(edge);
}
@Override
public boolean equals(Object obj) {
- return Objects.equals(this.value, ((Cell) obj).value);
+ return Objects.equals(this.value, ((CellImpl) obj).value);
}
}
diff --git a/jogo-oito/src/main/java/model/Adjacent.java b/jogo-oito/src/main/java/service/EdgeImpl.java
similarity index 63%
rename from jogo-oito/src/main/java/model/Adjacent.java
rename to jogo-oito/src/main/java/service/EdgeImpl.java
index 6573c4f4..2205b6c7 100644
--- a/jogo-oito/src/main/java/model/Adjacent.java
+++ b/jogo-oito/src/main/java/service/EdgeImpl.java
@@ -2,22 +2,24 @@
* Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license
* Click nbfs://nbhost/SystemFileSystem/Templates/Classes/Class.java to edit this template
*/
-package model;
+package service;
+
+import service.interfaces.Edge;
+import service.interfaces.Cell;
+import util.Keyboard;
-import interfaces.Edge;
-import interfaces.Vertex;
import java.util.Objects;
/**
*
* @author allen
*/
-public class Adjacent implements Edge{
+public class EdgeImpl implements Edge{
private final Keyboard key;
- private final Vertex cell;
+ private final Cell cell;
- public Adjacent(Keyboard key, Vertex cell) {
+ public EdgeImpl(Keyboard key, Cell cell) {
this.key = key;
this.cell = cell;
}
@@ -28,13 +30,13 @@ public Keyboard getKey() {
}
@Override
- public Vertex getCell() {
+ public Cell getCell() {
return this.cell;
}
@Override
public boolean equals(Object obj) {
- return Objects.equals(((Adjacent) obj).getKey(), this.getKey());
+ return Objects.equals(((EdgeImpl) obj).getKey(), this.getKey());
}
}
diff --git a/jogo-oito/src/main/java/util/Board.java b/jogo-oito/src/main/java/service/GraphImpl.java
similarity index 73%
rename from jogo-oito/src/main/java/util/Board.java
rename to jogo-oito/src/main/java/service/GraphImpl.java
index e71e83ea..1178fdbe 100644
--- a/jogo-oito/src/main/java/util/Board.java
+++ b/jogo-oito/src/main/java/service/GraphImpl.java
@@ -1,7 +1,7 @@
-package util;
+package service;
-import interfaces.Graph;
-import interfaces.Vertex;
+import model.Matrix;
+import service.interfaces.Cell;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
@@ -9,17 +9,18 @@
import java.util.List;
import java.util.Optional;
import java.util.stream.IntStream;
-import model.Keyboard;
-import model.Matrix;
-public class Board implements Graph {
+import service.interfaces.Graph;
+import util.Keyboard;
+
+public class GraphImpl implements Graph {
- private List cells;
- private Vertex emptyCell;
+ private List cells;
+ private Cell emptyCell;
private Integer length;
private Matrix matrix;
- public Board() {
+ public GraphImpl() {
}
@Override
@@ -31,7 +32,7 @@ public void feedback() {
}
@Override
- public void setting() {
+ public void setter() {
this.matrix = new Matrix();
this.cells = this.matrix.getCells();
this.length = cells.size();
@@ -42,27 +43,26 @@ public void setting() {
private void shuffleCell() {
Iterator iterator = this.shuffleValues().iterator();
- this.cells.stream()
+ this.cells
.forEach(vertex -> vertex.setValue(iterator.next()));
}
private List shuffleValues() {
List values = new ArrayList<>();
this.cells.stream()
- .map(Vertex::getValue)
+ .map(Cell::getValue)
.forEach(values::add);
Collections.shuffle(values);
return values;
}
private void defineEmptyCell() {
- Optional minCell = this.cells.stream()
- .min(Comparator.comparing(cell -> cell.getValue()));
- minCell.ifPresent(cell -> {
- this.emptyCell = cell;
- });
+ Optional minCell = this.cells.stream()
+ .min(Comparator.comparing(Cell::getValue));
+ minCell.ifPresent(this::accept);
}
+
@Override
public void click(Integer cellValue) {
this.emptyCell = this.emptyCell.swapCells(cellValue);
@@ -75,12 +75,12 @@ public void swap(Integer keyCode) {
}
@Override
- public List getCells() {
+ public List getCells() {
return this.cells;
}
@Override
- public Vertex getEmptyCell() {
+ public Cell getEmptyCell() {
return this.emptyCell;
}
@@ -91,4 +91,7 @@ public Boolean checkGameOver() {
}
+ private void accept(Cell cell) {
+ this.emptyCell = cell;
+ }
}
diff --git a/jogo-oito/src/main/java/interfaces/Vertex.java b/jogo-oito/src/main/java/service/interfaces/Cell.java
similarity index 61%
rename from jogo-oito/src/main/java/interfaces/Vertex.java
rename to jogo-oito/src/main/java/service/interfaces/Cell.java
index 4ff55e4b..49ac0d48 100644
--- a/jogo-oito/src/main/java/interfaces/Vertex.java
+++ b/jogo-oito/src/main/java/service/interfaces/Cell.java
@@ -2,35 +2,35 @@
* Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license
* Click nbfs://nbhost/SystemFileSystem/Templates/Classes/Interface.java to edit this template
*/
-package interfaces;
+package service.interfaces;
import java.util.List;
-import model.Keyboard;
+import util.Keyboard;
/**
*
* @author allen
*/
-public interface Vertex {
+public interface Cell {
void setValue(Integer value);
Integer getValue();
- void creatingHorizontalAdjacent(Vertex cell);
+ void createHorizontalAdjacent(Cell cell);
- void creatingVerticalAdjacent(Vertex cell);
+ void createVerticalAdjacent(Cell cell);
String valueToText();
Edge getAdjacentByKeyCode(Keyboard key);
- Vertex click(Keyboard key);
+ Cell click(Keyboard key);
List getAdjacents();
- void addAdjacents(Edge edge);
+ void addAdjacent(Edge edge);
- Vertex swapCells(Integer value);
+ Cell swapCells(Integer value);
}
diff --git a/jogo-oito/src/main/java/interfaces/Edge.java b/jogo-oito/src/main/java/service/interfaces/Edge.java
similarity index 80%
rename from jogo-oito/src/main/java/interfaces/Edge.java
rename to jogo-oito/src/main/java/service/interfaces/Edge.java
index 20e56cd0..38a53574 100644
--- a/jogo-oito/src/main/java/interfaces/Edge.java
+++ b/jogo-oito/src/main/java/service/interfaces/Edge.java
@@ -2,9 +2,9 @@
* Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license
* Click nbfs://nbhost/SystemFileSystem/Templates/Classes/Class.java to edit this template
*/
-package interfaces;
+package service.interfaces;
-import model.Keyboard;
+import util.Keyboard;
/**
*
@@ -14,6 +14,6 @@ public interface Edge {
Keyboard getKey();
- Vertex getCell();
+ Cell getCell();
}
diff --git a/jogo-oito/src/main/java/interfaces/Graph.java b/jogo-oito/src/main/java/service/interfaces/Graph.java
similarity index 80%
rename from jogo-oito/src/main/java/interfaces/Graph.java
rename to jogo-oito/src/main/java/service/interfaces/Graph.java
index e22aad8e..2ad26b8c 100644
--- a/jogo-oito/src/main/java/interfaces/Graph.java
+++ b/jogo-oito/src/main/java/service/interfaces/Graph.java
@@ -2,7 +2,7 @@
* Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license
* Click nbfs://nbhost/SystemFileSystem/Templates/Classes/Interface.java to edit this template
*/
-package interfaces;
+package service.interfaces;
import java.util.List;
@@ -14,13 +14,13 @@ public interface Graph {
void feedback();
- void setting();
+ void setter();
void swap(Integer keyCode);
- List getCells();
+ List getCells();
- Vertex getEmptyCell();
+ Cell getEmptyCell();
void click(Integer cellValue);
diff --git a/jogo-oito/src/main/java/model/Keyboard.java b/jogo-oito/src/main/java/util/Keyboard.java
similarity index 98%
rename from jogo-oito/src/main/java/model/Keyboard.java
rename to jogo-oito/src/main/java/util/Keyboard.java
index ada8bb7a..2ae2a05e 100644
--- a/jogo-oito/src/main/java/model/Keyboard.java
+++ b/jogo-oito/src/main/java/util/Keyboard.java
@@ -2,7 +2,7 @@
* Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license
* Click nbfs://nbhost/SystemFileSystem/Templates/Classes/Class.java to edit this template
*/
-package model;
+package util;
import java.awt.event.KeyEvent;
import java.util.Arrays;
diff --git a/jogo-oito/src/main/java/view/JogoDosOito.java b/jogo-oito/src/main/java/view/JogoDosOito.java
index 2b687559..4b6b7dc4 100644
--- a/jogo-oito/src/main/java/view/JogoDosOito.java
+++ b/jogo-oito/src/main/java/view/JogoDosOito.java
@@ -1,7 +1,7 @@
package view;
-import facade.Controller;
-import interfaces.Vertex;
+import controller.Controller;
+import service.interfaces.Cell;
import java.awt.Font;
import java.awt.GridLayout;
import java.awt.event.ActionEvent;
@@ -21,13 +21,11 @@ public class JogoDosOito extends JFrame implements KeyListener {
private final List buttons;
private final Controller controller;
- private JButton reset;
- private JButton feedback;
public JogoDosOito() {
super("Jogo dos Oito");
this.controller = new Controller();
- this.controller.setting();
+ this.controller.setter();
this.buttons = new ArrayList<>();
}
@@ -54,7 +52,7 @@ private Integer textToValue(String text) {
.orElse(0);
}
- private JButton configButton(Vertex cell) {
+ private JButton configButton(Cell cell) {
JButton button = new JButton();
button.setFont(new Font("Arial", Font.BOLD, 36));
button.setText(cell.valueToText());
@@ -78,10 +76,10 @@ private void checkGameOver() {
}
private void configMenu() {
- this.reset = this.configReset();
- this.feedback = this.configFeedback();
- add(this.feedback);
- add(this.reset);
+ JButton reset = this.configReset();
+ JButton feedback = this.configFeedback();
+ add(feedback);
+ add(reset);
add(new JLabel(""));
}
@@ -105,7 +103,7 @@ private JButton configFeedback() {
private void resetGame() {
- this.controller.setting();
+ this.controller.setter();
this.updateBoard();
}
@@ -115,7 +113,7 @@ private void showFeedback() {
}
private void updateBoard() {
- List cells = this.controller.getCells();
+ List cells = this.controller.getCells();
IntStream.range(0, cells.size())
.forEach(index -> {
JButton button = this.buttons.get(index);
diff --git a/jogo-oito/src/test/java/game/AdjacentTest.java b/jogo-oito/src/test/java/game/AdjacentTest.java
deleted file mode 100644
index 49dd2ac3..00000000
--- a/jogo-oito/src/test/java/game/AdjacentTest.java
+++ /dev/null
@@ -1,39 +0,0 @@
-package game;
-
-import model.Adjacent;
-import model.Cell;
-import model.Keyboard;
-import interfaces.Edge;
-import interfaces.Vertex;
-import org.junit.jupiter.api.Test;
-import static org.junit.jupiter.api.Assertions.*;
-
-public class AdjacentTest {
-
- @Test
- public void testGetKey() {
- Edge edge = new Adjacent(Keyboard.RIGHT, null);
- assertEquals(Keyboard.RIGHT, edge.getKey());
- }
-
- @Test
- public void testGetCell() {
- Vertex cell = new Cell(1);
- Edge edge = new Adjacent(Keyboard.RIGHT, cell);
- assertEquals(cell, edge.getCell());
- }
-
- @Test
- public void testEquals() {
- Vertex cell1 = new Cell(1);
- Vertex cell2 = new Cell(2);
-
- Edge edge1 = new Adjacent(Keyboard.RIGHT, cell2);
- Edge edge2 = new Adjacent(Keyboard.LEFT, cell1);
-
- assertEquals(edge1.getCell().click(Keyboard.RIGHT), cell2);
- assertEquals(edge2.getCell().click(Keyboard.LEFT), cell1);
-
- }
-
-}
diff --git a/jogo-oito/src/test/java/game/BoardTest.java b/jogo-oito/src/test/java/game/BoardTest.java
index 7b39668f..945b7dff 100644
--- a/jogo-oito/src/test/java/game/BoardTest.java
+++ b/jogo-oito/src/test/java/game/BoardTest.java
@@ -4,39 +4,35 @@
*/
package game;
-/**
- *
- * @author allen
- */
-import model.Cell;
-import util.Board;
-import interfaces.Edge;
-import interfaces.Vertex;
+import service.CellImpl;
+import service.GraphImpl;
+import service.interfaces.Edge;
+import service.interfaces.Cell;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import static org.junit.jupiter.api.Assertions.*;
import java.util.List;
-import model.Keyboard;
+import util.Keyboard;
import org.junit.jupiter.api.Assertions;
public class BoardTest {
- private Board board;
+ private GraphImpl graphImpl;
@BeforeEach
- public void setUp() {
- board = new Board();
- board.feedback();
+ public void createVerticalAdjacent() {
+ graphImpl = new GraphImpl();
+ graphImpl.feedback();
}
@Test
public void testSwap() {
- Vertex emptyCell = board.getEmptyCell();
- Vertex cell = board.getCells().get(7);
+ Cell emptyCell = graphImpl.getEmptyCell();
+ Cell cell = graphImpl.getCells().get(7);
Integer cellValue = cell.getValue();
- board.click(cellValue);
+ graphImpl.click(cellValue);
assertEquals(cellValue, emptyCell.getValue());
assertEquals(0, cell.getValue());
@@ -44,7 +40,7 @@ public void testSwap() {
@Test
public void testGetCells() {
- List cells = board.getCells();
+ List cells = graphImpl.getCells();
assertNotNull(cells);
assertEquals(9, cells.size());
@@ -52,11 +48,11 @@ public void testGetCells() {
@Test
public void testDefineCellRelationships() {
- Vertex cell1 = board.getCells().get(1);
- Vertex cell2 = board.getCells().get(2);
+ Cell cell1 = graphImpl.getCells().get(1);
+ Cell cell2 = graphImpl.getCells().get(2);
- Edge adjacent1 = cell1.getAdjacentByKeyCode(model.Keyboard.LEFT);
- Edge adjacent2 = cell2.getAdjacentByKeyCode(model.Keyboard.RIGHT);
+ Edge adjacent1 = cell1.getAdjacentByKeyCode(Keyboard.LEFT);
+ Edge adjacent2 = cell2.getAdjacentByKeyCode(Keyboard.RIGHT);
assertEquals(cell2, adjacent1.getCell());
assertEquals(cell1, adjacent2.getCell());
@@ -64,11 +60,11 @@ public void testDefineCellRelationships() {
@Test
public void testClick() {
- Vertex emptyCell = board.getEmptyCell();
- Vertex cell = board.getCells().get(7);
+ Cell emptyCell = graphImpl.getEmptyCell();
+ Cell cell = graphImpl.getCells().get(7);
Integer cellValue = cell.getValue();
- board.click(cellValue);
+ graphImpl.click(cellValue);
assertEquals(cellValue, emptyCell.getValue());
assertEquals(0, cell.getValue());
@@ -76,36 +72,36 @@ public void testClick() {
@Test
public void testCheckGameOver() {
- Assertions.assertTrue(this.board.checkGameOver());
- board = new Board();
- board.setting();
- Assertions.assertFalse(board.checkGameOver());
+ Assertions.assertTrue(this.graphImpl.checkGameOver());
+ graphImpl = new GraphImpl();
+ graphImpl.setter();
+ Assertions.assertFalse(graphImpl.checkGameOver());
}
@Test
- public void testCellCreatingHorizontalAdjacent() {
- Vertex cell1 = new Cell(1);
- Vertex cell2 = new Cell(2);
+ public void testCellcreateHorizontalAdjacent() {
+ Cell cell1 = new CellImpl(1);
+ Cell cell2 = new CellImpl(2);
- cell1.creatingHorizontalAdjacent(cell2);
+ cell1.createHorizontalAdjacent(cell2);
- Edge adjacent1 = cell1.getAdjacentByKeyCode(model.Keyboard.LEFT);
- Edge adjacent2 = cell2.getAdjacentByKeyCode(model.Keyboard.RIGHT);
+ Edge adjacent1 = cell1.getAdjacentByKeyCode(Keyboard.LEFT);
+ Edge adjacent2 = cell2.getAdjacentByKeyCode(Keyboard.RIGHT);
assertEquals(cell2, adjacent1.getCell());
assertEquals(cell1, adjacent2.getCell());
}
@Test
- public void testCellCreatingVerticalAdjacent() {
- Vertex cell1 = new Cell(1);
- Vertex cell2 = new Cell(2);
+ public void testCellcreateVerticalAdjacent() {
+ Cell cell1 = new CellImpl(1);
+ Cell cell2 = new CellImpl(2);
- cell1.creatingVerticalAdjacent(cell2);
+ cell1.createVerticalAdjacent(cell2);
- Edge adjacent1 = cell1.getAdjacentByKeyCode(model.Keyboard.UP);
- Edge adjacent2 = cell2.getAdjacentByKeyCode(model.Keyboard.DOWN);
+ Edge adjacent1 = cell1.getAdjacentByKeyCode(Keyboard.UP);
+ Edge adjacent2 = cell2.getAdjacentByKeyCode(Keyboard.DOWN);
assertEquals(cell2, adjacent1.getCell());
assertEquals(cell1, adjacent2.getCell());
@@ -113,7 +109,7 @@ public void testCellCreatingVerticalAdjacent() {
@Test
public void testValueToText() {
- Vertex cell = new Cell(0);
+ Cell cell = new CellImpl(0);
assertEquals("", cell.valueToText());
cell.setValue(5);
@@ -122,37 +118,37 @@ public void testValueToText() {
@Test
public void testGetAdjacentByKeyCode() {
- Vertex cell1 = new Cell(1);
- Vertex cell2 = new Cell(2);
+ Cell cell1 = new CellImpl(1);
+ Cell cell2 = new CellImpl(2);
- cell1.creatingHorizontalAdjacent(cell2);
+ cell1.createHorizontalAdjacent(cell2);
- Edge adjacent = cell1.getAdjacentByKeyCode(model.Keyboard.LEFT);
+ Edge adjacent = cell1.getAdjacentByKeyCode(Keyboard.LEFT);
assertEquals(cell2, adjacent.getCell());
}
@Test
public void testClickDown() {
- board.swap(Keyboard.DOWN.getValue());
- Assertions.assertEquals(5, board.getCells().indexOf(board.getEmptyCell()));
+ graphImpl.swap(Keyboard.DOWN.getValue());
+ Assertions.assertEquals(5, graphImpl.getCells().indexOf(graphImpl.getEmptyCell()));
}
@Test
public void testClickUp() {
- board.swap(Keyboard.UP.getValue());
- Assertions.assertEquals(8, board.getCells().indexOf(board.getEmptyCell()));
+ graphImpl.swap(Keyboard.UP.getValue());
+ Assertions.assertEquals(8, graphImpl.getCells().indexOf(graphImpl.getEmptyCell()));
}
@Test
public void testClickRight() {
- board.swap(Keyboard.RIGHT.getValue());
- Assertions.assertEquals(7, board.getCells().indexOf(board.getEmptyCell()));
+ graphImpl.swap(Keyboard.RIGHT.getValue());
+ Assertions.assertEquals(7, graphImpl.getCells().indexOf(graphImpl.getEmptyCell()));
}
@Test
public void testClickLeft() {
- board.swap(Keyboard.LEFT.getValue());
- Assertions.assertEquals(8, board.getCells().indexOf(board.getEmptyCell()));
+ graphImpl.swap(Keyboard.LEFT.getValue());
+ Assertions.assertEquals(8, graphImpl.getCells().indexOf(graphImpl.getEmptyCell()));
}
}
diff --git a/jogo-oito/src/test/java/game/CellTest.java b/jogo-oito/src/test/java/game/CellImplTest.java
similarity index 55%
rename from jogo-oito/src/test/java/game/CellTest.java
rename to jogo-oito/src/test/java/game/CellImplTest.java
index a2742248..7a197527 100644
--- a/jogo-oito/src/test/java/game/CellTest.java
+++ b/jogo-oito/src/test/java/game/CellImplTest.java
@@ -4,48 +4,48 @@
*/
package game;
-import interfaces.Edge;
-import interfaces.Vertex;
+import service.CellImpl;
+import service.interfaces.Edge;
+import service.interfaces.Cell;
import java.util.List;
-import model.Adjacent;
-import model.Cell;
-import model.Keyboard;
+import service.EdgeImpl;
+import util.Keyboard;
import org.junit.jupiter.api.Test;
import static org.junit.jupiter.api.Assertions.*;
-public class CellTest{
+public class CellImplTest {
@Test
public void testSetValue() {
- Vertex cell = new Cell(0);
+ Cell cell = new CellImpl(0);
cell.setValue(5);
assertEquals(5, cell.getValue());
}
@Test
public void testGetValue() {
- Vertex cell = new Cell(10);
+ Cell cell = new CellImpl(10);
assertEquals(10, cell.getValue());
}
@Test
- public void testCreatingHorizontalAdjacent() {
- Vertex cell1 = new Cell(1);
- Vertex cell2 = new Cell(2);
+ public void testcreateHorizontalAdjacent() {
+ Cell cell1 = new CellImpl(1);
+ Cell cell2 = new CellImpl(2);
- cell1.creatingHorizontalAdjacent(cell2);
+ cell1.createHorizontalAdjacent(cell2);
assertEquals(1, cell1.getAdjacents().size());
assertEquals(1, cell2.getAdjacents().size());
}
@Test
- public void testCreatingVerticalAdjacent() {
- Vertex cell1 = new Cell(1);
- Vertex cell2 = new Cell(2);
+ public void testcreateVerticalAdjacent() {
+ Cell cell1 = new CellImpl(1);
+ Cell cell2 = new CellImpl(2);
- cell1.creatingVerticalAdjacent(cell2);
+ cell1.createVerticalAdjacent(cell2);
assertEquals(1, cell1.getAdjacents().size());
assertEquals(1, cell2.getAdjacents().size());
@@ -53,8 +53,8 @@ public void testCreatingVerticalAdjacent() {
@Test
public void testValueToText() {
- Vertex cell1 = new Cell(0);
- Vertex cell2 = new Cell(5);
+ Cell cell1 = new CellImpl(0);
+ Cell cell2 = new CellImpl(5);
assertEquals("", cell1.valueToText());
assertEquals("5", cell2.valueToText());
@@ -62,27 +62,27 @@ public void testValueToText() {
@Test
public void testGetAdjacentByKeyCode() {
- Vertex cell1 = new Cell(1);
- Vertex cell2 = new Cell(2);
- cell1.creatingHorizontalAdjacent(cell2);
+ Cell cell1 = new CellImpl(1);
+ Cell cell2 = new CellImpl(2);
+ cell1.createHorizontalAdjacent(cell2);
assertEquals(cell2, cell1.getAdjacentByKeyCode(Keyboard.LEFT).getCell());
}
@Test
public void testClick() {
- Vertex cell1 = new Cell(1);
- Vertex cell2 = new Cell(2);
- cell1.creatingHorizontalAdjacent(cell2);
+ Cell cell1 = new CellImpl(1);
+ Cell cell2 = new CellImpl(2);
+ cell1.createHorizontalAdjacent(cell2);
assertEquals(cell2, cell1.click(Keyboard.LEFT));
}
@Test
public void testSwapCells() {
- Vertex cell1 = new Cell(0);
- Vertex cell2 = new Cell(2);
- cell1.creatingHorizontalAdjacent(cell2);
+ Cell cell1 = new CellImpl(0);
+ Cell cell2 = new CellImpl(2);
+ cell1.createHorizontalAdjacent(cell2);
cell1.swapCells(cell2.getValue());
@@ -92,11 +92,11 @@ public void testSwapCells() {
@Test
public void testAddAdjacents() {
- Vertex cell1 = new Cell(1);
- Vertex cell2 = new Cell(2);
- Edge edge = new Adjacent(Keyboard.RIGHT, cell2);
+ Cell cell1 = new CellImpl(1);
+ Cell cell2 = new CellImpl(2);
+ Edge edge = new EdgeImpl(Keyboard.RIGHT, cell2);
- cell1.addAdjacents(edge);
+ cell1.addAdjacent(edge);
List adjacents = cell1.getAdjacents();
assertEquals(1, adjacents.size());
@@ -105,14 +105,14 @@ public void testAddAdjacents() {
@Test
public void defineAdjacents() {
- Vertex cell1 = new Cell(5);
- Vertex cell2 = new Cell(10);
- Vertex cell3 = new Cell(15);
- Vertex cell4 = new Cell(20);
-
- cell1.creatingVerticalAdjacent(cell2);
- cell1.creatingVerticalAdjacent(cell3);
- cell1.creatingHorizontalAdjacent(cell4);
+ Cell cell1 = new CellImpl(5);
+ Cell cell2 = new CellImpl(10);
+ Cell cell3 = new CellImpl(15);
+ Cell cell4 = new CellImpl(20);
+
+ cell1.createVerticalAdjacent(cell2);
+ cell1.createVerticalAdjacent(cell3);
+ cell1.createHorizontalAdjacent(cell4);
List adjacents = cell1.getAdjacents();
assertEquals(cell2, adjacents.get(0).getCell());
diff --git a/jogo-oito/src/test/java/game/EdgeImplTest.java b/jogo-oito/src/test/java/game/EdgeImplTest.java
new file mode 100644
index 00000000..5d297683
--- /dev/null
+++ b/jogo-oito/src/test/java/game/EdgeImplTest.java
@@ -0,0 +1,39 @@
+package game;
+
+import service.CellImpl;
+import service.EdgeImpl;
+import util.Keyboard;
+import service.interfaces.Edge;
+import service.interfaces.Cell;
+import org.junit.jupiter.api.Test;
+import static org.junit.jupiter.api.Assertions.*;
+
+public class EdgeImplTest {
+
+ @Test
+ public void testGetKey() {
+ Edge edge = new EdgeImpl(Keyboard.RIGHT, null);
+ assertEquals(Keyboard.RIGHT, edge.getKey());
+ }
+
+ @Test
+ public void testGetCell() {
+ Cell cell = new CellImpl(1);
+ Edge edge = new EdgeImpl(Keyboard.RIGHT, cell);
+ assertEquals(cell, edge.getCell());
+ }
+
+ @Test
+ public void testEquals() {
+ Cell cell1 = new CellImpl(1);
+ Cell cell2 = new CellImpl(2);
+
+ Edge edge1 = new EdgeImpl(Keyboard.RIGHT, cell2);
+ Edge edge2 = new EdgeImpl(Keyboard.LEFT, cell1);
+
+ assertEquals(edge1.getCell().click(Keyboard.RIGHT), cell2);
+ assertEquals(edge2.getCell().click(Keyboard.LEFT), cell1);
+
+ }
+
+}
diff --git a/senior-developer-challenge.iml b/senior-developer-challenge.iml
new file mode 100644
index 00000000..48426fcc
--- /dev/null
+++ b/senior-developer-challenge.iml
@@ -0,0 +1,9 @@
+
+
+
+
+
+
+
+
+
\ No newline at end of file
| | | | | | | | |