Skip to content

Commit

Permalink
Merge pull request #15 from emmamickas/AddConstantArraylistAccessModi…
Browse files Browse the repository at this point in the history
…fiers

Add constant arraylist access modifiers
  • Loading branch information
emmamickas authored Nov 14, 2021
2 parents 246e6c0 + 49f062b commit 65b0e78
Show file tree
Hide file tree
Showing 40 changed files with 1,202 additions and 96 deletions.
1 change: 0 additions & 1 deletion CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -119,4 +119,3 @@
* [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.


Binary file added Class Diagram/PackageitemdiagramAfterchange.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Class Diagram/PackageitemdiagramBeforechange.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Class Diagram/PackagemaindiagramAfterchange.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Class Diagram/PackagemaindiagramBeforechange.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Dependency References/ArmourDependencies.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Dependency References/EnemyDependencies.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Dependency References/FoodDependencies.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Dependency References/WeaponDependencies.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Sequence Diagrams/Debug_menu_sequenceDiagram.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Sequence Diagrams/Food_list_sequenceDiagram.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
35 changes: 35 additions & 0 deletions TESTING.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,38 @@
# 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:
Expand Down
196 changes: 196 additions & 0 deletions src/com/hotmail/kalebmarc/textfighter/item/ArmourTest.java
Original file line number Diff line number Diff line change
@@ -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());
}
}
16 changes: 8 additions & 8 deletions src/com/hotmail/kalebmarc/textfighter/item/Chest.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,21 +23,21 @@ public static void view() {
Ui.println(" Recovery: " + Potion.get("recovery"));
Ui.println("Coins: " + Coins.get());
Ui.println("POWERS: " + Power.get());
for (int i = 0; i < Weapon.arrayWeapon.size(); i++) {
if (Weapon.arrayWeapon.get(i).owns()) {
Ui.println(Weapon.arrayWeapon.get(i).getName());
if (!Weapon.arrayWeapon.get(i).melee)
Ui.println(" (Ammo: " + Weapon.arrayWeapon.get(i).getAmmo() + ")");
for (int i = 0; i < Weapon.getWeapons().size(); i++) {
if (Weapon.getWeapons().get(i).owns()) {
Ui.println(Weapon.getWeapons().get(i).getName());
if (!Weapon.getWeapons().get(i).melee)
Ui.println(" (Ammo: " + Weapon.getWeapons().get(i).getAmmo() + ")");
}
}
for (int i = 1; i < Armour.getArmours().size(); i++) {
if (Armour.getArmours().get(i).isOwns()) {
Ui.println(Armour.getArmours().get(i).toString());
}
}
for (int i = 0; i < Food.arrayFood.size(); i++) {
if (Food.arrayFood.get(i).getQuantity() > 0)
Ui.println(Food.arrayFood.get(i).getName() + "(x" + Food.arrayFood.get(i).getQuantity() + ")");
for (int i = 0; i < Food.getFoods().size(); i++) {
if (Food.getFoods().get(i).getQuantity() > 0)
Ui.println(Food.getFoods().get(i).getName() + "(x" + Food.getFoods().get(i).getQuantity() + ")");
}
Ui.println();
Ui.println("------------------------------");
Expand Down
28 changes: 14 additions & 14 deletions src/com/hotmail/kalebmarc/textfighter/main/Cheats.java
Original file line number Diff line number Diff line change
Expand Up @@ -44,27 +44,27 @@ private static void cheatSelect() {
Coins.set(5000, false);
FirstAid.set(5000, false);
InstaHealth.set(5000, false);
for (int i = 0; i < Weapon.arrayWeapon.size(); i++) {
Weapon.arrayWeapon.get(i).setAmmo(5000, false);
for (int i = 0; i < Weapon.getWeapons().size(); i++) {
Weapon.getWeapons().get(i).setAmmo(5000, false);
}
Power.set(5000, false);
for (int i = 0; i < Weapon.arrayWeapon.size(); i++) {
Weapon.arrayWeapon.get(i).owns = true;
for (int i = 0; i < Weapon.getWeapons().size(); i++) {
Weapon.getWeapons().get(i).owns = true;
}
Stats.timesCheated++;
for (int i = 0; i < Food.arrayFood.size(); i++)
Food.arrayFood.get(i).setQuantity(5000);
for (int i = 0; i < Food.getFoods().size(); i++)
Food.getFoods().get(i).setQuantity(5000);
Potion.set("Survival", 5000, false);
Potion.set("Recovery", 5000, false);
break;
case "weaponstash":
for (int i = 0; i <= Weapon.arrayWeapon.size(); i++) {
Weapon.arrayWeapon.get(i).setAmmo(5000, false);
for (int i = 0; i < Weapon.getWeapons().size(); i++) {
Weapon.getWeapons().get(i).setAmmo(5000, false);
}

Power.set(5000, false);
for (int i = 0; i < Weapon.arrayWeapon.size(); i++) {
Weapon.arrayWeapon.get(i).owns = true;
for (int i = 0; i < Weapon.getWeapons().size(); i++) {
Weapon.getWeapons().get(i).owns = true;
}
Stats.timesCheated++;
break;
Expand All @@ -73,8 +73,8 @@ private static void cheatSelect() {
InstaHealth.set(500, false);
Potion.set("Survival", 500, false);
Potion.set("Recovery", 500, false);
for (int i = 0; i < Food.arrayFood.size(); i++)
Food.arrayFood.get(i).setQuantity(100);
for (int i = 0; i < Food.getFoods().size(); i++)
Food.getFoods().get(i).setQuantity(100);
Stats.timesCheated++;
break;
case "healme":
Expand Down Expand Up @@ -103,8 +103,8 @@ private static void cheatSelect() {
Stats.timesCheated++;
break;
case "thirstforfood":
for (int i = 0; i < Food.arrayFood.size(); i++)
Food.arrayFood.get(i).setQuantity(10);
for (int i = 0; i < Food.getFoods().size(); i++)
Food.getFoods().get(i).setQuantity(10);
Stats.timesCheated++;
break;

Expand Down
Loading

0 comments on commit 65b0e78

Please sign in to comment.