Skip to content
Snippets Groups Projects
Commit c17e781e authored by hiba1907's avatar hiba1907
Browse files

code de la classe Coordinate avec les methodes codees testees

parent bf768551
No related branches found
No related tags found
No related merge requests found
Pipeline #38282 failed
Showing
with 12 additions and 16 deletions
File added
File added
File added
File added
File added
File added
File added
File added
File added
File added
File added
package matrix;
import java.util.ArrayList;
import java.util.List;
/**
......@@ -15,8 +16,7 @@ public record Coordinate(int x, int y) {
* @return A new {@link Coordinate} instance.
*/
public static Coordinate of(int x, int y) {
// TODO: compléter ce fabriquant
return null;
return new Coordinate(x, y) ;
}
/**
......@@ -25,8 +25,7 @@ public record Coordinate(int x, int y) {
* @return The left adjacent {@link Coordinate}.
*/
public Coordinate left() {
// TODO: à compléter
return null;
return new Coordinate(x-1, y);
}
/**
......@@ -35,8 +34,7 @@ public record Coordinate(int x, int y) {
* @return The right adjacent {@link Coordinate}.
*/
public Coordinate right() {
// TODO: à compléter
return null;
return new Coordinate(x+1, y);
}
/**
......@@ -45,8 +43,7 @@ public record Coordinate(int x, int y) {
* @return The above adjacent {@link Coordinate}.
*/
public Coordinate above() {
// TODO: à compléter
return null;
return new Coordinate(x,y+1);
}
/**
......@@ -55,8 +52,7 @@ public record Coordinate(int x, int y) {
* @return The below adjacent {@link Coordinate}.
*/
public Coordinate below() {
// TODO: à compléter
return null;
return new Coordinate(x, y-1);
}
/**
......@@ -73,8 +69,7 @@ public record Coordinate(int x, int y) {
* @return A list of orthogonal neighboring {@link Coordinate}s.
*/
public List<Coordinate> orthogonalNeighbours() {
// TODO: à compléter
return List.of();
return List.of(this.right(),this.left(),this.above(),this.below());
}
/**
......@@ -92,8 +87,7 @@ public record Coordinate(int x, int y) {
* @return A list of diagonal neighboring {@link Coordinate}s.
*/
public List<Coordinate> diagonalNeighbours() {
// TODO: à compléter
return List.of();
return List.of(this.above().left(), this.above().right(),this.below().left(),this.below().right());
}
/**
......@@ -111,8 +105,10 @@ public record Coordinate(int x, int y) {
* @return A list of all neighboring {@link Coordinate}s.
*/
public List<Coordinate> orthodiagonalNeighbours() {
// TODO: à compléter
return List.of();
List<Coordinate> eightNeighbours= new ArrayList<>();
eightNeighbours.addAll(this.orthogonalNeighbours());
eightNeighbours.addAll(this.diagonalNeighbours());
return eightNeighbours;
}
@Override
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment