Last active
August 29, 2015 14:07
-
-
Save DarkLotus/00c533f8b41d107a3aae to your computer and use it in GitHub Desktop.
A2 tester
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| package com.jameskidd; | |
| /** | |
| * An automated driver class for the farm game.<p> | |
| * | |
| * @version 1.0 | |
| * @author James Kidd | |
| */ | |
| import java.io.Console; | |
| import com.jameskidd.Controllers.Controller; | |
| import com.jameskidd.Models.Animals.Cow; | |
| import com.jameskidd.Models.Animals.Sheep; | |
| import com.jameskidd.Models.Crops.Apple; | |
| import com.jameskidd.Models.Crops.Wheat; | |
| import com.jameskidd.Util.GameCalendar; | |
| public class AutomatedDriver | |
| { | |
| static Controllable game; | |
| private static boolean testName(){ | |
| if(game.getName().equals("Player")) | |
| return true; | |
| return false; | |
| } | |
| private static void testLiveStockMonthlyRevLoss() throws Exception { | |
| double money = 4000; | |
| game.sellLand(3, 4); | |
| game.sellLand(3, 3); | |
| if(game.getWorth() != money) | |
| throw new Exception("Wrong Money after inital land sale"); | |
| game.buyProduce(4, 4, new Cow()); | |
| game.buyProduce(4, 3, new Sheep()); | |
| money = 1200; | |
| if(game.getWorth() != money) | |
| throw new Exception("Wrong Money after inital livestock purchase"); | |
| System.out.println("Sold 2x land, purchased 1x Cow, 1x Sheep. Advancing calender..."); | |
| for(int i = 0; i <= 12;i++){ | |
| game.advanceCalendar(); | |
| money = money - 390 + 500; | |
| if(game.getWorth() != money) | |
| throw new Exception("invalid livestock cash flow had:" + game.getWorth() + " should of had: " + money); | |
| System.out.println(GameCalendar.getDateString() + " Money: " + game.getWorth()); | |
| } | |
| System.out.println("Monthly Livestock Profit test: Passed"); | |
| } | |
| private static void testCropPlotMaintenance() throws Exception { | |
| double money = 4000; | |
| game.sellLand(3, 4); | |
| game.sellLand(3, 3); | |
| if(game.getWorth() != money) | |
| throw new Exception("Wrong Money after inital land sale"); | |
| game.buyProduce(4, 4, new Wheat()); | |
| game.buyProduce(4, 3, new Apple()); | |
| money = 2700; | |
| if(game.getWorth() != money) | |
| throw new Exception("Wrong Money after inital livestock purchase"); | |
| System.out.println("Sold 2x land, purchased 1x Wheat, 1x Apple. Advancing calender..."); | |
| for(int i = 0; i <= 12;i++){ | |
| game.advanceCalendar(); | |
| money -= 120; | |
| if(game.getWorth() != money) | |
| throw new Exception("invalid livestock cash flow"); | |
| System.out.println(GameCalendar.getDateString() + " Money: " + game.getWorth()); | |
| } | |
| System.out.println("Monthly Crop Profit test: Passed"); | |
| } | |
| /** | |
| * The main execution method. | |
| * @throws Exception | |
| */ | |
| public static void main(String[] args) throws Exception | |
| { | |
| game = new Controller("Player"); | |
| if(!testName()) | |
| throw new Exception("Names do not match"); | |
| testLiveStockMonthlyRevLoss(); | |
| game = new Controller("Player"); | |
| testCropPlotMaintenance(); | |
| testCropSaleProfits(12); | |
| testEventRemoval(); | |
| System.out.println("Livestock and Crop tests passed"); | |
| } | |
| private static void testCropSaleProfits(int months) throws Exception | |
| { | |
| game = new Controller("Player"); | |
| double money = 4000; | |
| game.sellLand(3, 4); | |
| game.sellLand(3, 3); | |
| if(game.getWorth() != money) | |
| throw new Exception("Wrong Money after inital land sale"); | |
| game.buyProduce(4, 4, new Apple()); | |
| for(int i = 0; i <= months;i++){ | |
| game.advanceCalendar(); | |
| } | |
| System.out.println("Advanced : " + months + " Current Funds: " + game.getWorth()); | |
| double gold = game.getWorth(); | |
| game.sellProduce(4, 4); | |
| gold = game.getWorth() - gold; | |
| System.out.println("Sold Produce: " + " Profit: " + gold); | |
| if(months < 12) | |
| testCropSaleProfits(++months); | |
| } | |
| private static void testEventRemoval() throws Exception { | |
| game = new Controller("Player"); | |
| double money = 4000; | |
| game.sellLand(3, 4); | |
| game.sellLand(3, 3); | |
| game.buyProduce(4, 4, new Apple()); | |
| game.advanceCalendar(); | |
| game.sellLand(4, 4); | |
| game.advanceCalendar(); | |
| if(game.getWorth() != 4090) | |
| throw new Exception("Worth didnt match " + game.getWorth() + " should be $4090"); | |
| game.advanceCalendar(); | |
| if(game.getWorth() != 4070) | |
| throw new Exception("Worth didnt match " + game.getWorth() + " should be $4070"); | |
| System.out.println("Cur1: " + game.getWorth()); | |
| game.buyProduce(4, 3, new Cow()); | |
| game.advanceCalendar(); | |
| System.out.println("Cur2: " + game.getWorth()); | |
| if(game.getWorth() != 2650) | |
| throw new Exception("Worth didnt match " + game.getWorth() + " should be $2650"); | |
| game.sellProduce(4, 3); | |
| System.out.println("Cur3: " + game.getWorth()); | |
| game.advanceCalendar(); | |
| if(game.getWorth() != 3372) | |
| throw new Exception("Worth didnt match " + game.getWorth() + " should be $3372"); | |
| System.out.println("Event Removal appears fine, Worths match up"); | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment