diff --git a/CHANGES.md b/CHANGES.md new file mode 100644 index 00000000..ac796719 --- /dev/null +++ b/CHANGES.md @@ -0,0 +1,120 @@ +# Changes in this branch (to be used in maintainability measurement work). + + +## Changes in the ShowSpecificPotionStats branch + +### This branch addresses the following issue: +#### Show Specific Potion Stats, ([issue #58](https://github.com/hhaslam11/Text-Fighter/issues/58) in the source hhaslam11/Text-Fighter repository, [issue #7](https://github.com/emmamickas/Text-Fighter/issues/7) in the forked emmamickas/Text-Fighter repository) + +### Desired modifications: +#### In the current functionality, when a player views their stats, they are only able to view a total number of potions used, but not individual totals for different types of potions that they have used. The changes include separating the totals for individual potion types to display each total, while also keeping a total of all potions used by the player. + +### Modified files: +#### As viewable in the [Dependency References folder](https://github.com/emmamickas/Text-Fighter/tree/ShowSpecificPotionStats/Dependency%20References), the following files were modified in the change: + * [Potion.java](https://github.com/emmamickas/Text-Fighter/blob/ShowSpecificPotionStats/src/com/hotmail/kalebmarc/textfighter/player/Potion.java) + * [Stats.java](https://github.com/emmamickas/Text-Fighter/blob/ShowSpecificPotionStats/src/com/hotmail/kalebmarc/textfighter/player/Stats.java) + +### Testing: +#### The following tests were performed to ensure that behavior was preserved after refactoring/changes: + * [Potion](https://github.com/emmamickas/Text-Fighter/blob/ShowSpecificPotionStats/src/com/hotmail/kalebmarc/textfighter/player/PotionTest.java) + ##### See [here](https://github.com/emmamickas/Text-Fighter/blob/ShowSpecificPotionStats/TESTING.md) for more information on testing. + + ### Resolution: + #### The branch was merged with master, closing issue #58: + [Pull request #125](https://github.com/hhaslam11/Text-Fighter/commit/659955becfa0eb803f4b214821f18dbef9419da8) + + ### Additional resources: + #### Please view the following to find additional documentation of the changes and the code involved in the changes. + * [Class Diagrams](https://github.com/emmamickas/Text-Fighter/tree/ShowSpecificPotionStats/Class%20Diagram) of modified classes. + * [Dependencies](https://github.com/emmamickas/Text-Fighter/tree/ShowSpecificPotionStats/Dependency%20References) of modified or dependent classes. + * [Sequence Diagrams](https://github.com/emmamickas/Text-Fighter/tree/ShowSpecificPotionStats/Sequence%20Diagrams) of modified or dependent methods. + +## Changes in the AddConstantArrayListAccessModifiers branch + +### This branch addresses the following issue: +#### Show Specific Potion Stats, ([issue #46](https://github.com/hhaslam11/Text-Fighter/issues/46) in the source hhaslam11/Text-Fighter repository, [issue #4](https://github.com/emmamickas/Text-Fighter/issues/4) in the forked emmamickas/Text-Fighter repository) + +### Desired modifications: +#### In the current implementation, when accessing an array from a static class including Weapon, Enemy, and Food, the array is accessed directly. The changes include implementing an access modifier to these arrays. + +### Modified files: +#### As viewable in the [Dependency References folder](https://github.com/emmamickas/Text-Fighter/tree/AddConstantArraylistAccessModifiers/Dependency%20References), the following files were modified in the change: + * [Armour.java](https://github.com/emmamickas/Text-Fighter/blob/AddConstantArraylistAccessModifiers/src/com/hotmail/kalebmarc/textfighter/item/Armour.java) + * [Weapon.java](https://github.com/emmamickas/Text-Fighter/blob/AddConstantArraylistAccessModifiers/src/com/hotmail/kalebmarc/textfighter/main/Weapon.java) + * [Enemy.java](https://github.com/emmamickas/Text-Fighter/blob/AddConstantArraylistAccessModifiers/src/com/hotmail/kalebmarc/textfighter/main/Enemy.java) + * [Food.java](https://github.com/emmamickas/Text-Fighter/blob/AddConstantArraylistAccessModifiers/src/com/hotmail/kalebmarc/textfighter/main/Food.java) + +### Testing: +#### The following tests were performed to ensure that behavior was preserved after refactoring/changes: + * [Armour](https://github.com/emmamickas/Text-Fighter/blob/AddConstantArraylistAccessModifiers/src/com/hotmail/kalebmarc/textfighter/item/ArmourTest.java) + * [Weapon](https://github.com/emmamickas/Text-Fighter/blob/AddConstantArraylistAccessModifiers/src/com/hotmail/kalebmarc/textfighter/main/WeaponTest.java) + * [Enemy](https://github.com/emmamickas/Text-Fighter/blob/AddConstantArraylistAccessModifiers/src/com/hotmail/kalebmarc/textfighter/main/EnemyTest.java) + * [Food](https://github.com/emmamickas/Text-Fighter/blob/AddConstantArraylistAccessModifiers/src/com/hotmail/kalebmarc/textfighter/main/FoodTest.java) + * [Cheats](https://github.com/emmamickas/Text-Fighter/blob/AddConstantArraylistAccessModifiers/src/com/hotmail/kalebmarc/textfighter/main/CheatsTest.java) + * [Debug](https://github.com/emmamickas/Text-Fighter/blob/AddConstantArraylistAccessModifiers/src/com/hotmail/kalebmarc/textfighter/main/DebugTest.java) + ##### See [here](https://github.com/emmamickas/Text-Fighter/blob/AddConstantArraylistAccessModifiers/TESTING.md) for more information on testing. + + ### Resolution: + #### The branch was merged with master: + [Pull request #127](https://github.com/hhaslam11/Text-Fighter/commit/555f73191bb4e5476f82c6f481dd3b8190866159) + + ### Additional resources: + #### Please view the following to find additional documentation of the changes and the code involved in the changes. + * [Class Diagrams](https://github.com/emmamickas/Text-Fighter/tree/AddConstantArraylistAccessModifiers/Class%20Diagram) of modified classes. + * [Dependencies](https://github.com/emmamickas/Text-Fighter/tree/AddConstantArraylistAccessModifiers/Dependency%20References) of modified or dependent classes. + * [Sequence Diagrams](https://github.com/emmamickas/Text-Fighter/tree/AddConstantArraylistAccessModifiers/Sequence%20Diagrams) of modified or dependent methods. + +## Changes in the CriticalHits branch + +### This branch addresses the following issue: +#### Critical Hits, ([issue #25](https://github.com/hhaslam11/Text-Fighter/issues/25) in the source hhaslam11/Text-Fighter repository, [issue #1](https://github.com/emmamickas/Text-Fighter/issues/1) in the forked emmamickas/Text-Fighter repository) + +### Desired modifications: +#### In the current functionality, the damage that a weapon can do can be increased by a critical multiplier based upon the weapon's type. The changes include adding another critical modifier that increases the damage done by weapons with bullets only. This modifier has a 0.01% chance to activate and increases damage by a factor of 10. + +### Modified files: +#### As viewable in the [Dependency References folder](https://github.com/emmamickas/Text-Fighter/tree/CriticalHits/Dependency%20References), the following files were modified in the change: + * [Weapon.java](https://github.com/emmamickas/Text-Fighter/blob/CriticalHits/src/com/hotmail/kalebmarc/textfighter/main/Weapon.java) + +### Testing: +#### The following tests were performed to ensure that behavior was preserved after refactoring/changes: + * [Weapon](https://github.com/emmamickas/Text-Fighter/tree/CriticalHits/src/com/hotmail/kalebmarc/textfighter/main) + * [Enemy](https://github.com/emmamickas/Text-Fighter/tree/CriticalHits/src/com/hotmail/kalebmarc/textfighter/main) + ##### See [here](https://github.com/emmamickas/Text-Fighter/blob/CriticalHits/TESTING.md) for more information on testing. + + ### Resolution: + #### Pending + A [pull request](https://github.com/hhaslam11/Text-Fighter/pull/129) has been made to merge the change onto the master branch of the source repo. + + ### Additional resources: + #### Please view the following to find additional documentation of the changes and the code involved in the changes. + * [Class Diagrams](https://github.com/emmamickas/Text-Fighter/tree/CriticalHits/Class%20Diagram) of modified classes. + * [Dependencies](https://github.com/emmamickas/Text-Fighter/tree/CriticalHits/Dependency%20References) of modified or dependent classes. + * [Sequence Diagrams](https://github.com/emmamickas/Text-Fighter/tree/CriticalHits/Sequence%20Diagrams) of modified or dependent methods. + +## Changes in the CheatsIndexOutOfBoundsFix + +### This branch addresses the following issue: +#### Critical Hits, ([issue #130](https://github.com/hhaslam11/Text-Fighter/issues/130) in the source hhaslam11/Text-Fighter repository, [issue #9](https://github.com/emmamickas/Text-Fighter/issues/9) in the forked emmamickas/Text-Fighter repository) + +### Desired modifications: +#### In the current implementation, selecting the weaponstash cheat involves accessing an array of weapons in which the final index being referenced is the size of the array, which is out of the bounds of the array. The changes involve updating the condition of the loop that accesses the array to prevent the violation of the index. + +### Modified files: +#### As viewable in the [Dependency References folder](https://github.com/emmamickas/Text-Fighter/tree/CheatsIndexOutOfBoundsFix/Dependency%20References), the following files were modified in the change: + * [Cheats.java](https://github.com/emmamickas/Text-Fighter/blob/CheatsIndexOutOfBoundsFix/src/com/hotmail/kalebmarc/textfighter/main/Cheats.java) + +### Testing: +#### The following tests were performed to ensure that behavior was preserved after refactoring/changes: + * [Cheats](https://github.com/emmamickas/Text-Fighter/blob/AddConstantArraylistAccessModifiers/src/com/hotmail/kalebmarc/textfighter/main/CheatsTest.java) + ##### See [here](https://github.com/emmamickas/Text-Fighter/blob/CheatsIndexOutOfBoundsFix/TESTING.md) for more information on testing. + + ### Resolution: + #### Pending + A [pull request](https://github.com/hhaslam11/Text-Fighter/pull/131) has been made to merge the change onto the master branch of the source repo. + + ### Additional resources: + #### Please view the following to find additional documentation of the changes and the code involved in the changes. + * [Class Diagrams](https://github.com/emmamickas/Text-Fighter/tree/CheatsIndexOutOfBoundsFix/Class%20Diagram) of modified classes. + * [Dependencies](https://github.com/emmamickas/Text-Fighter/tree/CheatsIndexOutOfBoundsFix/Dependency%20References) of modified or dependent classes. + * [Sequence Diagrams](https://github.com/emmamickas/Text-Fighter/tree/CheatsIndexOutOfBoundsFix/Sequence%20Diagrams) of modified or dependent methods. diff --git a/Class Diagram/Packagecasinodiagram.png b/Class Diagram/Packagecasinodiagram.png new file mode 100644 index 00000000..42b85805 Binary files /dev/null and b/Class Diagram/Packagecasinodiagram.png differ diff --git a/Class Diagram/Packageitemdiagram.png b/Class Diagram/Packageitemdiagram.png new file mode 100644 index 00000000..acbc4ce6 Binary files /dev/null and b/Class Diagram/Packageitemdiagram.png differ diff --git a/Class Diagram/PackageitemdiagramAfterchange.png b/Class Diagram/PackageitemdiagramAfterchange.png new file mode 100644 index 00000000..4c2400c7 Binary files /dev/null and b/Class Diagram/PackageitemdiagramAfterchange.png differ diff --git a/Class Diagram/PackageitemdiagramBeforechange.png b/Class Diagram/PackageitemdiagramBeforechange.png new file mode 100644 index 00000000..acbc4ce6 Binary files /dev/null and b/Class Diagram/PackageitemdiagramBeforechange.png differ diff --git a/Class Diagram/Packagemaindiagram.png b/Class Diagram/Packagemaindiagram.png new file mode 100644 index 00000000..5c0c9d27 Binary files /dev/null and b/Class Diagram/Packagemaindiagram.png differ diff --git a/Class Diagram/PackagemaindiagramAfterchange.png b/Class Diagram/PackagemaindiagramAfterchange.png new file mode 100644 index 00000000..6ef4fc9b Binary files /dev/null and b/Class Diagram/PackagemaindiagramAfterchange.png differ diff --git a/Class Diagram/PackagemaindiagramBeforechange.png b/Class Diagram/PackagemaindiagramBeforechange.png new file mode 100644 index 00000000..5c0c9d27 Binary files /dev/null and b/Class Diagram/PackagemaindiagramBeforechange.png differ diff --git a/Class Diagram/Packageplayerdiagram.png b/Class Diagram/Packageplayerdiagram.png new file mode 100644 index 00000000..25d293bd Binary files /dev/null and b/Class Diagram/Packageplayerdiagram.png differ diff --git a/Class Diagram/Sourcestructurediagram.png b/Class Diagram/Sourcestructurediagram.png new file mode 100644 index 00000000..bd479971 Binary files /dev/null and b/Class Diagram/Sourcestructurediagram.png differ diff --git a/Dependency References/ArmourDependencies.png b/Dependency References/ArmourDependencies.png new file mode 100644 index 00000000..9a476be6 Binary files /dev/null and b/Dependency References/ArmourDependencies.png differ diff --git a/Dependency References/CheatsWeaponDependencies.png b/Dependency References/CheatsWeaponDependencies.png new file mode 100644 index 00000000..cb124738 Binary files /dev/null and b/Dependency References/CheatsWeaponDependencies.png differ diff --git a/Dependency References/EnemyDependencies.png b/Dependency References/EnemyDependencies.png new file mode 100644 index 00000000..1a77f3b9 Binary files /dev/null and b/Dependency References/EnemyDependencies.png differ diff --git a/Dependency References/FoodDependencies.png b/Dependency References/FoodDependencies.png new file mode 100644 index 00000000..041051b9 Binary files /dev/null and b/Dependency References/FoodDependencies.png differ diff --git a/Dependency References/PotionStatsDependencies.png b/Dependency References/PotionStatsDependencies.png new file mode 100644 index 00000000..959b07c3 Binary files /dev/null and b/Dependency References/PotionStatsDependencies.png differ diff --git a/Dependency References/Usage Slicing/ArrayArmoursUsage1.png b/Dependency References/Usage Slicing/ArrayArmoursUsage1.png new file mode 100644 index 00000000..70d42d94 Binary files /dev/null and b/Dependency References/Usage Slicing/ArrayArmoursUsage1.png differ diff --git a/Dependency References/Usage Slicing/ArrayEnemyUsage1.png b/Dependency References/Usage Slicing/ArrayEnemyUsage1.png new file mode 100644 index 00000000..16dcb76a Binary files /dev/null and b/Dependency References/Usage Slicing/ArrayEnemyUsage1.png differ diff --git a/Dependency References/Usage Slicing/ArrayFoodUsage1.png b/Dependency References/Usage Slicing/ArrayFoodUsage1.png new file mode 100644 index 00000000..7f1a08db Binary files /dev/null and b/Dependency References/Usage Slicing/ArrayFoodUsage1.png differ diff --git a/Dependency References/Usage Slicing/ArrayFoodUsage2.png b/Dependency References/Usage Slicing/ArrayFoodUsage2.png new file mode 100644 index 00000000..b0443a40 Binary files /dev/null and b/Dependency References/Usage Slicing/ArrayFoodUsage2.png differ diff --git a/Dependency References/Usage Slicing/ArrayFoodUsage3.png b/Dependency References/Usage Slicing/ArrayFoodUsage3.png new file mode 100644 index 00000000..fcb09b04 Binary files /dev/null and b/Dependency References/Usage Slicing/ArrayFoodUsage3.png differ diff --git a/Dependency References/Usage Slicing/ArrayWeaponUsage1.png b/Dependency References/Usage Slicing/ArrayWeaponUsage1.png new file mode 100644 index 00000000..39c4a1da Binary files /dev/null and b/Dependency References/Usage Slicing/ArrayWeaponUsage1.png differ diff --git a/Dependency References/Usage Slicing/ArrayWeaponUsage2.png b/Dependency References/Usage Slicing/ArrayWeaponUsage2.png new file mode 100644 index 00000000..5ce0db68 Binary files /dev/null and b/Dependency References/Usage Slicing/ArrayWeaponUsage2.png differ diff --git a/Dependency References/Usage Slicing/ArrayWeaponUsage3.png b/Dependency References/Usage Slicing/ArrayWeaponUsage3.png new file mode 100644 index 00000000..68812b3b Binary files /dev/null and b/Dependency References/Usage Slicing/ArrayWeaponUsage3.png differ diff --git a/Dependency References/Usage Slicing/Cheat-CheatSelect-ArrayWeapon_Usage1.png b/Dependency References/Usage Slicing/Cheat-CheatSelect-ArrayWeapon_Usage1.png new file mode 100644 index 00000000..bb41a821 Binary files /dev/null and b/Dependency References/Usage Slicing/Cheat-CheatSelect-ArrayWeapon_Usage1.png differ diff --git a/Dependency References/Usage Slicing/GetArmoursUsage1.png b/Dependency References/Usage Slicing/GetArmoursUsage1.png new file mode 100644 index 00000000..7fa0b957 Binary files /dev/null and b/Dependency References/Usage Slicing/GetArmoursUsage1.png differ diff --git a/Dependency References/Usage Slicing/Potion-used_Usage1.png b/Dependency References/Usage Slicing/Potion-used_Usage1.png new file mode 100644 index 00000000..1f766506 Binary files /dev/null and b/Dependency References/Usage Slicing/Potion-used_Usage1.png differ diff --git a/Dependency References/Usage Slicing/RecoveryPotionsUsed_Usage1.png b/Dependency References/Usage Slicing/RecoveryPotionsUsed_Usage1.png new file mode 100644 index 00000000..a422dfcd Binary files /dev/null and b/Dependency References/Usage Slicing/RecoveryPotionsUsed_Usage1.png differ diff --git a/Dependency References/Usage Slicing/SurvivalPotionsUsed_Usage1.png b/Dependency References/Usage Slicing/SurvivalPotionsUsed_Usage1.png new file mode 100644 index 00000000..fb10a986 Binary files /dev/null and b/Dependency References/Usage Slicing/SurvivalPotionsUsed_Usage1.png differ diff --git a/Dependency References/WeaponDependencies.png b/Dependency References/WeaponDependencies.png new file mode 100644 index 00000000..9a7b2bff Binary files /dev/null and b/Dependency References/WeaponDependencies.png differ diff --git a/Sequence Diagrams/Armour_choose_sequenceDiagram.png b/Sequence Diagrams/Armour_choose_sequenceDiagram.png new file mode 100644 index 00000000..0ca9d815 Binary files /dev/null and b/Sequence Diagrams/Armour_choose_sequenceDiagram.png differ diff --git a/Sequence Diagrams/Cheat_select_sequenceDiagram.png b/Sequence Diagrams/Cheat_select_sequenceDiagram.png new file mode 100644 index 00000000..1f2c4ccf Binary files /dev/null and b/Sequence Diagrams/Cheat_select_sequenceDiagram.png differ diff --git a/Sequence Diagrams/Debug_menu_sequenceDiagram.png b/Sequence Diagrams/Debug_menu_sequenceDiagram.png new file mode 100644 index 00000000..321ea517 Binary files /dev/null and b/Sequence Diagrams/Debug_menu_sequenceDiagram.png differ diff --git a/Sequence Diagrams/Enemy_findEnemy_sequenceDiagram.png b/Sequence Diagrams/Enemy_findEnemy_sequenceDiagram.png new file mode 100644 index 00000000..0e09b451 Binary files /dev/null and b/Sequence Diagrams/Enemy_findEnemy_sequenceDiagram.png differ diff --git a/Sequence Diagrams/Food_list_sequenceDiagram.png b/Sequence Diagrams/Food_list_sequenceDiagram.png new file mode 100644 index 00000000..ccc9770e Binary files /dev/null and b/Sequence Diagrams/Food_list_sequenceDiagram.png differ diff --git a/Sequence Diagrams/Potion_use_sequenceDiagram.png b/Sequence Diagrams/Potion_use_sequenceDiagram.png new file mode 100644 index 00000000..b6314f51 Binary files /dev/null and b/Sequence Diagrams/Potion_use_sequenceDiagram.png differ diff --git a/Sequence Diagrams/Stats_view_sequenceDiagram.png b/Sequence Diagrams/Stats_view_sequenceDiagram.png new file mode 100644 index 00000000..1a00e6a3 Binary files /dev/null and b/Sequence Diagrams/Stats_view_sequenceDiagram.png differ diff --git a/Sequence Diagrams/Weapon_choose_sequenceDiagram.png b/Sequence Diagrams/Weapon_choose_sequenceDiagram.png new file mode 100644 index 00000000..3038d291 Binary files /dev/null and b/Sequence Diagrams/Weapon_choose_sequenceDiagram.png differ diff --git a/TESTING.md b/TESTING.md new file mode 100644 index 00000000..31025ef1 --- /dev/null +++ b/TESTING.md @@ -0,0 +1,57 @@ +# Testing cheat functionality: +## The following tests were performed to ensure that behavior was preserved after refactoring/changes: + ### [Cheats](https://github.com/emmamickas/Text-Fighter/blob/CheatsIndexOutOfBoundsFix/src/com/hotmail/kalebmarc/textfighter/main/CheatsTest.java) Tests including testing of the methods: + * cheatGateway() + ** This method is tested for the 'givemeitall' cheat, the 'weaponstash' cheat, and the 'thirstforfood' cheat. + +## Additional Notes on Testing: +### N/A +### All tests may be run as normal through JUnit + +# Testing array access modifier functionality: +## The following tests were performed to ensure that behavior was preserved after refactoring/changes: + ### [Armour Tests](https://github.com/emmamickas/Text-Fighter/blob/AddConstantArraylistAccessModifiers/src/com/hotmail/kalebmarc/textfighter/item/ArmourTest.java) including testing of the methods: + * choose() + * getArmours() + ### [Weapon Tests](https://github.com/emmamickas/Text-Fighter/blob/AddConstantArraylistAccessModifiers/src/com/hotmail/kalebmarc/textfighter/main/WeaponTest.java) including testing of the methods: + * set(int i) + * choose() + * getWeapons() + ### [Enemy Tests](https://github.com/emmamickas/Text-Fighter/blob/AddConstantArraylistAccessModifiers/src/com/hotmail/kalebmarc/textfighter/main/EnemyTest.java) including testing of the methods: + * set(int i) + * get() + * getIndex(Enemy i) + * findEnemy() + * getEnemies() + ### [Food Tests](https://github.com/emmamickas/Text-Fighter/blob/AddConstantArraylistAccessModifiers/src/com/hotmail/kalebmarc/textfighter/main/FoodTest.java) including testing of the methods: + * choose() + * getFoods() + ### [Cheats Tests](https://github.com/emmamickas/Text-Fighter/blob/AddConstantArraylistAccessModifiers/src/com/hotmail/kalebmarc/textfighter/main/CheatsTest.java) including testing of the methods: + * cheatGateway() +** This method is tested for the 'givemeitall' cheat, the 'weaponstash' cheat, and the 'thirstforfood' cheat. + ### [Debug Tests](https://github.com/emmamickas/Text-Fighter/blob/AddConstantArraylistAccessModifiers/src/com/hotmail/kalebmarc/textfighter/main/DebugTest.java) including testing of the methods: + * menu() +** This method is tested for weapon and food debugging + +## Additional Notes on Testing:Testing constant array access modifier functionality: +### The testing of the Armour, Weapon, Food, Enemy, Debug, and Cheat class require UI interaction. +### As such, each test requiring UI interaction including: +* ArmourTest: testChooseOnly, testChooseFirst, testChooseMiddle, testChooseLast +* CheatsTest: testCheatGatewaygivemeitall, testCheatGatewayweaponstash, testCheatGatewaythirstforfood +* DebugTest: testMenuWeapon, testMenuFood +* FoodTest: testListChooseFirst, testListChooseMiddle, testListChooseLast +* WeaponTest: testChooseFirst, testChooseMiddle, testChooseLast +### Must be run individually rather than running all tests in the class at once. + +# Testing potion functionality: +## The following tests were performed to ensure that behavior was preserved after refactoring/changes: + ### [Potion](https://github.com/emmamickas/Text-Fighter/blob/ShowSpecificPotionStats/src/com/hotmail/kalebmarc/textfighter/player/PotionTest.java) Tests including testing of the methods: + * get(String kind) + * set(String kind, int amount, boolean add) + * use(String k) + * used(String kind) + +## Additional Notes on Testing: +### The potion tests are built to work when run all at once or separately except for the testUsed() test case. +### This test case keeps track of all previous actions of the class, and thus will be accurate when only when run with the other tests. +### If you wish to perform only the unit test for the used function, you may reenable the testUsedAlone test and run all tests, or only the testUsedAlone test. diff --git a/src/com/hotmail/kalebmarc/textfighter/item/ArmourTest.java b/src/com/hotmail/kalebmarc/textfighter/item/ArmourTest.java new file mode 100644 index 00000000..5cf1a839 --- /dev/null +++ b/src/com/hotmail/kalebmarc/textfighter/item/ArmourTest.java @@ -0,0 +1,196 @@ +package com.hotmail.kalebmarc.textfighter.item; + +import static org.junit.Assert.*; +import java.io.ByteArrayInputStream; +import java.io.IOException; +import java.io.InputStream; + +import java.io.InputStream; +import java.io.PrintStream; +import java.io.PrintWriter; +import java.io.StringWriter; +import java.util.ArrayList; +import java.util.Scanner; + +import org.junit.After; +import org.junit.AfterClass; +import org.junit.Before; +import org.junit.BeforeClass; +import org.junit.Rule; +import org.junit.Test; + +public class ArmourTest { + + static Armour none; + + static Armour basic; + + static Armour advanced; + + static InputStream sysInBackup; + + static ByteArrayInputStream in; + + @BeforeClass + public static void setUpBeforeClass() throws Exception { + + sysInBackup = System.in; + + none = new Armour("None", 0, 0, 1); + basic = new Armour("Basic", 400, 15, 5); + advanced = new Armour("Advanced", 750, 30, 7); + + none.setOwns(true); + + basic.setOwns(false); + + advanced.setOwns(false); + + Armour.set(0); + } + + @AfterClass + public static void tearDownAfterClass() throws Exception { + + System.setIn(sysInBackup); + } + + @Before + public void setUp() throws Exception { + + System.setIn(sysInBackup); + + none.setOwns(true); + + basic.setOwns(false); + + advanced.setOwns(false); + + Armour.set(0); + } + + @After + public void tearDown() throws Exception { + + System.setIn(sysInBackup); + } + + @Test + public void testChooseOnly() { + // Select armour when only one type is owned + + // Check that no armour is equipped yet + assertEquals(0, Armour.get()); + + ByteArrayInputStream chooseIn = new ByteArrayInputStream("1".getBytes()); // Set input stream to pick armour automatically + + System.setIn(chooseIn); + + Armour.choose(); // Pick armour to equip + + System.setIn(sysInBackup); + + assertEquals(0, Armour.get()); // Check that correct armour was equipped + + assertEquals(none, Armour.getEquipped()); // Check for correct armour object equipped + } + + @Test + public void testChooseFirst() { + // Select armour when only all three types are owned + + none.setOwns(true); + + basic.setOwns(true); + + advanced.setOwns(true); + + // Check that no armour is equipped yet + assertEquals(0, Armour.get()); + + ByteArrayInputStream chooseIn = new ByteArrayInputStream("1".getBytes()); // Set input stream to pick armour automatically + + System.setIn(chooseIn); + + Armour.choose(); // Pick armour to equip + + System.setIn(sysInBackup); + + assertEquals(0, Armour.get()); // Check that correct armour was equipped + + assertEquals(none, Armour.getEquipped()); // Check for correct armour object equipped + } + + @Test + public void testChooseMiddle() { + + none.setOwns(true); + + basic.setOwns(true); + + advanced.setOwns(true); + + // Check that no armour is equipped yet + assertEquals(0, Armour.get()); + + ByteArrayInputStream chooseIn = new ByteArrayInputStream("2".getBytes()); // Set input stream to pick armour automatically + + System.setIn(chooseIn); + + Armour.choose(); // Pick armour to equip + + System.setIn(sysInBackup); + + assertEquals(1, Armour.get()); // Check that correct armour was equipped + + assertEquals(basic, Armour.getEquipped()); // Check for correct armour object equipped + } + + @Test + public void testChooseLast() { + + none.setOwns(true); + + basic.setOwns(true); + + advanced.setOwns(true); + + // Check that no armour is equipped yet + assertEquals(0, Armour.get()); + + ByteArrayInputStream chooseIn = new ByteArrayInputStream("3".getBytes()); // Set input stream to pick armour automatically + + System.setIn(chooseIn); + + Armour.choose(); // Pick armour to equip + + System.setIn(sysInBackup); + + assertEquals(2, Armour.get()); // Check that correct armour was equipped + + assertEquals(advanced, Armour.getEquipped()); // Check for correct armour object equipped + } + + @Test + public void testGetArmours() { + // Test constant armours array access + + assertEquals(3, Armour.getArmours().size()); + + // Check all objects are the same in each list access method + assertEquals("None", Armour.getArmours().get(0).getName()); + assertEquals(0, Armour.getArmours().get(0).getPrice()); + assertEquals(0, Armour.getArmours().get(0).getDamResist()); + assertEquals(1, Armour.getArmours().get(0).getLevel()); + + assertEquals( "Basic", Armour.getArmours().get(1).getName()); + assertEquals(400, Armour.getArmours().get(1).getPrice()); + assertEquals(15, Armour.getArmours().get(1).getDamResist()); + assertEquals(5, Armour.getArmours().get(1).getLevel()); + + assertEquals("Advanced", Armour.getArmours().get(2).getName()); + assertEquals(750, Armour.getArmours().get(2).getPrice()); + assertEquals(30, Armour.getArmours().get(2).getDamResist()); + assertEquals(7, Armour.getArmours().get(2).getLevel()); + } +} diff --git a/src/com/hotmail/kalebmarc/textfighter/main/Cheats.java b/src/com/hotmail/kalebmarc/textfighter/main/Cheats.java index 5af1425c..44bc108d 100644 --- a/src/com/hotmail/kalebmarc/textfighter/main/Cheats.java +++ b/src/com/hotmail/kalebmarc/textfighter/main/Cheats.java @@ -58,8 +58,8 @@ private static void cheatSelect() { Potion.set("Recovery", 5000, false); break; case "weaponstash": - for (int i = 0; i <= Weapon.getWeapons().size(); i++) { - Weapon.getWeapons().get(i).setAmmo(5000, false); + for (int i = 0; i < Weapon.arrayWeapon.size(); i++) { + Weapon.arrayWeapon.get(i).setAmmo(5000, false); } Power.set(5000, false); diff --git a/src/com/hotmail/kalebmarc/textfighter/main/CheatsTest.java b/src/com/hotmail/kalebmarc/textfighter/main/CheatsTest.java new file mode 100644 index 00000000..593267f3 --- /dev/null +++ b/src/com/hotmail/kalebmarc/textfighter/main/CheatsTest.java @@ -0,0 +1,156 @@ +package com.hotmail.kalebmarc.textfighter.main; + +import static org.junit.Assert.*; + +import java.io.ByteArrayInputStream; +import java.io.InputStream; + +import org.junit.After; +import org.junit.AfterClass; +import org.junit.Before; +import org.junit.BeforeClass; +import org.junit.Test; + +public class CheatsTest { + + static InputStream sysInBackup; + + public static Food apple; + public static Food orange; + public static Food dragonfruit; + public static Food meat; + public static Food mushroom; + public static Food fish; + + static Weapon fists; + static Weapon baseballBat; + static Weapon knife; + static Weapon pipe; + //Guns: + static Weapon pistol; + static Weapon smg; + static Weapon shotgun; + static Weapon rifle; + static Weapon sniper; + + @BeforeClass + public static void setUpBeforeClass() throws Exception { + Cheats.enable(); + + sysInBackup = System.in; // backup System.in to restore it later + + apple = new Food("Apple", "A boring 'ol apple.", StatusEffect.type.HEALTH, Food.type.FRUIT, 5); + orange = new Food("Orange", "Sort of like an apple, but orange.", StatusEffect.type.HEALTH, Food.type.FRUIT, 5); + dragonfruit = new Food("Dragon Fruit", "Unfortunately, not a real dragon.", StatusEffect.type.HEALTH, Food.type.FRUIT, 10); + meat = new Food("Chunk of meat", "Probably not rotten.", StatusEffect.type.HEALTH, Food.type.MEAT_OTHER, 15); + mushroom = new Food("Mushroom", "The good kind!", StatusEffect.type.HEALTH, Food.type.OTHER, 5); + fish = new Food("Fish", "Found in rivers and lakes.", StatusEffect.type.HEALTH, Food.type.MEAT_FISH, 15); + + fists = new Weapon("Fists", true, false, 0, 0, 5, 10, true, false); + baseballBat = new Weapon("Baseball Bat", false, true, 120, 1, 10, 15, true, false); + knife = new Weapon("Knife", false, true, 125, 2, 10, 20, true, false); + pipe = new Weapon("Pipe", false, false, 0, 0, 5, 20, true, false); + //Guns: + pistol = new Weapon("Pistol", 1, 18, true, 250, 1, 4, 15, 1.5, 3, 4, true, false); + smg = new Weapon("Smg", 10, 75, true, 700, 1, 10, 75, 2.5, 4, 6, true, false); + shotgun = new Weapon("Shotgun", 1, 12, true, 375, 2, 9, 60, 2, 5, 7, true, false); + rifle = new Weapon("Rifle", 1, 18, true, 275, 1, 5, 10, 1.25, 6, 7, true, false); + sniper = new Weapon("Sniper", 1, 10, true, 700, 2, 7, 0, 1, 7, 10, true, false); + + Weapon.arrayWeapon.get(1).owns = true; + Weapon.arrayWeapon.get(4).owns = true; + } + + @AfterClass + public static void tearDownAfterClass() throws Exception { + + System.setIn(sysInBackup); + } + + @Before + public void setUp() throws Exception { + + System.setIn(sysInBackup); + } + + @After + public void tearDown() throws Exception { + + System.setIn(sysInBackup); + } + + @Test + public void testCheatGatewaygivemeitall() { + + Ui.print("Type 'givemeitall' to test"); + + ByteArrayInputStream chooseIn = new ByteArrayInputStream("givemeitall".getBytes()); // Set input stream to pick cheat automatically + + System.setIn(chooseIn); + + Cheats.cheatGateway(); + + System.setIn(sysInBackup); + + // Ensure that cheat updated food counts + assertEquals(5000, Food.arrayFood.get(0).getQuantity()); + assertEquals(5000, Food.arrayFood.get(1).getQuantity()); + assertEquals(5000, Food.arrayFood.get(2).getQuantity()); + assertEquals(5000, Food.arrayFood.get(3).getQuantity()); + assertEquals(5000, Food.arrayFood.get(4).getQuantity()); + assertEquals(5000, Food.arrayFood.get(5).getQuantity()); + + // Ensure that cheat updated weapon counts + assertTrue(Weapon.arrayWeapon.get(0).owns); + assertTrue(Weapon.arrayWeapon.get(1).owns); + assertTrue(Weapon.arrayWeapon.get(2).owns); + assertTrue(Weapon.arrayWeapon.get(3).owns); + assertTrue(Weapon.arrayWeapon.get(4).owns); + assertTrue(Weapon.arrayWeapon.get(5).owns); + assertTrue(Weapon.arrayWeapon.get(6).owns); + assertTrue(Weapon.arrayWeapon.get(7).owns); + assertTrue(Weapon.arrayWeapon.get(8).owns); + } + + @Test + public void testCheatGatewayweaponstash() { + + Ui.print("Type 'weaponstash' to test"); + + ByteArrayInputStream chooseIn = new ByteArrayInputStream("weaponstash".getBytes()); // Set input stream to pick cheat automatically + + System.setIn(chooseIn); + + Cheats.cheatGateway(); + + System.setIn(sysInBackup); + + // Ensure that cheat updated weapon ammo counts + assertEquals(5000, Weapon.arrayWeapon.get(4).getAmmo()); + assertEquals(5000, Weapon.arrayWeapon.get(5).getAmmo()); + assertEquals(5000, Weapon.arrayWeapon.get(6).getAmmo()); + assertEquals(5000, Weapon.arrayWeapon.get(7).getAmmo()); + assertEquals(5000, Weapon.arrayWeapon.get(8).getAmmo()); + } + + @Test + public void testCheatGatewaythirstforfood() { + + Ui.print("Type 'thirstforfood' to test"); + + ByteArrayInputStream chooseIn = new ByteArrayInputStream("thirstforfood".getBytes()); // Set input stream to pick cheat automatically + + System.setIn(chooseIn); + + Cheats.cheatGateway(); + + System.setIn(sysInBackup); + + // Ensure that cheat updated food counts + assertEquals(10, Food.arrayFood.get(0).getQuantity()); + assertEquals(10, Food.arrayFood.get(1).getQuantity()); + assertEquals(10, Food.arrayFood.get(2).getQuantity()); + assertEquals(10, Food.arrayFood.get(3).getQuantity()); + assertEquals(10, Food.arrayFood.get(4).getQuantity()); + assertEquals(10, Food.arrayFood.get(5).getQuantity()); + } diff --git a/src/com/hotmail/kalebmarc/textfighter/main/DebugTest.java b/src/com/hotmail/kalebmarc/textfighter/main/DebugTest.java new file mode 100644 index 00000000..ee5307ed --- /dev/null +++ b/src/com/hotmail/kalebmarc/textfighter/main/DebugTest.java @@ -0,0 +1,160 @@ +package com.hotmail.kalebmarc.textfighter.main; + +import static org.junit.Assert.*; + +import java.io.ByteArrayInputStream; +import java.io.InputStream; + +import org.junit.After; +import org.junit.AfterClass; +import org.junit.Before; +import org.junit.BeforeClass; +import org.junit.Test; + +public class DebugTest { + + static InputStream sysInBackup; + + public static Food apple; + public static Food orange; + public static Food dragonfruit; + public static Food meat; + public static Food mushroom; + public static Food fish; + + static Weapon fists; + static Weapon baseballBat; + static Weapon knife; + static Weapon pipe; + //Guns: + static Weapon pistol; + static Weapon smg; + static Weapon shotgun; + static Weapon rifle; + static Weapon sniper; + + @BeforeClass + public static void setUpBeforeClass() throws Exception { + + Debug.enable(); + + sysInBackup = System.in; // backup System.in to restore it later + + apple = new Food("Apple", "A boring 'ol apple.", StatusEffect.type.HEALTH, Food.type.FRUIT, 5); + orange = new Food("Orange", "Sort of like an apple, but orange.", StatusEffect.type.HEALTH, Food.type.FRUIT, 5); + dragonfruit = new Food("Dragon Fruit", "Unfortunately, not a real dragon.", StatusEffect.type.HEALTH, Food.type.FRUIT, 10); + meat = new Food("Chunk of meat", "Probably not rotten.", StatusEffect.type.HEALTH, Food.type.MEAT_OTHER, 15); + mushroom = new Food("Mushroom", "The good kind!", StatusEffect.type.HEALTH, Food.type.OTHER, 5); + fish = new Food("Fish", "Found in rivers and lakes.", StatusEffect.type.HEALTH, Food.type.MEAT_FISH, 15); + + fists = new Weapon("Fists", true, false, 0, 0, 5, 10, true, false); + baseballBat = new Weapon("Baseball Bat", false, true, 120, 1, 10, 15, true, false); + knife = new Weapon("Knife", false, true, 125, 2, 10, 20, true, false); + pipe = new Weapon("Pipe", false, false, 0, 0, 5, 20, true, false); + //Guns: + pistol = new Weapon("Pistol", 1, 18, true, 250, 1, 4, 15, 1.5, 3, 4, true, false); + smg = new Weapon("Smg", 10, 75, true, 700, 1, 10, 75, 2.5, 4, 6, true, false); + shotgun = new Weapon("Shotgun", 1, 12, true, 375, 2, 9, 60, 2, 5, 7, true, false); + rifle = new Weapon("Rifle", 1, 18, true, 275, 1, 5, 10, 1.25, 6, 7, true, false); + sniper = new Weapon("Sniper", 1, 10, true, 700, 2, 7, 0, 1, 7, 10, true, false); + + Weapon.arrayWeapon.get(1).owns = true; + Weapon.arrayWeapon.get(4).owns = true; + } + + @AfterClass + public static void tearDownAfterClass() throws Exception { + + System.setIn(sysInBackup); + } + + @Before + public void setUp() throws Exception { + + System.setIn(sysInBackup); + } + + @After + public void tearDown() throws Exception { + + System.setIn(sysInBackup); + } + + @Test + public void testMenuWeapon() { + + Ui.print("Enter '3' followed by '9' to test"); + + ByteArrayInputStream chooseIn = new ByteArrayInputStream("3".getBytes()); // Set input stream to pick cheat automatically + + System.setIn(chooseIn); + + Debug.menu(); + + System.setIn(sysInBackup); + + // Ensure that debug updated weapon counts + assertTrue(Weapon.arrayWeapon.get(0).owns); + assertTrue(Weapon.arrayWeapon.get(1).owns); + assertTrue(Weapon.arrayWeapon.get(2).owns); + assertTrue(Weapon.arrayWeapon.get(3).owns); + assertTrue(Weapon.arrayWeapon.get(4).owns); + assertTrue(Weapon.arrayWeapon.get(5).owns); + assertTrue(Weapon.arrayWeapon.get(6).owns); + assertTrue(Weapon.arrayWeapon.get(7).owns); + assertTrue(Weapon.arrayWeapon.get(8).owns); + + assertTrue(Weapon.getWeapons().get(0).owns); + assertTrue(Weapon.getWeapons().get(1).owns); + assertTrue(Weapon.getWeapons().get(2).owns); + assertTrue(Weapon.getWeapons().get(3).owns); + assertTrue(Weapon.getWeapons().get(4).owns); + assertTrue(Weapon.getWeapons().get(5).owns); + assertTrue(Weapon.getWeapons().get(6).owns); + assertTrue(Weapon.getWeapons().get(7).owns); + assertTrue(Weapon.getWeapons().get(8).owns); + + // Ensure that debug updated weapon ammo counts + assertEquals(10000, Weapon.arrayWeapon.get(4).getAmmo()); + assertEquals(10000, Weapon.arrayWeapon.get(5).getAmmo()); + assertEquals(10000, Weapon.arrayWeapon.get(6).getAmmo()); + assertEquals(10000, Weapon.arrayWeapon.get(7).getAmmo()); + assertEquals(10000, Weapon.arrayWeapon.get(8).getAmmo()); + + assertEquals(10000, Weapon.getWeapons().get(4).getAmmo()); + assertEquals(10000, Weapon.getWeapons().get(5).getAmmo()); + assertEquals(10000, Weapon.getWeapons().get(6).getAmmo()); + assertEquals(10000, Weapon.getWeapons().get(7).getAmmo()); + assertEquals(10000, Weapon.getWeapons().get(8).getAmmo()); + } + + @Test + public void testMenuFood() { + + Ui.print("Enter '8' followed by the numbers '0' through '5' five times, then finally '9' to test"); + + ByteArrayInputStream chooseIn = new ByteArrayInputStream("8".getBytes()); // Set input stream to pick cheat automatically + + System.setIn(chooseIn); + + Debug.menu(); + + System.setIn(sysInBackup); + + // Ensure that cheat updated food counts + assertEquals(10, Food.arrayFood.get(0).getQuantity()); + assertEquals(10, Food.arrayFood.get(1).getQuantity()); + assertEquals(10, Food.arrayFood.get(2).getQuantity()); + assertEquals(10, Food.arrayFood.get(3).getQuantity()); + assertEquals(10, Food.arrayFood.get(4).getQuantity()); + assertEquals(10, Food.arrayFood.get(5).getQuantity()); + + assertEquals(10, Food.getFoods().get(0).getQuantity()); + assertEquals(10, Food.getFoods().get(1).getQuantity()); + assertEquals(10, Food.getFoods().get(2).getQuantity()); + assertEquals(10, Food.getFoods().get(3).getQuantity()); + assertEquals(10, Food.getFoods().get(4).getQuantity()); + assertEquals(10, Food.getFoods().get(5).getQuantity()); + } + +} diff --git a/src/com/hotmail/kalebmarc/textfighter/main/EnemyTest.java b/src/com/hotmail/kalebmarc/textfighter/main/EnemyTest.java new file mode 100644 index 00000000..b2f0c771 --- /dev/null +++ b/src/com/hotmail/kalebmarc/textfighter/main/EnemyTest.java @@ -0,0 +1,248 @@ +package com.hotmail.kalebmarc.textfighter.main; + +import static org.junit.Assert.*; + +import java.util.ArrayList; +import java.util.Set; + +import org.junit.After; +import org.junit.AfterClass; +import org.junit.Before; +import org.junit.BeforeClass; +import org.junit.Test; + +import com.hotmail.kalebmarc.textfighter.player.Xp; + +public class EnemyTest { + + public static Enemy darkElf; + public static Enemy ninja; + public static Enemy giantSpider; + public static Enemy zombie; + public static Enemy goblin; + public static Enemy ghost; + public static Enemy barbarian; + public static Enemy giantAnt; + public static Enemy evilUnicorn; + public static Enemy ogre; + + static ArrayList allEnemies; + + @BeforeClass + public static void setUpBeforeClass() throws Exception { + darkElf = new Enemy("Dark Elf", 45, 10, 15, 10, 15, 15, 5, 99, true, false); + ninja = new Enemy("Ninja", 75, 5, 15, 5, 15, 15, 1, 10, true, false); + giantSpider = new Enemy("Giant Spider", 35, 5, 10, 5, 10, 10, 5, 99, true, false); + zombie = new Enemy("Zombie", 20, 5, 15, 5, 15, 15, 1, 10, true, false); + goblin = new Enemy("Goblin", 60, 10, 20, 10, 20, 20, 1, 10, true, false); + ghost = new Enemy("Ghost", 85, 15, 25, 15, 25, 25, 1, 99, true, false); + barbarian = new Enemy("Barbarian", 50, 5, 15, 5, 15, 15, 5, 99, true, false); + giantAnt = new Enemy("Giant Ant", 30, 5, 10, 5, 10, 10, 1, 10, true, false); + evilUnicorn = new Enemy("Evil Unicorn", 35, 30, 40, 5, 15, 20, 5, 99, true, false); + ogre = new Enemy("Ogre", 90, 20, 50, 10, 30, 50, 5, 99, true, false); + + allEnemies = new ArrayList<>(); + + allEnemies.add(darkElf); + allEnemies.add(ninja); + allEnemies.add(giantSpider); + allEnemies.add(zombie); + allEnemies.add(ghost); + allEnemies.add(barbarian); + allEnemies.add(giantAnt); + allEnemies.add(evilUnicorn); + allEnemies.add(ogre); + + Xp.setLevel(1); + } + + @AfterClass + public static void tearDownAfterClass() throws Exception { + } + + @Before + public void setUp() throws Exception { + } + + @After + public void tearDown() throws Exception { + } + + @Test + public void testSet() { + + Xp.setLevel(1); // Set player level to set suitable enemies + + Enemy.set(1); // Set a new enemy to fight + + assertTrue(Enemy.get() instanceof Enemy); // Ensure that enemy was set without error + + assertEquals(ninja.getName(), Enemy.get().getName()); // Ensure that correct enemy was set + + Xp.setLevel(15); // Set player level to set suitable enemies + + Enemy.set(0); // Set a new enemy to fight + + assertTrue(Enemy.get() instanceof Enemy); // Ensure that enemy was set without error + + assertEquals(darkElf.getName(), Enemy.get().getName()); // Ensure that correct enemy was set + + Enemy getTestEnemy = new Enemy("getTestEnemy", 90, 20, 50, 10, 30, 50, 50, 100, true, false); + + Xp.setLevel(100); // Set player level to set suitable enemies + + Enemy.set(10); // Set a new enemy to fight + + assertTrue(Enemy.get() instanceof Enemy); // Ensure that enemy was set without error + + assertEquals(getTestEnemy.getName(), Enemy.get().getName()); // Ensure that correct enemy was set + } + + @Test + public void testGet() { + + Xp.setLevel(1); // Set player level to find suitable enemies + + Enemy.encounterNew(); // Encounter a new enemy to fight + + assertTrue(Enemy.get() instanceof Enemy); // Ensure that enemy was found without error + + ArrayList suitableEnemies = new ArrayList(); // Initialize a list of manually found suitable enemies + + suitableEnemies.add(ninja); + suitableEnemies.add(zombie); + suitableEnemies.add(goblin); + suitableEnemies.add(ghost); + suitableEnemies.add(giantAnt); + + assertTrue(suitableEnemies.contains(Enemy.get())); // Ensure that get returns a valid enemy that was encountered + + Xp.setLevel(15); // Set player level to find suitable enemies + + suitableEnemies = new ArrayList(); // Initialize a list of manually found suitable enemies + + suitableEnemies.add(darkElf); + suitableEnemies.add(giantSpider); + suitableEnemies.add(ghost); + suitableEnemies.add(barbarian); + suitableEnemies.add(evilUnicorn); + suitableEnemies.add(ogre); + + Enemy.encounterNew(); // Encounter a new enemy to fight + + assertTrue(Enemy.get() instanceof Enemy); // Ensure that enemy was found without error + + assertTrue(suitableEnemies.contains(Enemy.get())); // Ensure that get returns a valid enemy that was encountered + + Enemy getTestEnemy = new Enemy("getTestEnemy", 90, 20, 50, 10, 30, 50, 50, 100, true, false); + + Xp.setLevel(100); // Set player level to find suitable enemies + + Enemy.encounterNew(); // Encounter a new enemy to fight + + assertTrue(Enemy.get() instanceof Enemy); // Ensure that enemy was found without error + + assertEquals(getTestEnemy.getName(), Enemy.get().getName()); // Ensure that get returns specific enemy (only valid enemy) + } + + @Test + public void testGetIndex() { + + Xp.setLevel(1); // Set player level to find suitable enemies + + Enemy.encounterNew(); // Encounter a new enemy to fight + + ArrayList suitableEnemies = new ArrayList(); // Initialize a list of manually found suitable enemy indeces + + suitableEnemies.add(1); + suitableEnemies.add(3); + suitableEnemies.add(4); + suitableEnemies.add(5); + suitableEnemies.add(7); + + assertTrue(suitableEnemies.contains(Enemy.getIndex(Enemy.get()))); // Ensure that get returns a valid enemy that was encountered + + Xp.setLevel(15); // Set player level to find suitable enemies + + suitableEnemies = new ArrayList(); // Initialize a list of manually found suitable enemy indeces + + suitableEnemies.add(0); + suitableEnemies.add(2); + suitableEnemies.add(4); + suitableEnemies.add(6); + suitableEnemies.add(8); + suitableEnemies.add(9); + + Enemy.encounterNew(); // Encounter a new enemy to fight + + assertTrue(suitableEnemies.contains(Enemy.getIndex(Enemy.get()))); // Ensure that get returns a valid enemy that was encountered + + Enemy getTestEnemy = new Enemy("getTestEnemy", 90, 20, 50, 10, 30, 50, 50, 100, true, false); + + Xp.setLevel(100); // Set player level to find suitable enemies + + Enemy.encounterNew(); // Encounter a new enemy to fight + + assertTrue(Enemy.get() instanceof Enemy); // Ensure that enemy was found without error + + assertEquals(10, Enemy.getIndex(Enemy.get())); // Ensure that get returns specific enemy (only valid enemy) + } + + @Test + public void testFindEnemy() { + + Xp.setLevel(1); // Set player level to find suitable enemies + + Enemy.findEnemy(); // Find a new enemy to fight + + assertTrue(Enemy.get() instanceof Enemy); // Ensure that enemy was found without error + + ArrayList suitableEnemies = new ArrayList(); // Initialize a list of manually found suitable enemies + + suitableEnemies.add(ninja); + suitableEnemies.add(zombie); + suitableEnemies.add(goblin); + suitableEnemies.add(ghost); + suitableEnemies.add(giantAnt); + + assertTrue(suitableEnemies.contains(Enemy.get())); // Ensure that valid enemy was found + + Xp.setLevel(15); // Set player level to find suitable enemies + + suitableEnemies = new ArrayList(); // Initialize a list of manually found suitable enemies + + suitableEnemies.add(darkElf); + suitableEnemies.add(giantSpider); + suitableEnemies.add(ghost); + suitableEnemies.add(barbarian); + suitableEnemies.add(evilUnicorn); + suitableEnemies.add(ogre); + + Enemy.findEnemy(); // Find a new enemy to fight + + assertTrue(Enemy.get() instanceof Enemy); // Ensure that enemy was found without error + + assertTrue(suitableEnemies.contains(Enemy.get())); // Ensure that valid enemy was found + } + + @Test + public void testGetEnemies() { + // Test constant enemies array access + + assertEquals(Enemy.arrayEnemy.size(), Enemy.getEnemies().size()); + + assertEquals(Enemy.arrayEnemy, Enemy.getEnemies()); + + // Check all objects are the same in each list access method + assertEquals(Enemy.arrayEnemy.get(0), Enemy.getEnemies().get(0)); + assertEquals(Enemy.arrayEnemy.get(1), Enemy.getEnemies().get(1)); + assertEquals(Enemy.arrayEnemy.get(2), Enemy.getEnemies().get(2)); + assertEquals(Enemy.arrayEnemy.get(3), Enemy.getEnemies().get(3)); + assertEquals(Enemy.arrayEnemy.get(4), Enemy.getEnemies().get(4)); + assertEquals(Enemy.arrayEnemy.get(5), Enemy.getEnemies().get(5)); + assertEquals(Enemy.arrayEnemy.get(6), Enemy.getEnemies().get(6)); + assertEquals(Enemy.arrayEnemy.get(7), Enemy.getEnemies().get(7)); + assertEquals(Enemy.arrayEnemy.get(8), Enemy.getEnemies().get(8)); + assertEquals(Enemy.arrayEnemy.get(9), Enemy.getEnemies().get(9)); + } +} diff --git a/src/com/hotmail/kalebmarc/textfighter/main/FoodTest.java b/src/com/hotmail/kalebmarc/textfighter/main/FoodTest.java new file mode 100644 index 00000000..4033129f --- /dev/null +++ b/src/com/hotmail/kalebmarc/textfighter/main/FoodTest.java @@ -0,0 +1,119 @@ +package com.hotmail.kalebmarc.textfighter.main; + +import static org.junit.Assert.assertEquals; + +import java.io.ByteArrayInputStream; +import java.io.InputStream; + +import org.junit.After; +import org.junit.AfterClass; +import org.junit.Before; +import org.junit.BeforeClass; +import org.junit.Test; + +import com.hotmail.kalebmarc.textfighter.player.Health; + +public class FoodTest { + + static InputStream sysInBackup; + + public static Food apple; + public static Food orange; + public static Food dragonfruit; + public static Food meat; + public static Food mushroom; + public static Food fish; + + @BeforeClass + public static void setUpBeforeClass() throws Exception { + + sysInBackup = System.in; // backup System.in to restore it later + + apple = new Food("Apple", "A boring 'ol apple.", StatusEffect.type.HEALTH, Food.type.FRUIT, 5); + orange = new Food("Orange", "Sort of like an apple, but orange.", StatusEffect.type.HEALTH, Food.type.FRUIT, 5); + dragonfruit = new Food("Dragon Fruit", "Unfortunately, not a real dragon.", StatusEffect.type.HEALTH, Food.type.FRUIT, 10); + meat = new Food("Chunk of meat", "Probably not rotten.", StatusEffect.type.HEALTH, Food.type.MEAT_OTHER, 15); + mushroom = new Food("Mushroom", "The good kind!", StatusEffect.type.HEALTH, Food.type.OTHER, 5); + fish = new Food("Fish", "Found in rivers and lakes.", StatusEffect.type.HEALTH, Food.type.MEAT_FISH, 15); + } + + @AfterClass + public static void tearDownAfterClass() throws Exception { + + System.setIn(sysInBackup); + } + + @Before + public void setUp() throws Exception { + + System.setIn(sysInBackup); + } + + @After + public void tearDown() throws Exception { + + System.setIn(sysInBackup); + } + + @Test + public void testListChooseFirst() { + Health.set(50, 100); // Set player health to make food eating visible + + ByteArrayInputStream chooseIn = new ByteArrayInputStream("1".getBytes()); // Set input stream to pick food automatically + + System.setIn(chooseIn); + + Food.list(); // Eat a food + + System.setIn(sysInBackup); + + assertEquals(Health.get(), 55); // Check that player health was updated + } + + @Test + public void testListChooseMiddle() { + Health.set(50, 100); // Set player health to make food eating visible + + ByteArrayInputStream chooseIn = new ByteArrayInputStream("3".getBytes()); // Set input stream to pick food automatically + + System.setIn(chooseIn); + + Food.list(); // Eat a food + + System.setIn(sysInBackup); + + assertEquals(Health.get(), 60); // Check that player health was updated + } + + @Test + public void testListChooseLast() { + Health.set(50, 100); // Set player health to make food eating visible + + ByteArrayInputStream chooseIn = new ByteArrayInputStream("6".getBytes()); // Set input stream to pick food automatically + + System.setIn(chooseIn); + + Food.list(); // Eat a food + + System.setIn(sysInBackup); + + assertEquals(Health.get(), 65); // Check that player health was updated + } + + @Test + public void testGetFoods() { + // Test constant foods array access + + assertEquals(Food.arrayFood.size(), Food.getFoods().size()); + + assertEquals(Food.arrayFood, Food.getFoods()); + + // Check all objects are the same in each list access method + assertEquals(Food.arrayFood.get(0), Food.getFoods().get(0)); + assertEquals(Food.arrayFood.get(1), Food.getFoods().get(1)); + assertEquals(Food.arrayFood.get(2), Food.getFoods().get(2)); + assertEquals(Food.arrayFood.get(3), Food.getFoods().get(3)); + assertEquals(Food.arrayFood.get(4), Food.getFoods().get(4)); + assertEquals(Food.arrayFood.get(5), Food.getFoods().get(5)); + } +} diff --git a/src/com/hotmail/kalebmarc/textfighter/main/WeaponTest.java b/src/com/hotmail/kalebmarc/textfighter/main/WeaponTest.java new file mode 100644 index 00000000..1b4a60a1 --- /dev/null +++ b/src/com/hotmail/kalebmarc/textfighter/main/WeaponTest.java @@ -0,0 +1,147 @@ +package com.hotmail.kalebmarc.textfighter.main; + +import static org.junit.Assert.*; + +import java.io.ByteArrayInputStream; +import java.io.InputStream; + +import org.junit.After; +import org.junit.AfterClass; +import org.junit.Before; +import org.junit.BeforeClass; +import org.junit.Test; + +public class WeaponTest { + + static InputStream sysInBackup; + + static Weapon fists; + static Weapon baseballBat; + static Weapon knife; + static Weapon pipe; + //Guns: + static Weapon pistol; + static Weapon smg; + static Weapon shotgun; + static Weapon rifle; + static Weapon sniper; + + @BeforeClass + public static void setUpBeforeClass() throws Exception { + sysInBackup = System.in; // backup System.in to restore it later + + fists = new Weapon("Fists", true, false, 0, 0, 5, 10, true, false); + baseballBat = new Weapon("Baseball Bat", false, true, 120, 1, 10, 15, true, false); + knife = new Weapon("Knife", false, true, 125, 2, 10, 20, true, false); + pipe = new Weapon("Pipe", false, false, 0, 0, 5, 20, true, false); + //Guns: + pistol = new Weapon("Pistol", 1, 18, true, 250, 1, 4, 15, 1.5, 3, 4, true, false); + smg = new Weapon("Smg", 10, 75, true, 700, 1, 10, 75, 2.5, 4, 6, true, false); + shotgun = new Weapon("Shotgun", 1, 12, true, 375, 2, 9, 60, 2, 5, 7, true, false); + rifle = new Weapon("Rifle", 1, 18, true, 275, 1, 5, 10, 1.25, 6, 7, true, false); + sniper = new Weapon("Sniper", 1, 10, true, 700, 2, 7, 0, 1, 7, 10, true, false); + + Weapon.arrayWeapon.get(1).owns = true; + Weapon.arrayWeapon.get(4).owns = true; + } + + @AfterClass + public static void tearDownAfterClass() throws Exception { + + System.setIn(sysInBackup); + } + + @Before + public void setUp() throws Exception { + + System.setIn(sysInBackup); + } + + @After + public void tearDown() throws Exception { + + System.setIn(sysInBackup); + } + + @Test + public void testGetIndex() { + fail("Not yet implemented"); + } + + @Test + public void testSet() { + Weapon.set(0); // Set weapon to first weapon, fist + + assertEquals("Fists", Weapon.get().getName()); // Check for successful set + + Weapon.set(1); // Set weapon to middle weapon, pipe + + assertEquals("Pipe", Weapon.get().getName()); // Check for successful set + + Weapon.set(4); // Set weapon to middle weapon, pipe + + assertEquals("Pistol", Weapon.get().getName()); // Check for successful set + } + + @Test + public void testChooseFirst() { + + ByteArrayInputStream chooseIn = new ByteArrayInputStream("1".getBytes()); + + System.setIn(chooseIn); + + Weapon.choose(); // Choose a weapon + + System.setIn(sysInBackup); + + assertEquals("Fists", Weapon.get().getName()); // Check that player weapon was updated + } + + @Test + public void testChooseMiddle() { + + ByteArrayInputStream chooseIn = new ByteArrayInputStream("2".getBytes()); + + System.setIn(chooseIn); + + Weapon.choose(); // Choose a weapon + + System.setIn(sysInBackup); + + assertEquals("Pipe", Weapon.get().getName()); // Check that player weapon was updated + } + + @Test + public void testChooseLast() { + + ByteArrayInputStream chooseIn = new ByteArrayInputStream("3".getBytes()); + + System.setIn(chooseIn); + + Weapon.choose(); // Choose a weapon + + System.setIn(sysInBackup); + + assertEquals("Pistol", Weapon.get().getName()); // Check that player weapon was updated + } + + @Test + public void testGetWeapons() { + // Test constant weapons array access + + assertEquals(Weapon.arrayWeapon.size(), Weapon.getWeapons().size()); + + assertEquals(Weapon.arrayWeapon, Weapon.getWeapons()); + + // Check all objects are the same in each list access method + assertEquals(Weapon.arrayWeapon.get(0), Weapon.getWeapons().get(0)); + assertEquals(Weapon.arrayWeapon.get(1), Weapon.getWeapons().get(1)); + assertEquals(Weapon.arrayWeapon.get(2), Weapon.getWeapons().get(2)); + assertEquals(Weapon.arrayWeapon.get(3), Weapon.getWeapons().get(3)); + assertEquals(Weapon.arrayWeapon.get(4), Weapon.getWeapons().get(4)); + assertEquals(Weapon.arrayWeapon.get(5), Weapon.getWeapons().get(5)); + assertEquals(Weapon.arrayWeapon.get(6), Weapon.getWeapons().get(6)); + assertEquals(Weapon.arrayWeapon.get(7), Weapon.getWeapons().get(7)); + assertEquals(Weapon.arrayWeapon.get(8), Weapon.getWeapons().get(8)); + } +} diff --git a/src/com/hotmail/kalebmarc/textfighter/player/PotionTest.java b/src/com/hotmail/kalebmarc/textfighter/player/PotionTest.java new file mode 100644 index 00000000..0d1d6b93 --- /dev/null +++ b/src/com/hotmail/kalebmarc/textfighter/player/PotionTest.java @@ -0,0 +1,325 @@ +package com.hotmail.kalebmarc.textfighter.player; + +import static org.junit.Assert.assertEquals; + +import java.io.ByteArrayInputStream; +import java.io.InputStream; + +import org.junit.After; +import org.junit.AfterClass; +import org.junit.Before; +import org.junit.BeforeClass; +import org.junit.Ignore; +import org.junit.Test; + +public class PotionTest { + + static InputStream sysInBackup; + + static ByteArrayInputStream in; + + @BeforeClass + public static void setUpBeforeClass() throws Exception { + sysInBackup = System.in; // backup System.in to restore it later + in = new ByteArrayInputStream("\n".getBytes()); + System.setIn(in); + } + + @AfterClass + public static void tearDownAfterClass() throws Exception { + System.setIn(sysInBackup); + } + + @Before + public void setUp() throws Exception { + in = new ByteArrayInputStream("\n".getBytes()); + System.setIn(in); + } + + @After + public void tearDown() throws Exception { + System.setIn(sysInBackup); + } + + @Test + public void testGet() { + + assertEquals(Potion.get("survival"), 0); // Starting with no potions + + assertEquals(Potion.get("recovery"), 0); // Starting with no potions + + Potion.set("survival", 5, false); // Set player's survival potion count to 5 + + Potion.set("recovery", 5, false); // Set player's recovery potion count to 5 + + assertEquals(Potion.get("survival"), 5); // Check survival potion total + + assertEquals(Potion.get("recovery"), 5); // Check recovery potion total + + // Test that using a potion depletes the total + Potion.use("survival"); + + Potion.use("survival"); + + Potion.use("survival"); + + Potion.use("recovery"); + + Potion.use("recovery"); + + assertEquals(Potion.get("survival"), 2); // Check survival potion total after using some potions + + assertEquals(Potion.get("recovery"), 3); // Check recovery potion total after using some potions + + Potion.use("survival"); + + Potion.use("survival"); + + Potion.use("recovery"); + + Potion.use("recovery"); + + Potion.use("recovery"); + + assertEquals(Potion.get("survival"), 0); // Check survival potion total + + assertEquals(Potion.get("recovery"), 0); // Check recovery potion total + + // Attempt to use nonexistant potions + Potion.use("survival"); + + Potion.use("recovery"); + + assertEquals(Potion.get("survival"), 0); // Check survival potion total after using all potions + + assertEquals(Potion.get("recovery"), 0); // Check recovery potion total after using all potions + } + + @Test + public void testSet() { + + Potion.set("survival", 0, false); // Starting with no potions + + Potion.set("recovery", 0, false); // Starting with no potions + + assertEquals(Potion.get("survival"), 0); // Check survival potion total + + assertEquals(Potion.get("recovery"), 0); // Check recovery potion total + + Potion.set("survival", 5, false); // Set player's survival potion count to 5 + + Potion.set("recovery", 5, false); // Set player's recovery potion count to 5 + + assertEquals(Potion.get("survival"), 5); // Check survival potion total + + assertEquals(Potion.get("recovery"), 5); // Check recovery potion total + + // Test that using a potion depletes the total + Potion.use("survival"); + + Potion.use("survival"); + + Potion.use("survival"); + + Potion.use("recovery"); + + Potion.use("recovery"); + + Potion.set("survival", 5, false); // Set player's survival potion count to 5 + + Potion.set("recovery", 5, false); // Set player's recovery potion count to 5 + + assertEquals(Potion.get("survival"), 5); // Check survival potion total + + assertEquals(Potion.get("recovery"), 5); // Check recovery potion total + + // Deplete potions again + Potion.use("survival"); + + Potion.use("survival"); + + Potion.use("survival"); + + Potion.use("recovery"); + + Potion.use("recovery"); + + assertEquals(Potion.get("survival"), 2); // Check survival potion total + + assertEquals(Potion.get("recovery"), 3); // Check recovery potion total + + Potion.set("survival", 5, true); // Set player's survival potion count to 5 more + + Potion.set("recovery", 5, true); // Set player's recovery potion count to 5 more + + assertEquals(Potion.get("survival"), 7); // Check survival potion total + + assertEquals(Potion.get("recovery"), 8); // Check recovery potion total + } + + @Test + public void testUse() { + + Potion.set("survival", 0, false); // Starting with no potions + + Potion.set("recovery", 0, false); // Starting with no potions + + Potion.set("survival", 5, false); // Set player's survival potion count to 5 + + Potion.set("recovery", 5, false); // Set player's recovery potion count to 5 + + // Test that using a potion depletes the total + Potion.use("survival"); + + Potion.use("survival"); + + Potion.use("survival"); + + Potion.use("recovery"); + + Potion.use("recovery"); + + assertEquals(Potion.get("survival"), 2); // Check survival potion total + + assertEquals(Potion.get("recovery"), 3); // Check recovery potion total + + // Deplete potions again + Potion.use("survival"); + + Potion.use("survival"); + + Potion.use("recovery"); + + Potion.use("recovery"); + + Potion.use("recovery"); + + assertEquals(Potion.get("survival"), 0); // Check survival potion total + + assertEquals(Potion.get("recovery"), 0); // Check recovery potion total + + // Attempt to use nonexistant potions + Potion.use("survival"); + + Potion.use("recovery"); + + assertEquals(Potion.get("survival"), 0); // Check survival potion total after using all potions + + assertEquals(Potion.get("recovery"), 0); // Check recovery potion total after using all potions + } + + @Test + public void testUsed() { + + Potion.set("survival", 0, false); // Starting with no potions + + Potion.set("recovery", 0, false); // Starting with no potions + + Potion.set("survival", 5, false); // Set player's survival potion count to 5 + + Potion.set("recovery", 5, false); // Set player's recovery potion count to 5 + + assertEquals(16, Potion.spUsed); // Check total survival potions that have been used throughout the tests + + assertEquals(14, Potion.rpUsed); // Check total recovery potions that have been used throughout the tests + + // Test that using a potion increments the total used + Potion.use("survival"); + + Potion.use("survival"); + + Potion.use("survival"); + + Potion.use("recovery"); + + Potion.use("recovery"); + + assertEquals(19, Potion.spUsed); // Check total survival potions that have been used + + assertEquals(16, Potion.rpUsed); // Check total recovery potions that have been used + + // Deplete potions again + Potion.use("survival"); + + Potion.use("survival"); + + Potion.use("recovery"); + + Potion.use("recovery"); + + Potion.use("recovery"); + + assertEquals(21, Potion.spUsed); // Check total survival potions that have been used + + assertEquals(19, Potion.rpUsed); // Check total recovery potions that have been used + + // Attempt to use nonexistant potions + Potion.use("survival"); + + Potion.use("recovery"); + + assertEquals(21, Potion.spUsed); // Check total survival potions that have been used after using all potions + + assertEquals(19, Potion.rpUsed); // Check total recovery potions that have been used after using all potions + } + + @Ignore + @Test + public void testUsedAlone() { + + Potion.set("survival", 0, false); // Starting with no potions + + Potion.set("recovery", 0, false); // Starting with no potions + + Potion.set("survival", 5, false); // Set player's survival potion count to 5 + + Potion.set("recovery", 5, false); // Set player's recovery potion count to 5 + + Potion.spUsed = 0; // Reset survival potion usage count + + Potion.rpUsed = 0; // Reset recovery potion usage count + + assertEquals(0, Potion.spUsed); // Check total survival potions that have been used in this test + + assertEquals(0, Potion.rpUsed); // Check total recovery potions that have been used in this test + + // Test that using a potion increments the total used + Potion.use("survival"); + + Potion.use("survival"); + + Potion.use("survival"); + + Potion.use("recovery"); + + Potion.use("recovery"); + + assertEquals(3, Potion.spUsed); // Check total survival potions that have been used + + assertEquals(2, Potion.rpUsed); // Check total recovery potions that have been used + + // Deplete potions again + Potion.use("survival"); + + Potion.use("survival"); + + Potion.use("recovery"); + + Potion.use("recovery"); + + Potion.use("recovery"); + + assertEquals(5, Potion.spUsed); // Check total survival potions that have been used + + assertEquals(5, Potion.rpUsed); // Check total recovery potions that have been used + + // Attempt to use nonexistant potions + Potion.use("survival"); + + Potion.use("recovery"); + + assertEquals(5, Potion.spUsed); // Check total survival potions that have been used after using all potions + + assertEquals(5, Potion.rpUsed); // Check total recovery potions that have been used after using all potions + } +}