From efdce49d638fea18a91ff252ef6b422f2816cfd8 Mon Sep 17 00:00:00 2001 From: Doremina Date: Wed, 27 Dec 2023 16:43:37 +0300 Subject: [PATCH 01/13] started working on make experiment test also added toString to Molecule for future use on tests --- domain/potion/Molecule.java | 41 +++++++++++++++++++++++++++--------- test/TestMakeExperiment.java | 34 ++++++++++++++++++++++++++++++ 2 files changed, 65 insertions(+), 10 deletions(-) create mode 100644 test/TestMakeExperiment.java diff --git a/domain/potion/Molecule.java b/domain/potion/Molecule.java index 65f6755..b07f593 100644 --- a/domain/potion/Molecule.java +++ b/domain/potion/Molecule.java @@ -3,14 +3,14 @@ import java.util.Objects; public class Molecule { - + int moleculeId; Atom redAtom; Atom greenAtom; Atom blueAtom; public Molecule(int moleculeId, Atom redAtom, Atom greenAtom, Atom blueAtom) { - + this.moleculeId = moleculeId; this.redAtom = redAtom; this.greenAtom = greenAtom; @@ -38,27 +38,27 @@ public boolean equals(Object obj) { } public void setAtom(Atom atom) { - + if(atom.getAtomColor()==0) { this.redAtom=atom; }else if(atom.getAtomColor()==1) { - + this.greenAtom=atom; }else if(atom.getAtomColor()==2) { - + this.blueAtom=atom; } } - + public Atom getAtomByColor(int atomColorId) { if(redAtom.getAtomColor() == atomColorId) { return redAtom; } - + else if(greenAtom.getAtomColor() == atomColorId) { return greenAtom; } - + else if(blueAtom.getAtomColor() == atomColorId) { return blueAtom; } @@ -113,6 +113,27 @@ public Atom getBlueAtom() { public void setBlueAtom(Atom blueAtom) { this.blueAtom = blueAtom; } - - + + @Override + public String toString() { + + Atom redAtom = this.getRedAtom(); + String redAtomSize = (redAtom.getAtomSize() == 1? "Big" : "Small"); + String redAtomSign = (redAtom.getAtomSign() == 0? "Negative" : "Positive"); + + Atom blueAtom = this.getBlueAtom(); + String blueAtomSize = (blueAtom.getAtomSize() == 1? "Big" : "Small"); + String blueAtomSign = (blueAtom.getAtomSign() == 0? "Negative" : "Positive"); + + Atom greenAtom = this.getGreenAtom(); + String greenAtomSize = (greenAtom.getAtomSize() == 1? "Big" : "Small"); + String greenAtomSign = (greenAtom.getAtomSign() == 0? "Negative" : "Positive"); + + String str = "Red: " + redAtomSize + " " + redAtomSign; + str += "\nBlue: " + blueAtomSize + " " + blueAtomSign; + str += "\nGreen: " + greenAtomSize + " " + greenAtomSign; + + return str; + } + } diff --git a/test/TestMakeExperiment.java b/test/TestMakeExperiment.java new file mode 100644 index 0000000..ed0baa5 --- /dev/null +++ b/test/TestMakeExperiment.java @@ -0,0 +1,34 @@ +package test; + +import java.util.ArrayList; + +import domain.GameController; +import domain.GameInventory; +import domain.cards.IngredientCard; +import domain.potion.Atom; +import domain.potion.Molecule; +import userinterface.LoginSignupController; + +public class TestMakeExperiment { + + GameController controller; + GameInventory inventory; + ArrayList ingredientCards; + + public static void main(String[] args) { + + } + + public void testExperiment() { + + LoginSignupController.getInstance().signup("TestUser1", "testuser"); + LoginSignupController.getInstance().login("TestUser1", "testuser"); + + LoginSignupController.getInstance().signup("TestUser2", "testuser"); + LoginSignupController.getInstance().login("TestUser2", "testuser"); + + GameController.initializeGame(); + //controller = GameController.geti + inventory = GameInventory.getInstance(); + } +} From 30841a85acbbcf5dd4387a61f2792e5136992d31 Mon Sep 17 00:00:00 2001 From: Doremina Date: Wed, 27 Dec 2023 16:43:37 +0300 Subject: [PATCH 02/13] started working on make experiment test also added toString to Molecule for future use on tests --- domain/potion/Molecule.java | 41 +++++++++++++++++++++++++++--------- test/TestMakeExperiment.java | 34 ++++++++++++++++++++++++++++++ 2 files changed, 65 insertions(+), 10 deletions(-) create mode 100644 test/TestMakeExperiment.java diff --git a/domain/potion/Molecule.java b/domain/potion/Molecule.java index 65f6755..b07f593 100644 --- a/domain/potion/Molecule.java +++ b/domain/potion/Molecule.java @@ -3,14 +3,14 @@ import java.util.Objects; public class Molecule { - + int moleculeId; Atom redAtom; Atom greenAtom; Atom blueAtom; public Molecule(int moleculeId, Atom redAtom, Atom greenAtom, Atom blueAtom) { - + this.moleculeId = moleculeId; this.redAtom = redAtom; this.greenAtom = greenAtom; @@ -38,27 +38,27 @@ public boolean equals(Object obj) { } public void setAtom(Atom atom) { - + if(atom.getAtomColor()==0) { this.redAtom=atom; }else if(atom.getAtomColor()==1) { - + this.greenAtom=atom; }else if(atom.getAtomColor()==2) { - + this.blueAtom=atom; } } - + public Atom getAtomByColor(int atomColorId) { if(redAtom.getAtomColor() == atomColorId) { return redAtom; } - + else if(greenAtom.getAtomColor() == atomColorId) { return greenAtom; } - + else if(blueAtom.getAtomColor() == atomColorId) { return blueAtom; } @@ -113,6 +113,27 @@ public Atom getBlueAtom() { public void setBlueAtom(Atom blueAtom) { this.blueAtom = blueAtom; } - - + + @Override + public String toString() { + + Atom redAtom = this.getRedAtom(); + String redAtomSize = (redAtom.getAtomSize() == 1? "Big" : "Small"); + String redAtomSign = (redAtom.getAtomSign() == 0? "Negative" : "Positive"); + + Atom blueAtom = this.getBlueAtom(); + String blueAtomSize = (blueAtom.getAtomSize() == 1? "Big" : "Small"); + String blueAtomSign = (blueAtom.getAtomSign() == 0? "Negative" : "Positive"); + + Atom greenAtom = this.getGreenAtom(); + String greenAtomSize = (greenAtom.getAtomSize() == 1? "Big" : "Small"); + String greenAtomSign = (greenAtom.getAtomSign() == 0? "Negative" : "Positive"); + + String str = "Red: " + redAtomSize + " " + redAtomSign; + str += "\nBlue: " + blueAtomSize + " " + blueAtomSign; + str += "\nGreen: " + greenAtomSize + " " + greenAtomSign; + + return str; + } + } diff --git a/test/TestMakeExperiment.java b/test/TestMakeExperiment.java new file mode 100644 index 0000000..ed0baa5 --- /dev/null +++ b/test/TestMakeExperiment.java @@ -0,0 +1,34 @@ +package test; + +import java.util.ArrayList; + +import domain.GameController; +import domain.GameInventory; +import domain.cards.IngredientCard; +import domain.potion.Atom; +import domain.potion.Molecule; +import userinterface.LoginSignupController; + +public class TestMakeExperiment { + + GameController controller; + GameInventory inventory; + ArrayList ingredientCards; + + public static void main(String[] args) { + + } + + public void testExperiment() { + + LoginSignupController.getInstance().signup("TestUser1", "testuser"); + LoginSignupController.getInstance().login("TestUser1", "testuser"); + + LoginSignupController.getInstance().signup("TestUser2", "testuser"); + LoginSignupController.getInstance().login("TestUser2", "testuser"); + + GameController.initializeGame(); + //controller = GameController.geti + inventory = GameInventory.getInstance(); + } +} From 66f4ba4e6e3b580fab3d0968c750fac65be6b281 Mon Sep 17 00:00:00 2001 From: Doremina Date: Wed, 27 Dec 2023 19:49:08 +0300 Subject: [PATCH 03/13] still working. just to make sure the code is safe --- test/TestMakeExperiment.java | 32 +++++++++++++++++++++++++++++--- 1 file changed, 29 insertions(+), 3 deletions(-) diff --git a/test/TestMakeExperiment.java b/test/TestMakeExperiment.java index ed0baa5..ebda0b4 100644 --- a/test/TestMakeExperiment.java +++ b/test/TestMakeExperiment.java @@ -7,6 +7,7 @@ import domain.cards.IngredientCard; import domain.potion.Atom; import domain.potion.Molecule; +import exception.UserErrorException; import userinterface.LoginSignupController; public class TestMakeExperiment { @@ -21,14 +22,39 @@ public static void main(String[] args) { public void testExperiment() { + //Initialize game first + controller = GameController.getInstance(); + LoginSignupController.getInstance().signup("TestUser1", "testuser"); LoginSignupController.getInstance().login("TestUser1", "testuser"); LoginSignupController.getInstance().signup("TestUser2", "testuser"); LoginSignupController.getInstance().login("TestUser2", "testuser"); - GameController.initializeGame(); - //controller = GameController.geti - inventory = GameInventory.getInstance(); + controller.initializeGame(); + + //Then we can get inventory (after the game is initialized) + inventory = controller.getGameInventory(); + + //makeExperiment(IngredientCard ingredient1, IngredientCard ingredient2, Boolean testOnStu) + //throws UserErrorException, RuntimeException + + //For testing purposes, added 50 actions to the current player + controller.getCurrentPlayer().getPlayerToken().setPlayerAction(50); + + /* + * Things to test: + **** For all tests + ** + **** Drink Potion Tests + ** Health Potion (Red +) -> playerHealth should increase by 1. + ** Speed Potion (Green +) -> playerAction should increase by 1. + ** Wisdom Potion (Blue +) -> playerReputation should increase by 1. + * (Since player's gonna use 1 action to test the potion, the action amount before and after... + * ...makeExperiment should remain the same.) + * + */ + + } } From 680120008957ef64b69d9b673d57bd74563cc579 Mon Sep 17 00:00:00 2001 From: Doremina Date: Thu, 28 Dec 2023 17:18:48 +0300 Subject: [PATCH 04/13] added toString methods to player, inventory, token --- domain/player/Player.java | 6 ++ domain/player/PlayerInventory.java | 35 +++++++----- domain/player/PlayerToken.java | 88 ++++++++++++++++-------------- 3 files changed, 75 insertions(+), 54 deletions(-) diff --git a/domain/player/Player.java b/domain/player/Player.java index 7c7a9dd..c5fbcb1 100644 --- a/domain/player/Player.java +++ b/domain/player/Player.java @@ -71,4 +71,10 @@ public boolean equals(Player p2) { else return false; } + @Override + public String toString() { + + String str = playerName + playerToken; + return str; + } } diff --git a/domain/player/PlayerInventory.java b/domain/player/PlayerInventory.java index d9dfb09..c8fb4aa 100644 --- a/domain/player/PlayerInventory.java +++ b/domain/player/PlayerInventory.java @@ -17,7 +17,7 @@ public class PlayerInventory { final ArrayList playerPublicationCardList; public PlayerInventory() { - + playerRecipeList = new ArrayList(); playerPotionList = new ArrayList(); playerHypothesesList = new ArrayList(); @@ -25,7 +25,7 @@ public PlayerInventory() { playerArtifactCardList = new ArrayList(); playerPublicationCardList = new ArrayList(); } - + public ArrayList getPlayerRecipeList() { return playerRecipeList; } @@ -58,49 +58,56 @@ public ArrayList getPlayerPublicationCardList() { public void addPotion(Potion potion) { this.playerPotionList.add(potion); } - + public void addRecipe(Recipe recipe) { this.playerRecipeList.add(recipe); } - + public void addHypoteses(Hypotheses hyp) { this.playerHypothesesList.add(hyp); } - + public void addAIngredientCard(IngredientCard ing) { this.playerIngredientCardList.add(ing); } - + public void addArtifactCard(ArtifactCard art) { this.playerArtifactCardList.add(art); } - + public void addPublicationCard(PublicationCard pub) { this.playerPublicationCardList.add(pub); } - + public void removePotion(Potion potion) { this.playerPotionList.remove(potion); } - + public void removeRecipe(Recipe recipe) { this.playerRecipeList.remove(recipe); } - + public void removeHypoteses(Hypotheses hyp) { this.playerHypothesesList.remove(hyp); } - + public void removeIngredientCard(IngredientCard ing) { this.playerIngredientCardList.remove(ing); } - + public void removeArtifactCard(ArtifactCard art) { this.playerArtifactCardList.remove(art); } - + public void removePublicationCard(PublicationCard pub) { this.playerPublicationCardList.remove(pub); } - + + @Override + public String toString() { + + String str = "\nIngredient Cards: " + playerIngredientCardList + "\nArtifact Cards: " + playerArtifactCardList + "\nPotion List: " + playerPotionList + "\nRecipes: " + playerRecipeList ; + return str; + } + } diff --git a/domain/player/PlayerToken.java b/domain/player/PlayerToken.java index 574e427..c2ce5bf 100644 --- a/domain/player/PlayerToken.java +++ b/domain/player/PlayerToken.java @@ -18,39 +18,39 @@ public class PlayerToken { int playerAction=3; String playerAvatar; // the directory of the playeravatar is kept in this as a string. PlayerInventory playerInventory; - - + + public PlayerToken() { - + this.playerInventory= new PlayerInventory(); } - - + + public void addGold(int gold) { this.gold=this.gold+gold; - + } public void subtractGold(int gold) { this.gold=this.gold-gold; - + } public void addReputationPoint(int point) { this.reputation=this.reputation+point; - + } public void subtractReputationPoint(int point) { this.reputation=this.reputation-point; - + } - + public void addHealth() { if(this.playerHealth<3) { this.playerHealth++; } } - + public void reduceHealth() { if(this.playerHealth>0) { this.playerHealth--; @@ -60,56 +60,56 @@ public void reduceHealth() { this.gold=0; } } - - - - - + + + + + public void addPotion(Potion potion) { playerInventory.playerPotionList.add(potion); } - + public void addRecipe(Recipe recipe) { playerInventory.playerRecipeList.add(recipe); } - + public void addHypoteses(Hypotheses hyp) { playerInventory.playerHypothesesList.add(hyp); } - + public void addAIngredientCard(IngredientCard ing) { playerInventory.playerIngredientCardList.add(ing); } - + public void addArtifactCard(ArtifactCard art) { playerInventory.playerArtifactCardList.add(art); } - + public void addPublicationCard(PublicationCard pub) { playerInventory.playerPublicationCardList.add(pub); } - + public void removePotion(Potion potion) { playerInventory.playerPotionList.remove(potion); } - + public void removeRecipe(Recipe recipe) { playerInventory.playerRecipeList.remove(recipe); } - + public void removeHypoteses(Hypotheses hyp) { playerInventory.playerHypothesesList.remove(hyp); } - + public void removeIngredientCard(IngredientCard ing) { playerInventory.playerIngredientCardList.remove(ing); } - + public void removeArtifactCard(ArtifactCard art) { playerInventory.playerArtifactCardList.remove(art); } - + public void removePublicationCard(PublicationCard pub) { playerInventory.playerPublicationCardList.remove(pub); } @@ -173,26 +173,26 @@ public void setPlayerAvatar(String playerAvatar) { */ public void reducePlayerAction() throws RuntimeException{ if(this.playerAction<=0) { - - + + throw new RuntimeException("Tried to reduce user actions when the user had no actions left"); - + } this.playerAction -= 1; - + //GameController.changeCurrentPlayer(); if(this.playerAction ==0) { GameController.getInstance().changeCurrentPlayer(); } - - + + if(GameController.getInstance().shouldChangeRound()) { GameController.getInstance().changeRounds(); } - - + + } - + public PlayerInventory getPlayerInventory() { return playerInventory; } @@ -201,8 +201,16 @@ public PlayerInventory getPlayerInventory() { public void setPlayerInventory(PlayerInventory playerInventory) { this.playerInventory = playerInventory; } - - - - + + @Override + public String toString() { + + String str = "\nGold: " + gold + " Reputation: " + reputation + " Health: " + playerHealth + " Left Actions: " + playerAction; + str += playerInventory; + return str; + } + + + + } From c510ff800bb0d0fc6e7fc1d58c48c32c7402b99d Mon Sep 17 00:00:00 2001 From: Doremina Date: Thu, 28 Dec 2023 17:19:18 +0300 Subject: [PATCH 05/13] can't test tostring methods due to classpath error --- test/TestMakeExperiment.java | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) diff --git a/test/TestMakeExperiment.java b/test/TestMakeExperiment.java index ebda0b4..256f47b 100644 --- a/test/TestMakeExperiment.java +++ b/test/TestMakeExperiment.java @@ -17,7 +17,8 @@ public class TestMakeExperiment { ArrayList ingredientCards; public static void main(String[] args) { - + testExperiment(); + System.out.print(controller.getCurrentPlayer()); } public void testExperiment() { @@ -39,8 +40,8 @@ public void testExperiment() { //makeExperiment(IngredientCard ingredient1, IngredientCard ingredient2, Boolean testOnStu) //throws UserErrorException, RuntimeException - //For testing purposes, added 50 actions to the current player - controller.getCurrentPlayer().getPlayerToken().setPlayerAction(50); + //For testing purposes, added 100 actions to the current player + controller.getCurrentPlayer().getPlayerToken().setPlayerAction(100); /* * Things to test: @@ -52,9 +53,21 @@ public void testExperiment() { ** Wisdom Potion (Blue +) -> playerReputation should increase by 1. * (Since player's gonna use 1 action to test the potion, the action amount before and after... * ...makeExperiment should remain the same.) + * + ** Poison Potion (Red -) -> playerHealth should reduce by 1. + ** Slow Potion (Green -) -> playerHealth should reduce by 1. playerAction should reduce by 1 (if any left). + ** Insanity Potion (Blue -) -> playerHealth should reduce by 1. playerReputation should reduce by 1. * + ** Neutral Potion -> No effect. */ + //TODO In Potion class's testPotion() method, line 61 + //if (!GameController.getInstance().getCurrentPlayer().getInventory().getPlayerArtifactCardList().contains(GameController.getInstance().getGameInventory().getArtCards().get(1))) + //is a very fragile code. It should check all items in ArrayList and check if (item instanceof Vaccine) + //when the order of the cards change, the function won't function + //TODO playerHealth is in both Player and PlayerToken classes. Choose one (I think Player class is a better answer) + + } } From 920013feb3a72b487ef41d9352ed1f3d214d8721 Mon Sep 17 00:00:00 2001 From: Doremina Date: Fri, 29 Dec 2023 00:04:24 +0300 Subject: [PATCH 06/13] fixed classpath on testing2 --- .classpath | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.classpath b/.classpath index 020f156..f2e6b00 100644 --- a/.classpath +++ b/.classpath @@ -7,6 +7,6 @@ - + From 5c3d11e81cf72a370c81d20a4471cf9b5e9a656f Mon Sep 17 00:00:00 2001 From: Doremina Date: Fri, 29 Dec 2023 00:24:45 +0300 Subject: [PATCH 07/13] commented out problematic code --- test/TestMakeExperiment.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/test/TestMakeExperiment.java b/test/TestMakeExperiment.java index 256f47b..4e5baec 100644 --- a/test/TestMakeExperiment.java +++ b/test/TestMakeExperiment.java @@ -17,8 +17,8 @@ public class TestMakeExperiment { ArrayList ingredientCards; public static void main(String[] args) { - testExperiment(); - System.out.print(controller.getCurrentPlayer()); + //testExperiment(); + //System.out.print(controller.getCurrentPlayer()); } public void testExperiment() { From c23365ff82a6b6158c183b643f53c7c47e920def Mon Sep 17 00:00:00 2001 From: batuogkoc Date: Fri, 29 Dec 2023 01:29:51 +0300 Subject: [PATCH 08/13] added junit 5 and begun work on forage ingredient tests --- .classpath | 1 + test/TestForageForIngredient.java | 30 ++++++++++++++++++++++++++++++ 2 files changed, 31 insertions(+) create mode 100644 test/TestForageForIngredient.java diff --git a/.classpath b/.classpath index f2e6b00..303d7b8 100644 --- a/.classpath +++ b/.classpath @@ -5,6 +5,7 @@ + diff --git a/test/TestForageForIngredient.java b/test/TestForageForIngredient.java new file mode 100644 index 0000000..bdf5221 --- /dev/null +++ b/test/TestForageForIngredient.java @@ -0,0 +1,30 @@ +package test; +import static org.junit.jupiter.api.Assertions.assertThrows; + +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; + +import domain.GameController; +import domain.boards.BoardController; +import domain.boards.IngredientBoard; +import domain.player.*; + +public class TestForageForIngredient { + + public TestForageForIngredient() { + // TODO Auto-generated constructor stub + } + + @BeforeEach + public static void beforeEach() { + TestGameInitializer.initializeTestGame(); + } + + @Test + public static void noActionsLeft() { + Player currentPlayer = GameController.getInstance().getCurrentPlayer(); + currentPlayer.getPlayerToken().setPlayerAction(0); + assertThrows(null, BoardController.forageForIngredient); + } + +} From 454c096732be6cbc97e05920add4149edff8d179 Mon Sep 17 00:00:00 2001 From: batuogkoc Date: Fri, 29 Dec 2023 02:32:03 +0300 Subject: [PATCH 09/13] Had some trouble with junit, will continue later --- domain/GameController.java | 2 +- test/TestForageForIngredient.java | 70 +++++++++++++++++++++++++++++-- userinfo.json | 2 +- 3 files changed, 68 insertions(+), 6 deletions(-) diff --git a/domain/GameController.java b/domain/GameController.java index 029a373..d195b08 100644 --- a/domain/GameController.java +++ b/domain/GameController.java @@ -48,7 +48,7 @@ public void initializeGame() { initalizeGameHelper=new InitializeGameHelper(); } else { - System.out.println("Not able to initialize"); + System.out.println("Not able to initialize, have " + activePlayers.size() + "players, need 2"); } } diff --git a/test/TestForageForIngredient.java b/test/TestForageForIngredient.java index bdf5221..72eca47 100644 --- a/test/TestForageForIngredient.java +++ b/test/TestForageForIngredient.java @@ -1,4 +1,7 @@ package test; +import static org.junit.jupiter.api.Assertions.assertDoesNotThrow; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNotEquals; import static org.junit.jupiter.api.Assertions.assertThrows; import org.junit.jupiter.api.BeforeEach; @@ -8,6 +11,7 @@ import domain.boards.BoardController; import domain.boards.IngredientBoard; import domain.player.*; +import exception.UserErrorException; public class TestForageForIngredient { @@ -16,15 +20,73 @@ public TestForageForIngredient() { } @BeforeEach - public static void beforeEach() { + public void beforeEach() { TestGameInitializer.initializeTestGame(); } @Test - public static void noActionsLeft() { + public void noActionsLeft() { Player currentPlayer = GameController.getInstance().getCurrentPlayer(); currentPlayer.getPlayerToken().setPlayerAction(0); - assertThrows(null, BoardController.forageForIngredient); + Exception exception = assertThrows(UserErrorException.class, () -> BoardController.forageForIngredient()); + assertEquals(exception.getMessage(), "The user has no more actions left!"); } + + @Test + public void singleSuccess() { + Player currentPlayer = GameController.getInstance().getCurrentPlayer(); + currentPlayer.getPlayerToken().setPlayerAction(3); + int initialSize = currentPlayer.getInventory().getPlayerIngredientCardList().size(); + assertDoesNotThrow(() -> BoardController.forageForIngredient()); + assertEquals(initialSize+1, currentPlayer.getInventory().getPlayerIngredientCardList().size()); + } + + @Test + public void multipleSuccess() { + Player currentPlayer = GameController.getInstance().getCurrentPlayer(); + currentPlayer.getPlayerToken().setPlayerAction(3); + int initialSize = currentPlayer.getInventory().getPlayerIngredientCardList().size(); + assertDoesNotThrow(() -> BoardController.forageForIngredient()); + assertDoesNotThrow(() -> BoardController.forageForIngredient()); + assertDoesNotThrow(() -> BoardController.forageForIngredient()); + assertEquals(initialSize+3, currentPlayer.getInventory().getPlayerIngredientCardList().size()); + } + + @Test + public void singleSuccessNoActionsLeft() { + Player firstPlayer = GameController.getInstance().getCurrentPlayer(); + firstPlayer.getPlayerToken().setPlayerAction(1); + int firstPlayerSize = firstPlayer.getInventory().getPlayerIngredientCardList().size(); + assertDoesNotThrow(() -> BoardController.forageForIngredient()); + //since we had no more actions left, other user must have been switched to + Player secondPlayer = GameController.getInstance().getCurrentPlayer(); + int secondPlayerSize = secondPlayer.getInventory().getPlayerIngredientCardList().size(); + assertDoesNotThrow(() -> BoardController.forageForIngredient()); + assertNotEquals(GameController.getInstance().getCurrentPlayer(), firstPlayer); + assertEquals(GameController.getInstance().getCurrentPlayer(), secondPlayer); + assertNotEquals(secondPlayer, firstPlayer); + + assertEquals(firstPlayerSize+1, firstPlayer.getInventory().getPlayerIngredientCardList().size()); + assertEquals(secondPlayerSize+1, secondPlayer.getInventory().getPlayerIngredientCardList().size()); + } + + @Test + public void allSuccessNoActionsLeft() { + Player firstPlayer = GameController.getInstance().getCurrentPlayer(); + assertEquals(2, firstPlayer.getPlayerToken().getPlayerAction()); + int firstPlayerSize = firstPlayer.getInventory().getPlayerIngredientCardList().size(); + assertDoesNotThrow(() -> BoardController.forageForIngredient()); + assertDoesNotThrow(() -> BoardController.forageForIngredient());//exhaust actions -} + //since we had no more actions left, other user must have been switched to + Player secondPlayer = GameController.getInstance().getCurrentPlayer(); + int secondPlayerSize = secondPlayer.getInventory().getPlayerIngredientCardList().size(); + assertDoesNotThrow(() -> BoardController.forageForIngredient()); + assertNotEquals(GameController.getInstance().getCurrentPlayer(), firstPlayer); + assertEquals(GameController.getInstance().getCurrentPlayer(), secondPlayer); + assertNotEquals(secondPlayer, firstPlayer); + + assertEquals(firstPlayerSize+3, firstPlayer.getInventory().getPlayerIngredientCardList().size()); + assertEquals(secondPlayerSize+1, secondPlayer.getInventory().getPlayerIngredientCardList().size()); + } +} \ No newline at end of file diff --git a/userinfo.json b/userinfo.json index 8c499ac..4ef3214 100644 --- a/userinfo.json +++ b/userinfo.json @@ -1 +1 @@ -[{"password":"a","username":"a"},{"password":"b","username":"b"}] \ No newline at end of file +[{"password":"user_2","username":"user_2"},{"password":"user_1","username":"user_1"}] \ No newline at end of file From 754dd11f2d8a531f752dc4c9fe7e2ea6a45cde59 Mon Sep 17 00:00:00 2001 From: batuogkoc Date: Fri, 29 Dec 2023 09:54:16 +0300 Subject: [PATCH 10/13] fixed the problem with the tests not being fresh --- domain/GameController.java | 5 +++++ test/TestForageForIngredient.java | 3 ++- test/TestGameInitializer.java | 1 + 3 files changed, 8 insertions(+), 1 deletion(-) diff --git a/domain/GameController.java b/domain/GameController.java index d195b08..889e63b 100644 --- a/domain/GameController.java +++ b/domain/GameController.java @@ -36,6 +36,9 @@ public static GameController getInstance() { } return instance; } + public static void clearInstance() { + instance = null; + } //This func initializes the game by calling creating a new instance of initliazegamehelper @@ -52,6 +55,8 @@ public void initializeGame() { } } + + //This func changes rounds public void changeRounds() { diff --git a/test/TestForageForIngredient.java b/test/TestForageForIngredient.java index 72eca47..3e81de4 100644 --- a/test/TestForageForIngredient.java +++ b/test/TestForageForIngredient.java @@ -73,9 +73,10 @@ public void singleSuccessNoActionsLeft() { @Test public void allSuccessNoActionsLeft() { Player firstPlayer = GameController.getInstance().getCurrentPlayer(); - assertEquals(2, firstPlayer.getPlayerToken().getPlayerAction()); + assertEquals(3, firstPlayer.getPlayerToken().getPlayerAction()); int firstPlayerSize = firstPlayer.getInventory().getPlayerIngredientCardList().size(); assertDoesNotThrow(() -> BoardController.forageForIngredient()); + assertDoesNotThrow(() -> BoardController.forageForIngredient()); assertDoesNotThrow(() -> BoardController.forageForIngredient());//exhaust actions //since we had no more actions left, other user must have been switched to diff --git a/test/TestGameInitializer.java b/test/TestGameInitializer.java index cfd8396..b2ba4d5 100644 --- a/test/TestGameInitializer.java +++ b/test/TestGameInitializer.java @@ -10,6 +10,7 @@ public TestGameInitializer() { } public static void initializeTestGame() { + GameController.clearInstance(); LoginSignupController.getInstance().signup("user_1", "user_1"); LoginSignupController.getInstance().signup("user_2", "user_2"); From 7ab0ae724d41c47603b5461e8581d54319cb42fe Mon Sep 17 00:00:00 2001 From: larakucukdevlet <79307181+larakucukdevlet@users.noreply.github.com> Date: Fri, 29 Dec 2023 14:57:03 +0300 Subject: [PATCH 11/13] Update IngredientBoard.java Completed specification of transmuteIngredient method --- domain/boards/IngredientBoard.java | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/domain/boards/IngredientBoard.java b/domain/boards/IngredientBoard.java index fac19c3..a403a47 100644 --- a/domain/boards/IngredientBoard.java +++ b/domain/boards/IngredientBoard.java @@ -66,6 +66,14 @@ public IngredientCard popIngredient() { //Sells 1 ingredient card for 1 gold public void transmuteIngredient(IngredientCard ingredientCard) throws UserErrorException, RuntimeException { + /* Method: transmuteIngredient + * Requires: Ingredient card must be provided to player. Current player should have ingredient card. + * Modifies: Player's inventory. + * Player's token + * Effects: Throws UserErrorException if the player does not own ingredient card + * Transmute 1 ingredient card to a gold. + * Reduces player action by 1. + */ Player player = GameController.getInstance().getCurrentPlayer(); PlayerInventory inv = player.getInventory(); PlayerToken token = player.getPlayerToken(); From 5fca0857a02645a65e4fc3f5acdee7cb0811845c Mon Sep 17 00:00:00 2001 From: larakucukdevlet <79307181+larakucukdevlet@users.noreply.github.com> Date: Fri, 29 Dec 2023 15:02:44 +0300 Subject: [PATCH 12/13] Test class for transmuteIngredient class --- test/TestTransmuteIngredient.java | 57 +++++++++++++++++++++++++++++++ 1 file changed, 57 insertions(+) create mode 100644 test/TestTransmuteIngredient.java diff --git a/test/TestTransmuteIngredient.java b/test/TestTransmuteIngredient.java new file mode 100644 index 0000000..4bbdad5 --- /dev/null +++ b/test/TestTransmuteIngredient.java @@ -0,0 +1,57 @@ +package test; + +/*import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse;*/ + +import domain.GameController; +import domain.boards.BoardController; +import domain.cards.IngredientCard; +import domain.player.Player; +import exception.UserErrorException; + + +public class transmuteIngredientTest { + /*Test Cases: + Black-Box Test: Transmuting Ingredient Card owned by current player + Scenario: Providing an ingredient card owned by the player to transmute. + Expected result: The method successfully transmutes the ingredient card to 1 gold and reduces the player's action count. + + Black-Box Test: Transmuting Non-Owned Ingredient Card + Scenario: Providing an ingredient card not owned by the player to transmute. + Expected result: The method throws a UserErrorException since the ingredient card is not owned by the player. + + Glass-Box Test: Inventory Modification + Scenario: Checking the inventory modification. + Expected result: ingredient card is removed from the player's inventory after transmutation. + + Glass-Box Test: Gold Addition + Scenario: checking the gold addition. + Expected result: The player's gold increased by 1 after transmutation. + + Glass-Box Test: Player Action Reduction + Scenario: Checking the player action reduction. + Expected result: The player's action count decreases by 1 after transmutation.*/ + + //@Test + public void testTransmuteOwnedIngredient() throws UserErrorException { + // Test: Transmuting an owned ingredient card + GameController.getGameInventory().createAtom(); + GameController.getGameInventory().createMolecule(); + GameController.getGameInventory().createIngredientCard(); + + IngredientCard ownedCard=GameController.getGameInventory().getIngrCards().get(0); + + Player currentPlayer = new Player(1, "aa", "bb"); + currentPlayer.getInventory().addAIngredientCard(ownedCard); + currentPlayer.getPlayerToken().setPlayerAction(3); + currentPlayer.getPlayerToken().setGold(5); + BoardController.transmuteIngredient(ownedCard.getName()); + + // Assert + /*assertEquals(4, currentPlayer.getPlayerToken().getPlayerAction()); + assertEquals(6, currentPlayer.getPlayerToken().getGold()); + assertFalse(currentPlayer.getInventory().getPlayerIngredientCardList().contains(ownedCard));*/ + } + + +} From 999afa41e9fff7d6b30a183631e09b802681533c Mon Sep 17 00:00:00 2001 From: larakucukdevlet <79307181+larakucukdevlet@users.noreply.github.com> Date: Tue, 2 Jan 2024 17:59:24 +0300 Subject: [PATCH 13/13] Update IngredientBoard.java --- domain/boards/IngredientBoard.java | 8 -------- 1 file changed, 8 deletions(-) diff --git a/domain/boards/IngredientBoard.java b/domain/boards/IngredientBoard.java index a403a47..fac19c3 100644 --- a/domain/boards/IngredientBoard.java +++ b/domain/boards/IngredientBoard.java @@ -66,14 +66,6 @@ public IngredientCard popIngredient() { //Sells 1 ingredient card for 1 gold public void transmuteIngredient(IngredientCard ingredientCard) throws UserErrorException, RuntimeException { - /* Method: transmuteIngredient - * Requires: Ingredient card must be provided to player. Current player should have ingredient card. - * Modifies: Player's inventory. - * Player's token - * Effects: Throws UserErrorException if the player does not own ingredient card - * Transmute 1 ingredient card to a gold. - * Reduces player action by 1. - */ Player player = GameController.getInstance().getCurrentPlayer(); PlayerInventory inv = player.getInventory(); PlayerToken token = player.getPlayerToken();