Skip to content

Commit

Permalink
Tests have been cleaned up and modified for new requirments.
Browse files Browse the repository at this point in the history
  • Loading branch information
john committed Apr 25, 2015
1 parent 8bd30fd commit 6591cc8
Show file tree
Hide file tree
Showing 8 changed files with 45 additions and 49 deletions.
8 changes: 6 additions & 2 deletions MerchantRPGCSE2102/src/controller/RPGame.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import java.io.File;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Scanner;

Expand All @@ -11,6 +12,7 @@
import model.Merchant;
import model.Player;
import view.MapUI;
import view.StartScreen;

public class RPGame {

Expand Down Expand Up @@ -343,15 +345,17 @@ public boolean getMovement()
* Main method used to test the GUI components since test classes do not maintain the GUI
* @param args no need for input
* @throws InterruptedException
* @throws IOException
*/
public static void main(String[] args) throws InterruptedException
public static void main(String[] args) throws InterruptedException, IOException
{
int fps = 300; // Frames per second
RPGame rpgGame = new RPGame(3, 30);

// MAIN GAME LOOP
while (true) {
rpgGame.updateMapUI();
Thread.sleep(1000/300); // Controls the speed of the game (currently 144 frames/second)
Thread.sleep(1000/fps); // Controls the speed of the game
}
}
}
10 changes: 5 additions & 5 deletions MerchantRPGCSE2102/src/tests/MockGame.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,12 @@
public class MockGame {

public static void main(String[] args) throws InterruptedException {
RPGame rpg = new RPGame();
RPGame rpg = new RPGame(3, 30);
// SETTING UP PLAYER AND MERCHANT
Player player = new Player("Player", 0, null);
Merchant merch1 = new Merchant("Bill", 0, null);
Merchant merch2 = new Merchant("Joe", 0, null);
Merchant merch3 = new Merchant("Sam", 0, null);
Merchant merch1 = new Merchant("Bill", 0, null, 0);
Merchant merch2 = new Merchant("Joe", 0, null, 0);
Merchant merch3 = new Merchant("Sam", 0, null, 0);

// CREATING MAP AND INITIALIZE PLAYER AND MERCHANTS
Map map = new Map(30, 40);
Expand All @@ -30,7 +30,7 @@ public static void main(String[] args) throws InterruptedException {
JFrame frame = new JFrame("Merchant RPG");

// CREATING MAPUI AND SPRITES
MapUI mapui = new MapUI(map, rpg);
MapUI mapui = new MapUI(map, rpg, 30);
mapui.createPlayerSprite(15, 20);
mapui.addMerchantSprite(15, 0);
mapui.addMerchantSprite(29, 20);
Expand Down
22 changes: 12 additions & 10 deletions MerchantRPGCSE2102/src/tests/TestMap.java
Original file line number Diff line number Diff line change
Expand Up @@ -44,27 +44,29 @@ public void testOccupancy() {

public void testMovePlayer() {
Player player = new Player("TestPlayer", 0, null);
Merchant merchant = new Merchant("TestMerchant", 0, null);
Merchant merchant = new Merchant("TestMerchant", 0, null, 0);
map.initializePlayer(player, 3, 3);
map.initializeMerchant(merchant, 0, 2);
map.movePlayer("west");
System.out.println("Col: " + player.getCol() + " Row: " + player.getRow());
map.movePlayer("south");
System.out.println("Col: " + player.getCol() + " Row: " + player.getRow());
map.movePlayer("north");
System.out.println("Col: " + player.getCol() + " Row: " + player.getRow());
map.movePlayer("east");
System.out.println("Col: " + player.getCol() + " Row: " + player.getRow());
map.movePlayer("east");
System.out.println("Col: " + player.getCol() + " Row: " + player.getRow());
map.movePlayer("north");
System.out.println("Col: " + player.getCol() + " Row: " + player.getRow());
map.movePlayer("north");
System.out.println("Col: " + player.getCol() + " Row: " + player.getRow());
map.movePlayer("north");
System.out.println("Col: " + player.getCol() + " Row: " + player.getRow());
map.movePlayer("west");
map.movePlayer("west");
map.movePlayer("west");
map.movePlayer("west");
map.movePlayer("south");
map.movePlayer("south");
map.movePlayer("south");
map.movePlayer("south");
assertEquals(player.getCol(), 0);
assertEquals(player.getRow(), 1);
System.out.println("Col: " + player.getCol() + " Row: " + player.getRow());
assertEquals(player.getCol(), 3);
assertEquals(player.getRow(), 0);
assertEquals(map.isOccupied(player.getCol(), player.getRow()), true);
}

Expand Down
10 changes: 5 additions & 5 deletions MerchantRPGCSE2102/src/tests/TestMerchant.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@ public class TestMerchant extends TestCase

public void setup()
{
RPGame game = new RPGame();
RPGame game = new RPGame(3, 30);
game.inventoryFromFile();
m = new Merchant("Test", 100, game.getMerchantInventoryList(1));
m = new Merchant("Test", 100, game.getMerchantInventoryList(1), 0);
}

//testing cash system
Expand Down Expand Up @@ -60,9 +60,9 @@ public void testInventoryPrices() throws Exception
{
setup();
m.scaleAllAdjustedPrices();
assertEquals(0, m.getItemPrice("water"));
assertEquals(0, m.getItemPrice("armor"));
assertEquals(0, m.getItemPrice("food"));
assertEquals(0, m.getItemPrice("Water"));
assertEquals(0, m.getItemPrice("Candy"));
assertEquals(0, m.getItemPrice("Apple"));
}

//testing name
Expand Down
18 changes: 9 additions & 9 deletions MerchantRPGCSE2102/src/tests/TestPlayer.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ public void setup()
RPGame game = new RPGame(3, 30); //starting a new game
game.inventoryFromFile(); //read from file
p = new Player("TestPlayer", 1000, game.getPlayerInventoryList());
m = new Merchant("TestMerchant1", 100000, game.getMerchantInventoryList(1));
m = new Merchant("TestMerchant1", 100000, game.getMerchantInventoryList(1), 0);
}

//test cash system for Player class
Expand All @@ -43,20 +43,20 @@ public void testPlayerInventory() {
public void testBuy()
{
setup();
p.buy("water", m, 10);
assertEquals(970, p.getPlayerCash());
assertEquals(10, p.getItem("water").getQuantity());
p.buy("Water", m, 10);
assertEquals(980, p.getPlayerCash());
assertEquals(10, p.getItem("Water").getQuantity());
}

public void testSell() throws NotInInventoryException, MerchantNotEnoughCashException
{
setup();
testBuy();
p.sell("water", m, 11);
assertEquals(970, p.getPlayerCash());
assertEquals(10, p.getItem("water").getQuantity());
p.sell("water", m, 10);
p.sell("Water", m, 11);
assertEquals(980, p.getPlayerCash());
assertEquals(10, p.getItem("Water").getQuantity());
p.sell("Water", m, 10);
assertEquals(1000, p.getPlayerCash());
assertEquals(0, p.getItem("water").getQuantity());
assertEquals(0, p.getItem("Water").getQuantity());
}
}
19 changes: 7 additions & 12 deletions MerchantRPGCSE2102/src/tests/TestRPGame.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ public class TestRPGame extends TestCase

public void setup()
{
game = new RPGame(0, 0);
game = new RPGame(3, 30);
game.buildMerchants();
ArrayList<String> playerInventory = game.getMerchantInventoryList(1);
playerInventory.addAll(game.getMerchantInventoryList(2));
Expand All @@ -23,22 +23,17 @@ public void testFile()
{
// tests that the RPGame is able to read from the text file correctly
setup();
assertEquals("water 3", game.getMerchantInventoryList(1).get(0));
assertEquals("armor 5", game.getMerchantInventoryList(1).get(1));
assertEquals("food 10", game.getMerchantInventoryList(1).get(2));
assertEquals("wood 3", game.getMerchantInventoryList(2).get(0));
assertEquals("tarp 6", game.getMerchantInventoryList(2).get(1));
assertEquals("glass 3", game.getMerchantInventoryList(3).get(0));
assertEquals("tape 13", game.getMerchantInventoryList(3).get(1));
assertEquals("rope 5", game.getMerchantInventoryList(3).get(2));
assertEquals("Water 2", game.getMerchantInventoryList(1).get(0));
assertEquals("Candy 5", game.getMerchantInventoryList(1).get(1));
assertEquals("Apple 7", game.getMerchantInventoryList(1).get(2));
}

public void testDailyCycle()
{
setup();
assertEquals(1, game.getDay());
game.getMerchant(1).subtractCash(500);
assertEquals(500, game.getMerchant(1).getCurrentCash());
game.getMerchant(1).subtractCash(200);
assertEquals(0, game.getMerchant(1).getCurrentCash());
game.advanceDailyCycle();
assertEquals(2, game.getDay());

Expand All @@ -51,7 +46,7 @@ public void testDailyCycle()
test = false;

assertEquals(true, test);
assertEquals(1000, game.getMerchant(1).getCurrentCash());
assertEquals(200, game.getMerchant(1).getCurrentCash());

}
}
2 changes: 1 addition & 1 deletion MerchantRPGCSE2102/src/tests/TestTransaction.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ public class TestTransaction extends TestCase

public void setup()
{
_rpg = new RPGame(0, 0);
_rpg = new RPGame(3, 30);
_rpg.inventoryFromFile();
_rpg.buildMerchants();
ArrayList<String> playerInventory = _rpg.getMerchantInventoryList(1);
Expand Down
5 changes: 0 additions & 5 deletions MerchantRPGCSE2102/src/view/MainMenuUI.java

This file was deleted.

0 comments on commit 6591cc8

Please sign in to comment.