From a127f3a2da87c8dbad5c85b53ad71cff761c4c95 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E2=80=9Cwardin231=E2=80=9D?= Date: Sun, 11 Feb 2024 12:03:26 +0100 Subject: [PATCH 1/2] lab Finished --- .idea/.gitignore | 3 +++ .idea/lab-java-intro-to-testing.iml | 9 +++++++++ .idea/misc.xml | 6 ++++++ .idea/modules.xml | 8 ++++++++ .idea/vcs.xml | 6 ++++++ 5 files changed, 32 insertions(+) create mode 100644 .idea/.gitignore create mode 100644 .idea/lab-java-intro-to-testing.iml create mode 100644 .idea/misc.xml create mode 100644 .idea/modules.xml create mode 100644 .idea/vcs.xml diff --git a/.idea/.gitignore b/.idea/.gitignore new file mode 100644 index 0000000..26d3352 --- /dev/null +++ b/.idea/.gitignore @@ -0,0 +1,3 @@ +# Default ignored files +/shelf/ +/workspace.xml diff --git a/.idea/lab-java-intro-to-testing.iml b/.idea/lab-java-intro-to-testing.iml new file mode 100644 index 0000000..d6ebd48 --- /dev/null +++ b/.idea/lab-java-intro-to-testing.iml @@ -0,0 +1,9 @@ + + + + + + + + + \ No newline at end of file diff --git a/.idea/misc.xml b/.idea/misc.xml new file mode 100644 index 0000000..6f29fee --- /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 0000000..ab88969 --- /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 0000000..35eb1dd --- /dev/null +++ b/.idea/vcs.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file From fd4a0714f5c872b66bcc6a64582899c9579ca4e3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E2=80=9Cwardin231=E2=80=9D?= Date: Sun, 11 Feb 2024 12:20:11 +0100 Subject: [PATCH 2/2] New push, lab finished --- .DS_Store | Bin 0 -> 6148 bytes solution/.gitignore | 38 ++++++ solution/.idea/.gitignore | 3 + solution/.idea/encodings.xml | 7 + solution/.idea/misc.xml | 15 +++ solution/.idea/uiDesigner.xml | 124 ++++++++++++++++++ solution/pom.xml | 32 +++++ solution/src/main/java/ex1/lab.java | 17 +++ solution/src/main/java/ex2/keywords.java | 30 +++++ solution/src/main/java/ex3/PlayerClass.java | 98 ++++++++++++++ solution/src/test/java/ex1/labTest.java | 20 +++ solution/src/test/java/ex2/keywordsTest.java | 48 +++++++ .../src/test/java/ex3/PlayerClassTest.java | 117 +++++++++++++++++ 13 files changed, 549 insertions(+) create mode 100644 .DS_Store create mode 100644 solution/.gitignore create mode 100644 solution/.idea/.gitignore create mode 100644 solution/.idea/encodings.xml create mode 100644 solution/.idea/misc.xml create mode 100644 solution/.idea/uiDesigner.xml create mode 100644 solution/pom.xml create mode 100644 solution/src/main/java/ex1/lab.java create mode 100644 solution/src/main/java/ex2/keywords.java create mode 100644 solution/src/main/java/ex3/PlayerClass.java create mode 100644 solution/src/test/java/ex1/labTest.java create mode 100644 solution/src/test/java/ex2/keywordsTest.java create mode 100644 solution/src/test/java/ex3/PlayerClassTest.java diff --git a/.DS_Store b/.DS_Store new file mode 100644 index 0000000000000000000000000000000000000000..a827e3093b2d57039ac812781c0022e8d296978d GIT binary patch literal 6148 zcmeHKU279T6ur|%yJ->fpwJg#!PlluViClbG)=+yQKhT#K_%{HLz=qT3A>vH4S_uC zkMY%C;@{D8XQq%e2~q?pWiH$~Gk5Np%^c<|faqA{n5UkA?&I?r&wN@o|un zq=<%;Q4h7a5zXd{`+v(1M(Mze|1%gwy)-M8eu=g9+^yRi&W5w)eDqG`$jkg}nAZH{ zJ-6OS83h-0KWO$kqgLVWp^P)X7k3gx=!G4me0bN3LpiF+VH~E4>*)?B@8nyB?eVx= z+TU^a%azHFJAPa#q5kmEWRiF8J=lA4()t|rWBEdTKt(zOp2Lf3v`pm{ks}e|dGKubm+^O2 ztOzJ@Y!p~nQL8wYRvOZ-Y-VLUTUTaUf>ppOaMKmw^TCBPRt-)ys-pvidIA7*2rEOK z|1dDeHCQz`)rcOL&{UwN3iHGenvS?@@~Q@>8a17Sd3*@-Wno?@LVX?MyDFVTRiiDf z0#<=}1=e-5!1w>r>i7RV$+oNlR)HI(fXLOodJR)Dck9CB_^x%~pWtkqH`S;pD9m-N gDtr}h! + + + + + + \ No newline at end of file diff --git a/solution/.idea/misc.xml b/solution/.idea/misc.xml new file mode 100644 index 0000000..45028cd --- /dev/null +++ b/solution/.idea/misc.xml @@ -0,0 +1,15 @@ + + + + + + + + + + \ No newline at end of file diff --git a/solution/.idea/uiDesigner.xml b/solution/.idea/uiDesigner.xml new file mode 100644 index 0000000..2b63946 --- /dev/null +++ b/solution/.idea/uiDesigner.xml @@ -0,0 +1,124 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/solution/pom.xml b/solution/pom.xml new file mode 100644 index 0000000..3190d48 --- /dev/null +++ b/solution/pom.xml @@ -0,0 +1,32 @@ + + + 4.0.0 + + ironhack.com + introTesting + 1.0-SNAPSHOT + + + 17 + 17 + UTF-8 + + + + + org.junit.jupiter + junit-jupiter + 5.10.0 + test + + + org.junit.jupiter + junit-jupiter + RELEASE + test + + + + \ No newline at end of file diff --git a/solution/src/main/java/ex1/lab.java b/solution/src/main/java/ex1/lab.java new file mode 100644 index 0000000..15a9539 --- /dev/null +++ b/solution/src/main/java/ex1/lab.java @@ -0,0 +1,17 @@ +package ex1; + +import java.util.ArrayList; + +public class lab { + + public static ArrayList ar(int n){ + ArrayList numers = new ArrayList<>(n); + + for (int i = 0; i keywords = new ArrayList(); + keywords.add("abstract"); + keywords.add("boolean"); + keywords.add("break"); + keywords.add("byte"); + keywords.add("cas"); + keywords.add("cath"); + keywords.add("char"); + keywords.add("continue"); + keywords.add("default"); + keywords.add("do"); + keywords.add("double"); + keywords.add("else"); + + for (String i : words.split("\\s+")){ + for (String x : keywords){ + if (i.equals(x)){ + return true; + } + } + } + return false; + } +} diff --git a/solution/src/main/java/ex3/PlayerClass.java b/solution/src/main/java/ex3/PlayerClass.java new file mode 100644 index 0000000..314be0f --- /dev/null +++ b/solution/src/main/java/ex3/PlayerClass.java @@ -0,0 +1,98 @@ +package ex3; + + +abstract class Player{ + private int health; + private int strenght; + private int lives; + + public Player(int health, int strenght, int lives){ + this.health = 100; + setStrenght(strenght); + setLives(lives); + } + + public int getHealth() { + return health; + } + + public void setHealth(int health) { + this.health = health; + } + + public int getStrenght() { + return strenght; + } + + public void setStrenght(int strenght) { + this.strenght = strenght; + } + + public int getLives() { + return lives; + } + + public void setLives(int lives) { + this.lives = lives; + } + + public void decrementLive(){ + lives -= 1; + health = 100; + } + + public void attack(Player playerToAttack){ + playerToAttack.health -= strenght; + } + + public boolean checkHealth(){ + if (getHealth() == 0){ + decrementLive(); + } + return false; + } + +} + + +class Elf extends Player{ + private int speed; + public Elf(int health, int strength, int lives){ + super(health, strength, lives); + setSpeed(speed); + } + + public int getSpeed() { + return speed; + } + + public void setSpeed(int speed) { + this.speed = speed; + } +} + +class Warrior extends Player{ + public Warrior(int health, int strength, int lives){ + super(health, strength, lives); + } + + public Elf convertToElf(int speed){ + Elf elf = new Elf(getHealth(), getStrenght(), getLives()); + elf.setSpeed(speed); + return elf; + } +} + +class Wizard extends Player{ + public Wizard(int health, int strength, int lives){ + super(health, strength, lives); + } + + public Elf spell(int speed){ + Elf elf = new Elf(getHealth(), getStrenght(), getLives()); + elf.setSpeed(speed); + return elf; + } +} + + diff --git a/solution/src/test/java/ex1/labTest.java b/solution/src/test/java/ex1/labTest.java new file mode 100644 index 0000000..8f98ce0 --- /dev/null +++ b/solution/src/test/java/ex1/labTest.java @@ -0,0 +1,20 @@ +package ex1; +import java.util.ArrayList; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import static org.junit.jupiter.api.Assertions.assertEquals; + +public class labTest { + + @Test + void labTesting() { + ArrayList result = new ArrayList<>(); + result.add(0); + result.add(2); + result.add(4); + + assertEquals(lab.ar(5), result); + } +} + + diff --git a/solution/src/test/java/ex2/keywordsTest.java b/solution/src/test/java/ex2/keywordsTest.java new file mode 100644 index 0000000..539c0ef --- /dev/null +++ b/solution/src/test/java/ex2/keywordsTest.java @@ -0,0 +1,48 @@ +package ex2; +import java.util.ArrayList; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.Test; +import static org.junit.jupiter.api.Assertions.assertTrue; +import static org.junit.jupiter.api.Assertions.assertFalse; + + +public class keywordsTest { + + private final static ArrayList keywords = new ArrayList(); + + @BeforeAll + static void init(){ + + keywords.add("abstract"); + keywords.add("boolean"); + keywords.add("break"); + keywords.add("byte"); + keywords.add("cas"); + keywords.add("cath"); + keywords.add("char"); + keywords.add("continue"); + keywords.add("default"); + keywords.add("do"); + keywords.add("double"); + keywords.add("else"); + } + + private boolean check(String words){ + for (String i : words.split("\\s+")){ + for (String x : keywords){ + if (i.equals(x)){ + return true; + } + } + } + return false; + } + + @Test + void keyCheck(){ + assertTrue(check("I do my homework"), String.valueOf(true)); + assertFalse(check("I don“t my homework"), String.valueOf(true)); + } + + +} diff --git a/solution/src/test/java/ex3/PlayerClassTest.java b/solution/src/test/java/ex3/PlayerClassTest.java new file mode 100644 index 0000000..736707d --- /dev/null +++ b/solution/src/test/java/ex3/PlayerClassTest.java @@ -0,0 +1,117 @@ +package ex3; + +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; + +public class PlayerClassTest { + @BeforeEach + void setPlayer() { + } + + abstract class Player { + private int health; + private int strenght; + private int lives; + + public Player(int health, int strenght, int lives) { + this.health = 100; + setStrenght(strenght); + setLives(lives); + } + + public int getHealth() { + return health; + } + + public void setHealth(int health) { + this.health = health; + } + + public int getStrenght() { + return strenght; + } + + public void setStrenght(int strenght) { + this.strenght = strenght; + } + + public int getLives() { + return lives; + } + + public void setLives(int lives) { + this.lives = lives; + } + + public void decrementLive() { + lives -= 1; + health = 100; + } + + public void attack(Player playerToAttack) { + playerToAttack.health -= strenght; + } + + public boolean checkHealth() { + if (getHealth() == 0) { + decrementLive(); + } + return false; + } + + } + + @Test + void createElf() { + class Elf extends Player { + private int speed; + + public Elf(int health, int strength, int lives) { + super(health, strength, lives); + setSpeed(speed); + } + + public int getSpeed() { + return speed; + } + + public void setSpeed(int speed) { + this.speed = speed; + } + } + } + + @Test + void createWarrior(){ + class Warrior extends ex3.Player { + public Warrior(int health, int strength, int lives) { + super(health, strength, lives); + } + + public ex3.Elf convertToElf(int speed) { + ex3.Elf elf = new ex3.Elf(getHealth(), getStrenght(), getLives()); + elf.setSpeed(speed); + return elf; + } + } + } + + @Test + void createWizard() { + class Wizard extends ex3.Player { + public Wizard(int health, int strength, int lives) { + super(health, strength, lives); + } + + public ex3.Elf spell(int speed) { + ex3.Elf elf = new ex3.Elf(getHealth(), getStrenght(), getLives()); + elf.setSpeed(speed); + return elf; + } + } + } +} + + +