Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cheats index out of bounds fix #131

Merged
merged 44 commits into from
Nov 15, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
44 commits
Select commit Hold shift + click to select a range
493c8ea
Re-included tests and added inline documentation as well as test inst…
emmamickas Oct 23, 2021
c70b9cf
Re-included tests and added inline documentation as well as test inst…
emmamickas Oct 23, 2021
da6ab53
Added tests for Cheats
emmamickas Oct 23, 2021
d3d5859
Added implementation to fix indexing of weapon array in cheats.
emmamickas Oct 23, 2021
8edbbeb
Temporarily remove test for cleanliness and merge.
emmamickas Oct 23, 2021
d061c92
Added documentation references for comprehension of changes involved …
emmamickas Oct 24, 2021
5902e1a
Added document to record information regarding changes and processes …
emmamickas Oct 24, 2021
4072cdb
Added documentation references for comprehension of changes involved …
emmamickas Oct 24, 2021
dc3afcf
Added document to record information regarding changes and processes …
emmamickas Oct 24, 2021
11e2b8a
Added documentation references for comprehension of changes involved …
emmamickas Oct 24, 2021
71c6fc5
Added document to record information regarding changes and processes …
emmamickas Oct 24, 2021
0ca895e
Update CHANGES.md
emmamickas Oct 24, 2021
f4587b3
Added direct links to issues for reference.
emmamickas Oct 24, 2021
96597c4
Update CHANGES.md
emmamickas Oct 24, 2021
f14b1ad
Update CHANGES.md
emmamickas Oct 24, 2021
e4bc649
Update TESTING.md
emmamickas Oct 24, 2021
0cf9523
Create TESTING.md
emmamickas Oct 24, 2021
dc0eb33
Update TESTING.md
emmamickas Oct 24, 2021
025d288
Added test information.
emmamickas Oct 24, 2021
65d9500
Added testing information.
emmamickas Oct 24, 2021
66cfcab
Added testing information.
emmamickas Oct 24, 2021
6e893b6
Create CHANGES.md
emmamickas Oct 24, 2021
dcfd9f8
Update CHANGES.md
emmamickas Oct 24, 2021
e15cda9
Re-included tests and added inline documentation as well as test inst…
emmamickas Oct 24, 2021
50a0442
Re-included tests and added inline documentation as well as test inst…
emmamickas Oct 24, 2021
7e38b87
Update TESTING.md
emmamickas Oct 24, 2021
d233079
Added documentation for slicing techniques used in program comprehens…
emmamickas Oct 24, 2021
7cb4512
Merge branch 'ShowSpecificPotionStats' of https://github.com/emmamick…
emmamickas Oct 24, 2021
d0c92f2
Update titling for clarity.
emmamickas Oct 24, 2021
657fa0c
Added documentation for slicing techniques used in program comprehens…
emmamickas Oct 24, 2021
3273e79
Updating remote branch for merging.
emmamickas Oct 24, 2021
ae41a47
Added documentation for slicing techniques used in program comprehens…
emmamickas Oct 24, 2021
b8601f2
Added overall program structure class diagrams used during maintenance.
emmamickas Oct 25, 2021
5f6f20d
Added overall program strucutre diagram used during program comprehen…
emmamickas Oct 25, 2021
ee5e83b
Update CHANGES.md
emmamickas Oct 25, 2021
8e7cb24
Update CHANGES.md
emmamickas Oct 25, 2021
cbc3c64
Merge branch 'master' into CheatsIndexOutOfBoundsFix
emmamickas Oct 25, 2021
3924e6b
Added casino package class diagram
emmamickas Oct 25, 2021
be4c487
Created new fork for changes to be included in maintainability measur…
emmamickas Nov 14, 2021
f316665
Merge branch 'Emma-Deliverable1-Changes' into ShowSpecificPotionStats
emmamickas Nov 14, 2021
246e6c0
Merge pull request #14 from emmamickas/ShowSpecificPotionStats
emmamickas Nov 14, 2021
49f062b
Merge branch 'Emma-Deliverable1-Changes' into AddConstantArraylistAcc…
emmamickas Nov 14, 2021
65b0e78
Merge pull request #15 from emmamickas/AddConstantArraylistAccessModi…
emmamickas Nov 14, 2021
4c05c71
Merge branch 'Emma-Deliverable1-Changes' into CheatsIndexOutOfBoundsFix
emmamickas Nov 14, 2021
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
120 changes: 120 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
@@ -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.
Binary file added Class Diagram/Packagecasinodiagram.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/Packageitemdiagram.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/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/Packagemaindiagram.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 Class Diagram/Packageplayerdiagram.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/Sourcestructurediagram.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.
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.
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
Binary file added Sequence Diagrams/Debug_menu_sequenceDiagram.png
Binary file added Sequence Diagrams/Food_list_sequenceDiagram.png
Binary file added Sequence Diagrams/Potion_use_sequenceDiagram.png
Binary file added Sequence Diagrams/Stats_view_sequenceDiagram.png
57 changes: 57 additions & 0 deletions TESTING.md
Original file line number Diff line number Diff line change
@@ -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.
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());
}
}
4 changes: 2 additions & 2 deletions src/com/hotmail/kalebmarc/textfighter/main/Cheats.java
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
Loading