From e56a6023f74b5e9765fa865bdf6fb13a792d193c Mon Sep 17 00:00:00 2001 From: Kamil Rudny <134285490+krudny@users.noreply.github.com> Date: Tue, 7 Nov 2023 21:52:12 +0100 Subject: [PATCH 01/11] Created animal class --- oolab/src/main/java/agh/ics/oop/model/Animal.java | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 oolab/src/main/java/agh/ics/oop/model/Animal.java diff --git a/oolab/src/main/java/agh/ics/oop/model/Animal.java b/oolab/src/main/java/agh/ics/oop/model/Animal.java new file mode 100644 index 0000000..0060334 --- /dev/null +++ b/oolab/src/main/java/agh/ics/oop/model/Animal.java @@ -0,0 +1,5 @@ +package agh.ics.oop.model; + +public class Animal { + +} From 9359584ec2bd36ac479b24e5e6b716a0e346cab0 Mon Sep 17 00:00:00 2001 From: Kamil Rudny <134285490+krudny@users.noreply.github.com> Date: Tue, 7 Nov 2023 22:56:14 +0100 Subject: [PATCH 02/11] Finished animal class --- .../main/java/agh/ics/oop/OptionsParser.java | 2 +- oolab/src/main/java/agh/ics/oop/World.java | 14 ++++-- .../main/java/agh/ics/oop/model/Animal.java | 50 ++++++++++++++++++- .../java/agh/ics/oop/model/MoveDirection.java | 2 +- .../main/java/agh/ics/oop/model/Vector2d.java | 3 -- 5 files changed, 62 insertions(+), 9 deletions(-) diff --git a/oolab/src/main/java/agh/ics/oop/OptionsParser.java b/oolab/src/main/java/agh/ics/oop/OptionsParser.java index 027c488..0311a28 100644 --- a/oolab/src/main/java/agh/ics/oop/OptionsParser.java +++ b/oolab/src/main/java/agh/ics/oop/OptionsParser.java @@ -11,7 +11,7 @@ public static MoveDirection[] Parser(String[] args) { if (Objects.equals(args[i], "f")) { moveDirection[i] = MoveDirection.FORWARD; } else if (Objects.equals(args[i], "b")) { - moveDirection[i] = MoveDirection.BACKWARDS; + moveDirection[i] = MoveDirection.BACKWARD; } else if (Objects.equals(args[i], "l")) { moveDirection[i] = MoveDirection.LEFT; } else if (Objects.equals(args[i], "r")) { diff --git a/oolab/src/main/java/agh/ics/oop/World.java b/oolab/src/main/java/agh/ics/oop/World.java index 95a8f9a..4af16e0 100644 --- a/oolab/src/main/java/agh/ics/oop/World.java +++ b/oolab/src/main/java/agh/ics/oop/World.java @@ -1,5 +1,6 @@ package agh.ics.oop; +import agh.ics.oop.model.Animal; import agh.ics.oop.model.MapDirection; import agh.ics.oop.model.MoveDirection; import agh.ics.oop.model.Vector2d; @@ -14,7 +15,7 @@ public static void run(MoveDirection[] directions) { case FORWARD: System.out.println("Zwierzak idzie prosto"); break; - case BACKWARDS: + case BACKWARD: System.out.println("Zwierzak idzie do tyłu"); break; case LEFT: @@ -37,11 +38,18 @@ public static void main(String[] args) { System.out.println(position2); System.out.println(position1.add(position2));*/ - MapDirection direction = MapDirection.EAST; + /*MapDirection direction = MapDirection.EAST; System.out.println("Aktualny kierunek: " + direction); System.out.println("Następny kierunek: " + direction.next()); System.out.println("Poprzedni kierunek: " + direction.previous()); - System.out.println("Jednostkowy wektor: " + direction.toUnitVector()); + System.out.println("Jednostkowy wektor: " + direction.toUnitVector());*/ + + Animal animal1 = new Animal(); + Animal animal2 = new Animal(3,4); + System.out.println(animal1.toString()); + animal1.move(MoveDirection.BACKWARD); + System.out.println(animal1.toString()); + } diff --git a/oolab/src/main/java/agh/ics/oop/model/Animal.java b/oolab/src/main/java/agh/ics/oop/model/Animal.java index 0060334..ad90227 100644 --- a/oolab/src/main/java/agh/ics/oop/model/Animal.java +++ b/oolab/src/main/java/agh/ics/oop/model/Animal.java @@ -1,5 +1,53 @@ package agh.ics.oop.model; public class Animal { - + private MapDirection direction; + private Vector2d position; + public Animal() { + this.direction = MapDirection.NORTH; + this.position = new Vector2d(2,2); + } + public Animal(int x, int y){ + this.direction = MapDirection.NORTH; + this.position = new Vector2d(x, y); + } + public MapDirection getDirection() { + return this.direction; + } + public Vector2d getPosition() { + return this.position; + } + @Override + public String toString() { + return "Position: " + position.toString() + " Orientation: " + direction.toString(); + } + public boolean isAt(Vector2d position) { + return position.equals(this.position); + } + public void move(MoveDirection direction) { + Vector2d MAP_RIGHT_TOP = new Vector2d(4,4); + Vector2d MAP_LEFT_BOTTOM = new Vector2d(0,0); + + switch(direction) { + case RIGHT: + this.direction = this.direction.next(); + break; + case LEFT: + this.direction = this.direction.previous(); + break; + case FORWARD: + Vector2d newPosition1 = this.position.add(this.direction.toUnitVector()); + if (newPosition1.precedes(MAP_RIGHT_TOP) && newPosition1.follows(MAP_LEFT_BOTTOM)) { + this.position = newPosition1; + } + break; + case BACKWARD: + Vector2d newPosition2 = this.position.subtract(this.direction.toUnitVector()); + if (newPosition2.precedes(MAP_RIGHT_TOP) && newPosition2.follows(MAP_LEFT_BOTTOM)) { + this.position = newPosition2; + } + break; + + } + } } diff --git a/oolab/src/main/java/agh/ics/oop/model/MoveDirection.java b/oolab/src/main/java/agh/ics/oop/model/MoveDirection.java index 7c32ccc..9a7aaa7 100644 --- a/oolab/src/main/java/agh/ics/oop/model/MoveDirection.java +++ b/oolab/src/main/java/agh/ics/oop/model/MoveDirection.java @@ -1,5 +1,5 @@ package agh.ics.oop.model; public enum MoveDirection { - FORWARD, BACKWARDS, LEFT, RIGHT; + FORWARD, BACKWARD, LEFT, RIGHT; } diff --git a/oolab/src/main/java/agh/ics/oop/model/Vector2d.java b/oolab/src/main/java/agh/ics/oop/model/Vector2d.java index 1e880e9..fd80a10 100644 --- a/oolab/src/main/java/agh/ics/oop/model/Vector2d.java +++ b/oolab/src/main/java/agh/ics/oop/model/Vector2d.java @@ -84,7 +84,4 @@ public int hashCode() { return Objects.hash(x, y); } - - - } From 4d549402db6027a5d2ea028d6c25aa1f60d4ef9d Mon Sep 17 00:00:00 2001 From: Kamil Rudny <134285490+krudny@users.noreply.github.com> Date: Wed, 8 Nov 2023 18:02:09 +0100 Subject: [PATCH 03/11] Finished lists --- .../main/java/agh/ics/oop/OptionsParser.java | 15 +++++---- oolab/src/main/java/agh/ics/oop/World.java | 11 ++++--- .../main/java/agh/ics/oop/model/Animal.java | 2 +- .../agh/ics/oop/model/OptionsParserTest.java | 32 ++++++++++++++----- 4 files changed, 40 insertions(+), 20 deletions(-) diff --git a/oolab/src/main/java/agh/ics/oop/OptionsParser.java b/oolab/src/main/java/agh/ics/oop/OptionsParser.java index 0311a28..b4e6d4e 100644 --- a/oolab/src/main/java/agh/ics/oop/OptionsParser.java +++ b/oolab/src/main/java/agh/ics/oop/OptionsParser.java @@ -1,23 +1,26 @@ package agh.ics.oop; import agh.ics.oop.model.MoveDirection; +import java.util.ArrayList; +import java.util.List; import java.util.Objects; public class OptionsParser { - public static MoveDirection[] Parser(String[] args) { + public static List Parser(String[] args) { MoveDirection[] moveDirection = new MoveDirection[args.length]; + List MoveDirectionList = new ArrayList<>(); for(int i = 0; i < args.length; i++){ if (Objects.equals(args[i], "f")) { - moveDirection[i] = MoveDirection.FORWARD; + MoveDirectionList.add(MoveDirection.FORWARD); } else if (Objects.equals(args[i], "b")) { - moveDirection[i] = MoveDirection.BACKWARD; + MoveDirectionList.add(MoveDirection.BACKWARD); } else if (Objects.equals(args[i], "l")) { - moveDirection[i] = MoveDirection.LEFT; + MoveDirectionList.add(MoveDirection.LEFT); } else if (Objects.equals(args[i], "r")) { - moveDirection[i] = MoveDirection.RIGHT; + MoveDirectionList.add(MoveDirection.RIGHT); } } - return moveDirection; + return MoveDirectionList; } } diff --git a/oolab/src/main/java/agh/ics/oop/World.java b/oolab/src/main/java/agh/ics/oop/World.java index 4af16e0..f46ba87 100644 --- a/oolab/src/main/java/agh/ics/oop/World.java +++ b/oolab/src/main/java/agh/ics/oop/World.java @@ -5,11 +5,12 @@ import agh.ics.oop.model.MoveDirection; import agh.ics.oop.model.Vector2d; +import java.util.List; import java.util.Objects; public class World { - public static void run(MoveDirection[] directions) { + public static void run(List directions) { for (MoveDirection direction : directions) { switch (direction) { case FORWARD: @@ -30,9 +31,9 @@ public static void run(MoveDirection[] directions) { public static void main(String[] args) { /*System.out.println("System zaczął działanie"); run(OptionsParser.Parser(args)); - System.out.println("System skończył działanie"); + System.out.println("System skończył działanie");*/ - Vector2d position1 = new Vector2d(1,2); + /*Vector2d position1 = new Vector2d(1,2); System.out.println(position1); Vector2d position2 = new Vector2d(-2,1); System.out.println(position2); @@ -44,11 +45,11 @@ public static void main(String[] args) { System.out.println("Poprzedni kierunek: " + direction.previous()); System.out.println("Jednostkowy wektor: " + direction.toUnitVector());*/ - Animal animal1 = new Animal(); + /*Animal animal1 = new Animal(); Animal animal2 = new Animal(3,4); System.out.println(animal1.toString()); animal1.move(MoveDirection.BACKWARD); - System.out.println(animal1.toString()); + System.out.println(animal1.toString());*/ diff --git a/oolab/src/main/java/agh/ics/oop/model/Animal.java b/oolab/src/main/java/agh/ics/oop/model/Animal.java index ad90227..1daf2c5 100644 --- a/oolab/src/main/java/agh/ics/oop/model/Animal.java +++ b/oolab/src/main/java/agh/ics/oop/model/Animal.java @@ -47,7 +47,7 @@ public void move(MoveDirection direction) { this.position = newPosition2; } break; - } } + } diff --git a/oolab/src/test/java/agh/ics/oop/model/OptionsParserTest.java b/oolab/src/test/java/agh/ics/oop/model/OptionsParserTest.java index 7506c54..888ea32 100644 --- a/oolab/src/test/java/agh/ics/oop/model/OptionsParserTest.java +++ b/oolab/src/test/java/agh/ics/oop/model/OptionsParserTest.java @@ -1,20 +1,36 @@ package agh.ics.oop.model; import agh.ics.oop.OptionsParser; +import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.Test; + +import java.util.ArrayList; +import java.util.List; + import static org.junit.jupiter.api.Assertions.assertArrayEquals; public class OptionsParserTest { @Test public void testParseValidDirections() { - String[] args = {"f", "b", "l", "r"}; - MoveDirection[] result = OptionsParser.Parser(args); - - assertArrayEquals(new MoveDirection[]{MoveDirection.FORWARD, MoveDirection.BACKWARDS, MoveDirection.LEFT, MoveDirection.RIGHT}, result); - - String[] args1 = {"f", "r", "k", "r"}; - MoveDirection[] result1 = OptionsParser.Parser(args1); + String[] args1 = {"f", "b", "l", "r"}; + List result1 = OptionsParser.Parser(args1); + List correct1 = new ArrayList<>() {{ + add(MoveDirection.FORWARD); + add(MoveDirection.BACKWARD); + add(MoveDirection.LEFT); + add(MoveDirection.RIGHT); + }}; + Assertions.assertEquals(result1, correct1); - assertArrayEquals(new MoveDirection[]{MoveDirection.FORWARD, MoveDirection.RIGHT, null, MoveDirection.RIGHT}, result1); + String[] args2 = {"b", "k", "r", "l", "f", "b"}; + List result2 = OptionsParser.Parser(args2); + List correct2 = new ArrayList<>() {{ + add(MoveDirection.BACKWARD); + add(MoveDirection.RIGHT); + add(MoveDirection.LEFT); + add(MoveDirection.FORWARD); + add(MoveDirection.BACKWARD); + }}; + Assertions.assertEquals(result2, correct2); } } From faa4003fa35aae94f78d4f781d303a4c75895a1f Mon Sep 17 00:00:00 2001 From: Kamil Rudny <134285490+krudny@users.noreply.github.com> Date: Thu, 9 Nov 2023 00:18:16 +0100 Subject: [PATCH 04/11] Finished simulation --- .../src/main/java/agh/ics/oop/Simulation.java | 38 +++++++++++++++++++ oolab/src/main/java/agh/ics/oop/World.java | 28 +++----------- .../main/java/agh/ics/oop/model/Animal.java | 2 +- .../agh/ics/oop/model/OptionsParserTest.java | 2 + 4 files changed, 46 insertions(+), 24 deletions(-) create mode 100644 oolab/src/main/java/agh/ics/oop/Simulation.java diff --git a/oolab/src/main/java/agh/ics/oop/Simulation.java b/oolab/src/main/java/agh/ics/oop/Simulation.java new file mode 100644 index 0000000..d13441b --- /dev/null +++ b/oolab/src/main/java/agh/ics/oop/Simulation.java @@ -0,0 +1,38 @@ +package agh.ics.oop; + +import agh.ics.oop.model.Animal; +import agh.ics.oop.model.MoveDirection; +import agh.ics.oop.model.Vector2d; + +import java.util.ArrayList; +import java.util.List; + +public class Simulation { + List Animals = new ArrayList<>(); + List Directions = new ArrayList<>(); + public Simulation(List positions, List directions) { + for(Vector2d position : positions) { + Animal new_animal = new Animal(position.getX(), position.getY()); + Animals.add(new_animal); + } + + this.Directions = directions; + } + + public void run() { + int animal_count = Animals.size(); + int cnt = 0; + + for(MoveDirection move : Directions) { + Animal current_animal = Animals.get(0); + Animals.remove(0); + current_animal.move(move); + System.out.println("Zwierze " + ((cnt % animal_count) + 1) + " " + current_animal.toString()); + cnt += 1; + Animals.add(current_animal); + } + } + + + +} diff --git a/oolab/src/main/java/agh/ics/oop/World.java b/oolab/src/main/java/agh/ics/oop/World.java index f46ba87..6ee6905 100644 --- a/oolab/src/main/java/agh/ics/oop/World.java +++ b/oolab/src/main/java/agh/ics/oop/World.java @@ -5,6 +5,7 @@ import agh.ics.oop.model.MoveDirection; import agh.ics.oop.model.Vector2d; +import java.util.ArrayList; import java.util.List; import java.util.Objects; @@ -29,29 +30,10 @@ public static void run(List directions) { } } public static void main(String[] args) { - /*System.out.println("System zaczął działanie"); - run(OptionsParser.Parser(args)); - System.out.println("System skończył działanie");*/ - - /*Vector2d position1 = new Vector2d(1,2); - System.out.println(position1); - Vector2d position2 = new Vector2d(-2,1); - System.out.println(position2); - System.out.println(position1.add(position2));*/ - - /*MapDirection direction = MapDirection.EAST; - System.out.println("Aktualny kierunek: " + direction); - System.out.println("Następny kierunek: " + direction.next()); - System.out.println("Poprzedni kierunek: " + direction.previous()); - System.out.println("Jednostkowy wektor: " + direction.toUnitVector());*/ - - /*Animal animal1 = new Animal(); - Animal animal2 = new Animal(3,4); - System.out.println(animal1.toString()); - animal1.move(MoveDirection.BACKWARD); - System.out.println(animal1.toString());*/ - - + List directions = OptionsParser.Parser(args); + List positions = List.of(new Vector2d(2,2), new Vector2d(3,4)); + Simulation simulation = new Simulation(positions, directions); + simulation.run(); } } diff --git a/oolab/src/main/java/agh/ics/oop/model/Animal.java b/oolab/src/main/java/agh/ics/oop/model/Animal.java index 1daf2c5..8c3cb42 100644 --- a/oolab/src/main/java/agh/ics/oop/model/Animal.java +++ b/oolab/src/main/java/agh/ics/oop/model/Animal.java @@ -19,7 +19,7 @@ public Vector2d getPosition() { } @Override public String toString() { - return "Position: " + position.toString() + " Orientation: " + direction.toString(); + return "Pozycja: " + position.toString() + " Orientacja: " + direction.toString(); } public boolean isAt(Vector2d position) { return position.equals(this.position); diff --git a/oolab/src/test/java/agh/ics/oop/model/OptionsParserTest.java b/oolab/src/test/java/agh/ics/oop/model/OptionsParserTest.java index 888ea32..2a27580 100644 --- a/oolab/src/test/java/agh/ics/oop/model/OptionsParserTest.java +++ b/oolab/src/test/java/agh/ics/oop/model/OptionsParserTest.java @@ -20,6 +20,7 @@ public void testParseValidDirections() { add(MoveDirection.LEFT); add(MoveDirection.RIGHT); }}; + Assertions.assertEquals(result1, correct1); String[] args2 = {"b", "k", "r", "l", "f", "b"}; @@ -31,6 +32,7 @@ public void testParseValidDirections() { add(MoveDirection.FORWARD); add(MoveDirection.BACKWARD); }}; + Assertions.assertEquals(result2, correct2); } } From 7734269659d1d9fd99f0342c7d186fa89bfa326a Mon Sep 17 00:00:00 2001 From: Kamil Rudny <134285490+krudny@users.noreply.github.com> Date: Sat, 11 Nov 2023 15:10:36 +0100 Subject: [PATCH 05/11] bugfix --- oolab/src/test/java/agh/ics/oop/model/AnimalTest.java | 2 ++ oolab/src/test/java/agh/ics/oop/model/IntegrationMoveTest.java | 2 ++ 2 files changed, 4 insertions(+) create mode 100644 oolab/src/test/java/agh/ics/oop/model/AnimalTest.java create mode 100644 oolab/src/test/java/agh/ics/oop/model/IntegrationMoveTest.java diff --git a/oolab/src/test/java/agh/ics/oop/model/AnimalTest.java b/oolab/src/test/java/agh/ics/oop/model/AnimalTest.java new file mode 100644 index 0000000..9a221f6 --- /dev/null +++ b/oolab/src/test/java/agh/ics/oop/model/AnimalTest.java @@ -0,0 +1,2 @@ +package agh.ics.oop.model;public class AnimalTest { +} diff --git a/oolab/src/test/java/agh/ics/oop/model/IntegrationMoveTest.java b/oolab/src/test/java/agh/ics/oop/model/IntegrationMoveTest.java new file mode 100644 index 0000000..4b2f84e --- /dev/null +++ b/oolab/src/test/java/agh/ics/oop/model/IntegrationMoveTest.java @@ -0,0 +1,2 @@ +package agh.ics.oop.model;public class IntegrationMoveTest { +} From 691f78631674170dcb5ba79631f25beef96596f3 Mon Sep 17 00:00:00 2001 From: Kamil Rudny <134285490+krudny@users.noreply.github.com> Date: Sat, 11 Nov 2023 15:11:07 +0100 Subject: [PATCH 06/11] bugfix --- .../src/main/java/agh/ics/oop/Simulation.java | 9 ++- oolab/src/main/java/agh/ics/oop/World.java | 8 +- .../java/agh/ics/oop/model/AnimalTest.java | 53 ++++++++++++- .../ics/oop/model/IntegrationMoveTest.java | 78 ++++++++++++++++++- 4 files changed, 141 insertions(+), 7 deletions(-) diff --git a/oolab/src/main/java/agh/ics/oop/Simulation.java b/oolab/src/main/java/agh/ics/oop/Simulation.java index d13441b..3650b15 100644 --- a/oolab/src/main/java/agh/ics/oop/Simulation.java +++ b/oolab/src/main/java/agh/ics/oop/Simulation.java @@ -23,16 +23,17 @@ public void run() { int animal_count = Animals.size(); int cnt = 0; - for(MoveDirection move : Directions) { + for(MoveDirection currentMove : Directions) { Animal current_animal = Animals.get(0); Animals.remove(0); - current_animal.move(move); + current_animal.move(currentMove); System.out.println("Zwierze " + ((cnt % animal_count) + 1) + " " + current_animal.toString()); cnt += 1; Animals.add(current_animal); } } - - + public List getAnimals() { + return Animals; + } } diff --git a/oolab/src/main/java/agh/ics/oop/World.java b/oolab/src/main/java/agh/ics/oop/World.java index 6ee6905..5955e5f 100644 --- a/oolab/src/main/java/agh/ics/oop/World.java +++ b/oolab/src/main/java/agh/ics/oop/World.java @@ -31,9 +31,15 @@ public static void run(List directions) { } public static void main(String[] args) { List directions = OptionsParser.Parser(args); - List positions = List.of(new Vector2d(2,2), new Vector2d(3,4)); + List positions = List.of(new Vector2d(2,2)); Simulation simulation = new Simulation(positions, directions); simulation.run(); + List finalAnimals = simulation.getAnimals(); + + for (Animal animal : finalAnimals) { + System.out.println(animal.getPosition()); + } + } } diff --git a/oolab/src/test/java/agh/ics/oop/model/AnimalTest.java b/oolab/src/test/java/agh/ics/oop/model/AnimalTest.java index 9a221f6..9a2dce8 100644 --- a/oolab/src/test/java/agh/ics/oop/model/AnimalTest.java +++ b/oolab/src/test/java/agh/ics/oop/model/AnimalTest.java @@ -1,2 +1,53 @@ -package agh.ics.oop.model;public class AnimalTest { +package agh.ics.oop.model; + +import org.junit.jupiter.api.Test; + +import static org.junit.jupiter.api.Assertions.*; + +public class AnimalTest { + @Test + public void getDirectionTest(){ + Animal animal1 = new Animal(); + Animal animal2 = new Animal(2,2); + assertEquals(animal1.getDirection(), MapDirection.NORTH); + assertEquals(animal2.getDirection(), MapDirection.NORTH); + } + + @Test + public void getPositionTest(){ + Animal animal1 = new Animal(); + Animal animal2 = new Animal(2,2); + Animal animal3 = new Animal(1,3); + + assertEquals(animal1.getPosition(), new Vector2d(2,2)); + assertEquals(animal2.getPosition(), new Vector2d(2,2)); + assertEquals(animal3.getPosition(), new Vector2d(1,3)); + } + + @Test + public void toStringTest(){ + Animal animal1 = new Animal(); + Animal animal2 = new Animal(2,2); + Animal animal3 = new Animal(1,3); + + assertEquals(animal1.toString(), "Pozycja: (2,2) Orientacja: Północ"); + assertEquals(animal2.toString(), "Pozycja: (2,2) Orientacja: Północ"); + assertEquals(animal3.toString(), "Pozycja: (1,3) Orientacja: Północ"); + } + + @Test + public void isAt(){ + Animal animal1 = new Animal(); + Animal animal2 = new Animal(2,2); + Animal animal3 = new Animal(1,3); + + assertTrue(animal1.isAt(new Vector2d(2,2))); + assertTrue(animal2.isAt(new Vector2d(2,2))); + assertTrue(animal3.isAt(new Vector2d(1,3))); + assertFalse(animal1.isAt(new Vector2d(1,2))); + assertFalse(animal2.isAt(new Vector2d(1,2))); + assertFalse(animal3.isAt(new Vector2d(2,3))); + } + + } diff --git a/oolab/src/test/java/agh/ics/oop/model/IntegrationMoveTest.java b/oolab/src/test/java/agh/ics/oop/model/IntegrationMoveTest.java index 4b2f84e..ade708c 100644 --- a/oolab/src/test/java/agh/ics/oop/model/IntegrationMoveTest.java +++ b/oolab/src/test/java/agh/ics/oop/model/IntegrationMoveTest.java @@ -1,2 +1,78 @@ -package agh.ics.oop.model;public class IntegrationMoveTest { +package agh.ics.oop.model; + +import agh.ics.oop.OptionsParser; + +import agh.ics.oop.Simulation; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Test; + +import java.util.ArrayList; +import java.util.List; + +import static org.junit.jupiter.api.Assertions.assertEquals; + +public class IntegrationMoveTest { + @Test + public void testValidMoves() { + String[] args = {"f", "b", "l", "r", "r", "f", "l", "b"}; + List directions = OptionsParser.Parser(args); + List positions = List.of(new Vector2d(2,2), new Vector2d(3,4)); + Simulation simulation = new Simulation(positions, directions); + simulation.run(); + + List finalAnimals = simulation.getAnimals(); + List actualPositions = new ArrayList<>(); + + for (Animal animal : finalAnimals) { + actualPositions.add(animal.getPosition()); + } + List correctPositions = new ArrayList<>() {{ + add(new Vector2d(2,3)); + add(new Vector2d(2,3)); + }}; + + assertEquals(correctPositions, actualPositions); + } + @Test + public void testInvalidMoves() { + String[] args = {"f", "w", "h", "b"}; + List directions = OptionsParser.Parser(args); + List positions = List.of(new Vector2d(2,2), new Vector2d(3,4)); + Simulation simulation = new Simulation(positions, directions); + simulation.run(); + + List finalAnimals = simulation.getAnimals(); + List actualPositions = new ArrayList<>(); + + for (Animal animal : finalAnimals) { + actualPositions.add(animal.getPosition()); + } + List correctPositions = new ArrayList<>() {{ + add(new Vector2d(2,3)); + add(new Vector2d(3,3)); + }}; + + assertEquals(correctPositions, actualPositions); + } + @Test + public void testOutOfBorderMoves() { + String[] args = {"f", "f", "f", "f", "f", "f", "f", "f", "f", "f", "f", "f"}; + List directions = OptionsParser.Parser(args); + List positions = List.of(new Vector2d(2,2), new Vector2d(3,4)); + Simulation simulation = new Simulation(positions, directions); + simulation.run(); + + List finalAnimals = simulation.getAnimals(); + List actualPositions = new ArrayList<>(); + + for (Animal animal : finalAnimals) { + actualPositions.add(animal.getPosition()); + } + List correctPositions = new ArrayList<>() {{ + add(new Vector2d(4,3)); + add(new Vector2d(3,4)); + }}; + + assertEquals(correctPositions, actualPositions); + } } From 54c4a8b704ed92b118e7ce5adf9a81f45e470661 Mon Sep 17 00:00:00 2001 From: Kamil Rudny <134285490+krudny@users.noreply.github.com> Date: Sat, 11 Nov 2023 15:26:19 +0100 Subject: [PATCH 07/11] Updated readme and gitignore --- .gitignore | 6 +++++- README.md | 4 +++- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/.gitignore b/.gitignore index d16bbbe..7f55b2c 100644 --- a/.gitignore +++ b/.gitignore @@ -74,4 +74,8 @@ fabric.properties .idea/httpRequests # Android studio 3.1+ serialized cache file -.idea/caches/build_file_checksums.ser \ No newline at end of file +.idea/caches/build_file_checksums.ser + +oolab/.idea +oolab/gradlew +oolab/gradlew.bat \ No newline at end of file diff --git a/README.md b/README.md index 586c886..f84bf95 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,6 @@ Kamil Rudny Piątek 11:20 Gerard -https://gitexercises.fracz.com/committer/4a757cf05e8a3f76ed8599ee38a79085391ed03d?email=karudny@student.agh.edu.pl \ No newline at end of file +https://gitexercises.fracz.com/committer/4a757cf05e8a3f76ed8599ee38a79085391ed03d?email=karudny@student.agh.edu.pl + +Za zadania z gita z srebrnej skrzynki chce marchewkę lab, a z brązowej weterynarza. \ No newline at end of file From 72095d60aa15ad0f6a875256a8f106608f149dd8 Mon Sep 17 00:00:00 2001 From: Kamil Rudny <134285490+krudny@users.noreply.github.com> Date: Sat, 11 Nov 2023 15:32:03 +0100 Subject: [PATCH 08/11] Updated .gitignore --- .gitignore | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/.gitignore b/.gitignore index 7f55b2c..d0a674d 100644 --- a/.gitignore +++ b/.gitignore @@ -76,6 +76,6 @@ fabric.properties # Android studio 3.1+ serialized cache file .idea/caches/build_file_checksums.ser -oolab/.idea -oolab/gradlew -oolab/gradlew.bat \ No newline at end of file +.idea +gradlew +gradlew.bat \ No newline at end of file From 1eb7632e408b59adcc42aa51a4f4f7a5b711c78a Mon Sep 17 00:00:00 2001 From: Kamil Rudny <134285490+krudny@users.noreply.github.com> Date: Sat, 11 Nov 2023 15:56:14 +0100 Subject: [PATCH 09/11] Updated git ignore --- .gitignore | 3 - oolab/.gitignore | 6 +- oolab/.idea/.gitignore | 8 --- oolab/.idea/gradle.xml | 3 +- oolab/.idea/misc.xml | 4 +- oolab/.idea/uiDesigner.xml | 124 ------------------------------------- 6 files changed, 7 insertions(+), 141 deletions(-) delete mode 100644 oolab/.idea/.gitignore delete mode 100644 oolab/.idea/uiDesigner.xml diff --git a/.gitignore b/.gitignore index d0a674d..8f4e780 100644 --- a/.gitignore +++ b/.gitignore @@ -76,6 +76,3 @@ fabric.properties # Android studio 3.1+ serialized cache file .idea/caches/build_file_checksums.ser -.idea -gradlew -gradlew.bat \ No newline at end of file diff --git a/oolab/.gitignore b/oolab/.gitignore index b63da45..992973c 100644 --- a/oolab/.gitignore +++ b/oolab/.gitignore @@ -39,4 +39,8 @@ bin/ .vscode/ ### Mac OS ### -.DS_Store \ No newline at end of file +.DS_Store + +/.idea/ +gradlew.bat +gradlew \ No newline at end of file diff --git a/oolab/.idea/.gitignore b/oolab/.idea/.gitignore deleted file mode 100644 index 13566b8..0000000 --- a/oolab/.idea/.gitignore +++ /dev/null @@ -1,8 +0,0 @@ -# Default ignored files -/shelf/ -/workspace.xml -# Editor-based HTTP Client requests -/httpRequests/ -# Datasource local storage ignored files -/dataSources/ -/dataSources.local.xml diff --git a/oolab/.idea/gradle.xml b/oolab/.idea/gradle.xml index 2a65317..39ec4f5 100644 --- a/oolab/.idea/gradle.xml +++ b/oolab/.idea/gradle.xml @@ -1,11 +1,10 @@ - \ No newline at end of file diff --git a/oolab/.idea/uiDesigner.xml b/oolab/.idea/uiDesigner.xml deleted file mode 100644 index 2b63946..0000000 --- a/oolab/.idea/uiDesigner.xml +++ /dev/null @@ -1,124 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - \ No newline at end of file From c43dfe86ff0a6a49f34be6bd13ccbdb5218ecb2d Mon Sep 17 00:00:00 2001 From: Kamil Rudny <134285490+krudny@users.noreply.github.com> Date: Sat, 11 Nov 2023 16:45:00 +0100 Subject: [PATCH 10/11] Finished integration tests --- oolab/.idea/gradle.xml | 16 -- oolab/.idea/misc.xml | 8 - oolab/.idea/vcs.xml | 6 - oolab/gradlew | 234 ------------------ oolab/gradlew.bat | 89 ------- .../src/main/java/agh/ics/oop/Simulation.java | 9 +- oolab/src/main/java/agh/ics/oop/World.java | 8 +- .../main/java/agh/ics/oop/model/Animal.java | 2 +- .../java/agh/ics/oop/model/MapDirection.java | 8 +- .../ics/oop/model/IntegrationMoveTest.java | 87 ++++++- 10 files changed, 95 insertions(+), 372 deletions(-) delete mode 100644 oolab/.idea/gradle.xml delete mode 100644 oolab/.idea/misc.xml delete mode 100644 oolab/.idea/vcs.xml delete mode 100644 oolab/gradlew delete mode 100644 oolab/gradlew.bat diff --git a/oolab/.idea/gradle.xml b/oolab/.idea/gradle.xml deleted file mode 100644 index 39ec4f5..0000000 --- a/oolab/.idea/gradle.xml +++ /dev/null @@ -1,16 +0,0 @@ - - - - - - \ No newline at end of file diff --git a/oolab/.idea/misc.xml b/oolab/.idea/misc.xml deleted file mode 100644 index 31f2c8b..0000000 --- a/oolab/.idea/misc.xml +++ /dev/null @@ -1,8 +0,0 @@ - - - - - - - - \ No newline at end of file diff --git a/oolab/.idea/vcs.xml b/oolab/.idea/vcs.xml deleted file mode 100644 index 6c0b863..0000000 --- a/oolab/.idea/vcs.xml +++ /dev/null @@ -1,6 +0,0 @@ - - - - - - \ No newline at end of file diff --git a/oolab/gradlew b/oolab/gradlew deleted file mode 100644 index 1b6c787..0000000 --- a/oolab/gradlew +++ /dev/null @@ -1,234 +0,0 @@ -#!/bin/sh - -# -# Copyright © 2015-2021 the original authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# https://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -# - -############################################################################## -# -# Gradle start up script for POSIX generated by Gradle. -# -# Important for running: -# -# (1) You need a POSIX-compliant shell to run this script. If your /bin/sh is -# noncompliant, but you have some other compliant shell such as ksh or -# bash, then to run this script, type that shell name before the whole -# command line, like: -# -# ksh Gradle -# -# Busybox and similar reduced shells will NOT work, because this script -# requires all of these POSIX shell features: -# * functions; -# * expansions «$var», «${var}», «${var:-default}», «${var+SET}», -# «${var#prefix}», «${var%suffix}», and «$( cmd )»; -# * compound commands having a testable exit status, especially «case»; -# * various built-in commands including «command», «set», and «ulimit». -# -# Important for patching: -# -# (2) This script targets any POSIX shell, so it avoids extensions provided -# by Bash, Ksh, etc; in particular arrays are avoided. -# -# The "traditional" practice of packing multiple parameters into a -# space-separated string is a well documented source of bugs and security -# problems, so this is (mostly) avoided, by progressively accumulating -# options in "$@", and eventually passing that to Java. -# -# Where the inherited environment variables (DEFAULT_JVM_OPTS, JAVA_OPTS, -# and GRADLE_OPTS) rely on word-splitting, this is performed explicitly; -# see the in-line comments for details. -# -# There are tweaks for specific operating systems such as AIX, CygWin, -# Darwin, MinGW, and NonStop. -# -# (3) This script is generated from the Groovy template -# https://github.com/gradle/gradle/blob/master/subprojects/plugins/src/main/resources/org/gradle/api/internal/plugins/unixStartScript.txt -# within the Gradle project. -# -# You can find Gradle at https://github.com/gradle/gradle/. -# -############################################################################## - -# Attempt to set APP_HOME - -# Resolve links: $0 may be a link -app_path=$0 - -# Need this for daisy-chained symlinks. -while - APP_HOME=${app_path%"${app_path##*/}"} # leaves a trailing /; empty if no leading path - [ -h "$app_path" ] -do - ls=$( ls -ld "$app_path" ) - link=${ls#*' -> '} - case $link in #( - /*) app_path=$link ;; #( - *) app_path=$APP_HOME$link ;; - esac -done - -APP_HOME=$( cd "${APP_HOME:-./}" && pwd -P ) || exit - -APP_NAME="Gradle" -APP_BASE_NAME=${0##*/} - -# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. -DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"' - -# Use the maximum available, or set MAX_FD != -1 to use that value. -MAX_FD=maximum - -warn () { - echo "$*" -} >&2 - -die () { - echo - echo "$*" - echo - exit 1 -} >&2 - -# OS specific support (must be 'true' or 'false'). -cygwin=false -msys=false -darwin=false -nonstop=false -case "$( uname )" in #( - CYGWIN* ) cygwin=true ;; #( - Darwin* ) darwin=true ;; #( - MSYS* | MINGW* ) msys=true ;; #( - NONSTOP* ) nonstop=true ;; -esac - -CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar - - -# Determine the Java command to use to start the JVM. -if [ -n "$JAVA_HOME" ] ; then - if [ -x "$JAVA_HOME/jre/sh/java" ] ; then - # IBM's JDK on AIX uses strange locations for the executables - JAVACMD=$JAVA_HOME/jre/sh/java - else - JAVACMD=$JAVA_HOME/bin/java - fi - if [ ! -x "$JAVACMD" ] ; then - die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME - -Please set the JAVA_HOME variable in your environment to match the -location of your Java installation." - fi -else - JAVACMD=java - which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. - -Please set the JAVA_HOME variable in your environment to match the -location of your Java installation." -fi - -# Increase the maximum file descriptors if we can. -if ! "$cygwin" && ! "$darwin" && ! "$nonstop" ; then - case $MAX_FD in #( - max*) - MAX_FD=$( ulimit -H -n ) || - warn "Could not query maximum file descriptor limit" - esac - case $MAX_FD in #( - '' | soft) :;; #( - *) - ulimit -n "$MAX_FD" || - warn "Could not set maximum file descriptor limit to $MAX_FD" - esac -fi - -# Collect all arguments for the java command, stacking in reverse order: -# * args from the command line -# * the main class name -# * -classpath -# * -D...appname settings -# * --module-path (only if needed) -# * DEFAULT_JVM_OPTS, JAVA_OPTS, and GRADLE_OPTS environment variables. - -# For Cygwin or MSYS, switch paths to Windows format before running java -if "$cygwin" || "$msys" ; then - APP_HOME=$( cygpath --path --mixed "$APP_HOME" ) - CLASSPATH=$( cygpath --path --mixed "$CLASSPATH" ) - - JAVACMD=$( cygpath --unix "$JAVACMD" ) - - # Now convert the arguments - kludge to limit ourselves to /bin/sh - for arg do - if - case $arg in #( - -*) false ;; # don't mess with options #( - /?*) t=${arg#/} t=/${t%%/*} # looks like a POSIX filepath - [ -e "$t" ] ;; #( - *) false ;; - esac - then - arg=$( cygpath --path --ignore --mixed "$arg" ) - fi - # Roll the args list around exactly as many times as the number of - # args, so each arg winds up back in the position where it started, but - # possibly modified. - # - # NB: a `for` loop captures its iteration list before it begins, so - # changing the positional parameters here affects neither the number of - # iterations, nor the values presented in `arg`. - shift # remove old arg - set -- "$@" "$arg" # push replacement arg - done -fi - -# Collect all arguments for the java command; -# * $DEFAULT_JVM_OPTS, $JAVA_OPTS, and $GRADLE_OPTS can contain fragments of -# shell script including quotes and variable substitutions, so put them in -# double quotes to make sure that they get re-expanded; and -# * put everything else in single quotes, so that it's not re-expanded. - -set -- \ - "-Dorg.gradle.appname=$APP_BASE_NAME" \ - -classpath "$CLASSPATH" \ - org.gradle.wrapper.GradleWrapperMain \ - "$@" - -# Use "xargs" to parse quoted args. -# -# With -n1 it outputs one arg per line, with the quotes and backslashes removed. -# -# In Bash we could simply go: -# -# readarray ARGS < <( xargs -n1 <<<"$var" ) && -# set -- "${ARGS[@]}" "$@" -# -# but POSIX shell has neither arrays nor command substitution, so instead we -# post-process each arg (as a line of input to sed) to backslash-escape any -# character that might be a shell metacharacter, then use eval to reverse -# that process (while maintaining the separation between arguments), and wrap -# the whole thing up as a single "set" statement. -# -# This will of course break if any of these variables contains a newline or -# an unmatched quote. -# - -eval "set -- $( - printf '%s\n' "$DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS" | - xargs -n1 | - sed ' s~[^-[:alnum:]+,./:=@_]~\\&~g; ' | - tr '\n' ' ' - )" '"$@"' - -exec "$JAVACMD" "$@" diff --git a/oolab/gradlew.bat b/oolab/gradlew.bat deleted file mode 100644 index 107acd3..0000000 --- a/oolab/gradlew.bat +++ /dev/null @@ -1,89 +0,0 @@ -@rem -@rem Copyright 2015 the original author or authors. -@rem -@rem Licensed under the Apache License, Version 2.0 (the "License"); -@rem you may not use this file except in compliance with the License. -@rem You may obtain a copy of the License at -@rem -@rem https://www.apache.org/licenses/LICENSE-2.0 -@rem -@rem Unless required by applicable law or agreed to in writing, software -@rem distributed under the License is distributed on an "AS IS" BASIS, -@rem WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -@rem See the License for the specific language governing permissions and -@rem limitations under the License. -@rem - -@if "%DEBUG%" == "" @echo off -@rem ########################################################################## -@rem -@rem Gradle startup script for Windows -@rem -@rem ########################################################################## - -@rem Set local scope for the variables with windows NT shell -if "%OS%"=="Windows_NT" setlocal - -set DIRNAME=%~dp0 -if "%DIRNAME%" == "" set DIRNAME=. -set APP_BASE_NAME=%~n0 -set APP_HOME=%DIRNAME% - -@rem Resolve any "." and ".." in APP_HOME to make it shorter. -for %%i in ("%APP_HOME%") do set APP_HOME=%%~fi - -@rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. -set DEFAULT_JVM_OPTS="-Xmx64m" "-Xms64m" - -@rem Find java.exe -if defined JAVA_HOME goto findJavaFromJavaHome - -set JAVA_EXE=java.exe -%JAVA_EXE% -version >NUL 2>&1 -if "%ERRORLEVEL%" == "0" goto execute - -echo. -echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. -echo. -echo Please set the JAVA_HOME variable in your environment to match the -echo location of your Java installation. - -goto fail - -:findJavaFromJavaHome -set JAVA_HOME=%JAVA_HOME:"=% -set JAVA_EXE=%JAVA_HOME%/bin/java.exe - -if exist "%JAVA_EXE%" goto execute - -echo. -echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% -echo. -echo Please set the JAVA_HOME variable in your environment to match the -echo location of your Java installation. - -goto fail - -:execute -@rem Setup the command line - -set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar - - -@rem Execute Gradle -"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %* - -:end -@rem End local scope for the variables with windows NT shell -if "%ERRORLEVEL%"=="0" goto mainEnd - -:fail -rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of -rem the _cmd.exe /c_ return code! -if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1 -exit /b 1 - -:mainEnd -if "%OS%"=="Windows_NT" endlocal - -:omega diff --git a/oolab/src/main/java/agh/ics/oop/Simulation.java b/oolab/src/main/java/agh/ics/oop/Simulation.java index 3650b15..80176ec 100644 --- a/oolab/src/main/java/agh/ics/oop/Simulation.java +++ b/oolab/src/main/java/agh/ics/oop/Simulation.java @@ -12,8 +12,11 @@ public class Simulation { List Directions = new ArrayList<>(); public Simulation(List positions, List directions) { for(Vector2d position : positions) { - Animal new_animal = new Animal(position.getX(), position.getY()); - Animals.add(new_animal); + if (position.getX() >= 0 && position.getX() < 5 && position.getY() >= 0 && position.getY() < 5) + { + Animal new_animal = new Animal(position.getX(), position.getY()); + Animals.add(new_animal); + } } this.Directions = directions; @@ -36,4 +39,6 @@ public void run() { public List getAnimals() { return Animals; } + + public List getDirections() { return Directions; } } diff --git a/oolab/src/main/java/agh/ics/oop/World.java b/oolab/src/main/java/agh/ics/oop/World.java index 5955e5f..6ee6905 100644 --- a/oolab/src/main/java/agh/ics/oop/World.java +++ b/oolab/src/main/java/agh/ics/oop/World.java @@ -31,15 +31,9 @@ public static void run(List directions) { } public static void main(String[] args) { List directions = OptionsParser.Parser(args); - List positions = List.of(new Vector2d(2,2)); + List positions = List.of(new Vector2d(2,2), new Vector2d(3,4)); Simulation simulation = new Simulation(positions, directions); simulation.run(); - List finalAnimals = simulation.getAnimals(); - - for (Animal animal : finalAnimals) { - System.out.println(animal.getPosition()); - } - } } diff --git a/oolab/src/main/java/agh/ics/oop/model/Animal.java b/oolab/src/main/java/agh/ics/oop/model/Animal.java index 8c3cb42..6f37d59 100644 --- a/oolab/src/main/java/agh/ics/oop/model/Animal.java +++ b/oolab/src/main/java/agh/ics/oop/model/Animal.java @@ -25,7 +25,7 @@ public boolean isAt(Vector2d position) { return position.equals(this.position); } public void move(MoveDirection direction) { - Vector2d MAP_RIGHT_TOP = new Vector2d(4,4); + Vector2d MAP_RIGHT_TOP = new Vector2d(5,5); Vector2d MAP_LEFT_BOTTOM = new Vector2d(0,0); switch(direction) { diff --git a/oolab/src/main/java/agh/ics/oop/model/MapDirection.java b/oolab/src/main/java/agh/ics/oop/model/MapDirection.java index 5bf5d12..e013ba1 100644 --- a/oolab/src/main/java/agh/ics/oop/model/MapDirection.java +++ b/oolab/src/main/java/agh/ics/oop/model/MapDirection.java @@ -6,10 +6,10 @@ public enum MapDirection { @Override public String toString() { return switch (this) { - case NORTH -> "Północ"; - case EAST -> "Wschód"; - case SOUTH -> "Południe"; - case WEST -> "Zachód"; + case NORTH -> "Polnoc"; + case EAST -> "Wschod"; + case SOUTH -> "Poludnie"; + case WEST -> "Zachod"; }; } public MapDirection next() { diff --git a/oolab/src/test/java/agh/ics/oop/model/IntegrationMoveTest.java b/oolab/src/test/java/agh/ics/oop/model/IntegrationMoveTest.java index ade708c..f981df0 100644 --- a/oolab/src/test/java/agh/ics/oop/model/IntegrationMoveTest.java +++ b/oolab/src/test/java/agh/ics/oop/model/IntegrationMoveTest.java @@ -28,14 +28,14 @@ public void testValidMoves() { } List correctPositions = new ArrayList<>() {{ add(new Vector2d(2,3)); - add(new Vector2d(2,3)); + add(new Vector2d(3,3)); }}; assertEquals(correctPositions, actualPositions); } @Test public void testInvalidMoves() { - String[] args = {"f", "w", "h", "b"}; + String[] args = {"f", "w", "h", "b", "l", "r", "r", "f", "l", "b"}; List directions = OptionsParser.Parser(args); List positions = List.of(new Vector2d(2,2), new Vector2d(3,4)); Simulation simulation = new Simulation(positions, directions); @@ -55,8 +55,29 @@ public void testInvalidMoves() { assertEquals(correctPositions, actualPositions); } @Test - public void testOutOfBorderMoves() { - String[] args = {"f", "f", "f", "f", "f", "f", "f", "f", "f", "f", "f", "f"}; + public void testOutOfBorderMoves1() { + String[] args = {"f", "l", "f", "f", "f", "f", "f", "f", "f", "f", "f", "f"}; + List directions = OptionsParser.Parser(args); + List positions = List.of(new Vector2d(2,2), new Vector2d(3,4)); + Simulation simulation = new Simulation(positions, directions); + simulation.run(); + + List finalAnimals = simulation.getAnimals(); + List actualPositions = new ArrayList<>(); + + for (Animal animal : finalAnimals) { + actualPositions.add(animal.getPosition()); + } + List correctPositions = new ArrayList<>() {{ + add(new Vector2d(2,4)); + add(new Vector2d(0,4)); + }}; + + assertEquals(correctPositions, actualPositions); + } + @Test + public void testOutOfBorderMoves2() { + String[] args = {"f", "l", "l", "b", "b", "b", "b", "b", "b", "b", "b", "b"}; List directions = OptionsParser.Parser(args); List positions = List.of(new Vector2d(2,2), new Vector2d(3,4)); Simulation simulation = new Simulation(positions, directions); @@ -70,9 +91,65 @@ public void testOutOfBorderMoves() { } List correctPositions = new ArrayList<>() {{ add(new Vector2d(4,3)); - add(new Vector2d(3,4)); + add(new Vector2d(4,4)); }}; assertEquals(correctPositions, actualPositions); } + @Test + public void testInputValues() { + String[] args = {"f", "l", "r", "b", "r", "f", "j", "k"}; + List directions = OptionsParser.Parser(args); + List positions = List.of(new Vector2d(7,11), new Vector2d(3,4), new Vector2d(1,1), new Vector2d(0,0)); + Simulation simulation = new Simulation(positions, directions); + + List finalAnimals = simulation.getAnimals(); + List finalDirections = simulation.getDirections(); + List finalPositions = new ArrayList<>(); + + + for (Animal animal : finalAnimals) { + finalPositions.add(animal.getPosition()); + } + + List correctPositions = new ArrayList<>() {{ + add(new Vector2d(3,4)); + add(new Vector2d(1,1)); + add(new Vector2d(0,0)); + }}; + + List correctDirections = new ArrayList<>() {{ + add(MoveDirection.FORWARD); + add(MoveDirection.LEFT); + add(MoveDirection.RIGHT); + add(MoveDirection.BACKWARD); + add(MoveDirection.RIGHT); + add(MoveDirection.FORWARD); + }}; + + assertEquals(correctPositions, finalPositions); + assertEquals(correctDirections, finalDirections); + } + @Test + public void testOrientation() { + String[] args = {"f", "b", "l", "r", "r", "f", "l", "b"}; + List directions = OptionsParser.Parser(args); + List positions = List.of(new Vector2d(2,2), new Vector2d(3,4)); + Simulation simulation = new Simulation(positions, directions); + simulation.run(); + + List finalAnimals = simulation.getAnimals(); + List actualDirections = new ArrayList<>(); + + for (Animal animal : finalAnimals) { + actualDirections.add(animal.getDirection()); + } + List correctDirections = new ArrayList<>() {{ + add(MapDirection.WEST); + add(MapDirection.EAST); + }}; + + assertEquals(correctDirections, actualDirections); + } + } From d27508e1f33d74e17b06e3dd487f973dcc3a8d2d Mon Sep 17 00:00:00 2001 From: Kamil Rudny <134285490+krudny@users.noreply.github.com> Date: Sat, 11 Nov 2023 16:46:04 +0100 Subject: [PATCH 11/11] updated .gitignore --- .gitignore | 47 +++++++++++++++++++++++++++++++++++++++++++++++ oolab/.gitignore | 46 ---------------------------------------------- 2 files changed, 47 insertions(+), 46 deletions(-) delete mode 100644 oolab/.gitignore diff --git a/.gitignore b/.gitignore index 8f4e780..6df27a3 100644 --- a/.gitignore +++ b/.gitignore @@ -76,3 +76,50 @@ fabric.properties # Android studio 3.1+ serialized cache file .idea/caches/build_file_checksums.ser +.gradle +build/ +!gradle/wrapper/gradle-wrapper.jar +!**/src/main/**/build/ +!**/src/test/**/build/ + +### IntelliJ IDEA ### +.idea/modules.xml +.idea/jarRepositories.xml +.idea/compiler.xml +.idea/libraries/ +*.iws +*.iml +*.ipr +out/ +!**/src/main/**/out/ +!**/src/test/**/out/ + +### Eclipse ### +.apt_generated +.classpath +.factorypath +.project +.settings +.springBeans +.sts4-cache +bin/ +!**/src/main/**/bin/ +!**/src/test/**/bin/ + +### NetBeans ### +/nbproject/private/ +/nbbuild/ +/dist/ +/nbdist/ +/.nb-gradle/ + +### VS Code ### +.vscode/ + +### Mac OS ### +.DS_Store + +oolab/.idea/ +oolab/gradlew.bat +oolab/gradlew +oolab/.gitignore \ No newline at end of file diff --git a/oolab/.gitignore b/oolab/.gitignore deleted file mode 100644 index 992973c..0000000 --- a/oolab/.gitignore +++ /dev/null @@ -1,46 +0,0 @@ -.gradle -build/ -!gradle/wrapper/gradle-wrapper.jar -!**/src/main/**/build/ -!**/src/test/**/build/ - -### IntelliJ IDEA ### -.idea/modules.xml -.idea/jarRepositories.xml -.idea/compiler.xml -.idea/libraries/ -*.iws -*.iml -*.ipr -out/ -!**/src/main/**/out/ -!**/src/test/**/out/ - -### Eclipse ### -.apt_generated -.classpath -.factorypath -.project -.settings -.springBeans -.sts4-cache -bin/ -!**/src/main/**/bin/ -!**/src/test/**/bin/ - -### NetBeans ### -/nbproject/private/ -/nbbuild/ -/dist/ -/nbdist/ -/.nb-gradle/ - -### VS Code ### -.vscode/ - -### Mac OS ### -.DS_Store - -/.idea/ -gradlew.bat -gradlew \ No newline at end of file