Skip to content

Commit

Permalink
Adds some changes.
Browse files Browse the repository at this point in the history
  • Loading branch information
Dougnkong committed Dec 18, 2020
1 parent cf8526e commit f0c030c
Show file tree
Hide file tree
Showing 11 changed files with 52 additions and 52 deletions.
2 changes: 1 addition & 1 deletion README.mkd
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,5 @@
All tools with which you can execute Java code.

## How to test the Project
The entire tests can be found in the class testDrinkAutomat in folder ../drinkAutomat/src/drinkAutomatTest/testDrinkAutomat.java.
The entire tests can be found in the class testDrinkAutomat in folder ../main.drinkautomat/src/main.drinkautomatTest/testDrinkAutomat.java.
When you run this class, all tests are run automatically. Explanations for each test can be found in the test itself.
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package drinkAutomat.common;
package main.drinkautomat.common;

import drinkAutomat.model.Coin;
import drinkAutomat.model.CoinAndQuantity;
import main.drinkautomat.model.Coin;
import main.drinkautomat.model.CoinAndQuantity;

import java.util.List;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package drinkAutomat.common;
package main.drinkautomat.common;

/**
* The coin is initialised in cents.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package drinkAutomat.common;
package main.drinkautomat.common;

public class Drink extends ProductType {
public Drink(String name, double price) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package drinkAutomat.common;
package main.drinkautomat.common;

public abstract class ProductType {
protected String name;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package drinkAutomat.model;
package main.drinkautomat.model;

import drinkAutomat.common.CoinValue;
import main.drinkautomat.common.CoinValue;

public class Coin {

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package drinkAutomat.model;
package main.drinkautomat.model;

import drinkAutomat.common.CoinValue;
import main.drinkautomat.common.CoinValue;

/**
* This class is used to store change coins.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package drinkAutomat.model;
package main.drinkautomat.model;

import drinkAutomat.common.ProductType;
import main.drinkautomat.common.ProductType;

/**
* Generic class for compartment in the drink machine.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package drinkAutomat.model;
package main.drinkautomat.model;

import drinkAutomat.common.CoinValue;
import drinkAutomat.common.Drink;
import main.drinkautomat.common.CoinValue;
import main.drinkautomat.common.Drink;

import java.util.HashMap;
import java.util.List;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package drinkAutomat.model;
package main.drinkautomat.model;

import drinkAutomat.common.Automat;
import drinkAutomat.common.CoinValue;
import drinkAutomat.common.Drink;
import main.drinkautomat.common.Automat;
import main.drinkautomat.common.CoinValue;
import main.drinkautomat.common.Drink;

import java.util.ArrayList;
import java.util.Collections;
Expand All @@ -13,9 +13,9 @@
/**
* This class is an implementation of a drink machine, with the principal procedure.
*/
public class DrinkAutomat extends Automat {
public class DrinkMachine extends Automat {
public static final String NOT_MORE_AVAILABLE = "The drink name you choose is not more available";
public static final String NOT_ENOUGH_MONEY = "You do not given enough coins for the drink you need.";
public static final String NOT_ENOUGH_MONEY = "You have not given enough coins for the drink you need.";
public static final String NOT_ENOUGH_COINS_FOR_CHANGE = "Not enough coins for change";

HashMap<String, Compartment> compartments;
Expand All @@ -25,7 +25,7 @@ public class DrinkAutomat extends Automat {
/**
* @param compartments: Each compartment contents only one drink type.
*/
public DrinkAutomat(HashMap<String, Compartment> compartments) {
public DrinkMachine(HashMap<String, Compartment> compartments) {
this.returnMoney = new ArrayList<>();
this.availableCoinForChange = new ArrayList<>();
this.compartments = compartments;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package drinkAutomatTest;
package main.drinkautomatTest;

import drinkAutomat.common.CoinValue;
import drinkAutomat.common.Drink;
import drinkAutomat.model.*;
import main.drinkautomat.common.CoinValue;
import main.drinkautomat.common.Drink;
import main.drinkautomat.model.*;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;

Expand All @@ -15,11 +15,11 @@
public class testDrinkAutomat {

public static final String COLA = "Cola";
public static final String BIER = "Bier";
public static final String BEER = "Beer";
Drink cola;
Drink bier;
Drink beer;
Compartment<Drink> colaCompartment;
Compartment<Drink> bierCompartment;
Compartment<Drink> beerCompartment;
HashMap<String, Compartment> compartments;


Expand All @@ -30,12 +30,12 @@ public class testDrinkAutomat {
@BeforeEach
private void init() {
cola = new Drink(COLA, 1.20);
bier = new Drink(BIER, 2);
beer = new Drink(BEER, 2);
colaCompartment = new Compartment<>(cola, 2);
bierCompartment = new Compartment<>(bier, 2);
beerCompartment = new Compartment<>(beer, 2);
compartments = new HashMap<>();
compartments.put(cola.getName(), colaCompartment);
compartments.put(bier.getName(), bierCompartment);
compartments.put(beer.getName(), beerCompartment);
}

/**
Expand All @@ -44,7 +44,7 @@ private void init() {
*/
@Test
public void testReturnDrink() {
DrinkAutomat drinkAutomat = new DrinkAutomat(compartments);
DrinkMachine drinkAutomat = new DrinkMachine(compartments);
List<Coin> inputCoins = new ArrayList<>();
inputCoins.add(new Coin(CoinValue.FIFTY_CENT));
inputCoins.add(new Coin(CoinValue.FIFTY_CENT));
Expand All @@ -57,9 +57,9 @@ public void testReturnDrink() {
drinkAutomat.addAvailableCoinForChange(coin_20);
drinkAutomat.addAvailableCoinForChange(coin_50);

DrinkAndChange drinkAndChange = drinkAutomat.buy(bier, inputCoins);
DrinkAndChange drinkAndChange = drinkAutomat.buy(beer, inputCoins);

assertEquals(bier.getName(), drinkAndChange.getDrinkName());
assertEquals(beer.getName(), drinkAndChange.getDrinkName());
assertEquals(0, drinkAndChange.getChange().size());


Expand All @@ -76,28 +76,28 @@ public void testReturnChange() {
List<Coin> inputCoins = new ArrayList<>();
inputCoins.add(new Coin(CoinValue.TWO_EURO));

DrinkAutomat drinkAutomat = new DrinkAutomat(compartments);
DrinkMachine drinkMachine = new DrinkMachine(compartments);

/**
* Set coins for change
*/
CoinAndQuantity coin_50 = new CoinAndQuantity(CoinValue.FIFTY_CENT, 1);
CoinAndQuantity coin_20 = new CoinAndQuantity(CoinValue.TWENTY_CENT, 4);
CoinAndQuantity coin_10 = new CoinAndQuantity(CoinValue.TEN_CENT, 8);
drinkAutomat.addAvailableCoinForChange(coin_10);
drinkAutomat.addAvailableCoinForChange(coin_20);
drinkAutomat.addAvailableCoinForChange(coin_50);
drinkMachine.addAvailableCoinForChange(coin_10);
drinkMachine.addAvailableCoinForChange(coin_20);
drinkMachine.addAvailableCoinForChange(coin_50);

DrinkAndChange drinkAndChange = drinkAutomat.buy(cola, inputCoins);
DrinkAndChange drinkAndChange = drinkMachine.buy(cola, inputCoins);

assertEquals(cola.getName(), drinkAndChange.getDrinkName());
assertEquals(1, drinkAndChange.getChange().get(CoinValue.FIFTY_CENT));
assertEquals(1, drinkAndChange.getChange().get(CoinValue.TWENTY_CENT));
assertEquals(1, drinkAndChange.getChange().get(CoinValue.TEN_CENT));

assertEquals(3, drinkAutomat.getAvailableCoinForChange().size());
assertEquals(3, drinkMachine.getAvailableCoinForChange().size());

for (CoinAndQuantity coinAndQuantity : drinkAutomat.getAvailableCoinForChange()) {
for (CoinAndQuantity coinAndQuantity : drinkMachine.getAvailableCoinForChange()) {
assertNotEquals(CoinValue.FIFTY_CENT, coinAndQuantity.getType());
}
}
Expand All @@ -114,9 +114,9 @@ public void testNoExistingDrink() {
List<Coin> inputCoins = new ArrayList<>();
inputCoins.add(new Coin(CoinValue.TWO_EURO));

DrinkAutomat drinkAutomat = new DrinkAutomat(compartments);
DrinkMachine drinkMachine = new DrinkMachine(compartments);

DrinkAndChange drinkAndChange = drinkAutomat.buy(cola, inputCoins);
DrinkAndChange drinkAndChange = drinkMachine.buy(cola, inputCoins);
assertNull(drinkAndChange);
}

Expand All @@ -129,9 +129,9 @@ public void testNotEnoughCoinForDrink() {
List<Coin> inputCoins = new ArrayList<>();
inputCoins.add(new Coin(CoinValue.ONE_EURO));

DrinkAutomat drinkAutomat = new DrinkAutomat(compartments);
DrinkMachine drinkMachine = new DrinkMachine(compartments);

DrinkAndChange result = drinkAutomat.buy(cola, inputCoins);
DrinkAndChange result = drinkMachine.buy(cola, inputCoins);

assertNull(result);
}
Expand All @@ -147,14 +147,14 @@ public void testFillInChangeCoins() {

inputCoins.add(new Coin(CoinValue.TEN_CENT));

DrinkAutomat drinkAutomat = new DrinkAutomat(compartments);
DrinkMachine drinkMachine = new DrinkMachine(compartments);

assertEquals(0, drinkAutomat.getAvailableCoinForChange().size());
assertEquals(0, drinkMachine.getAvailableCoinForChange().size());

drinkAutomat.fillInWithCoin(inputCoins);
drinkMachine.fillInWithCoin(inputCoins);

assertEquals(1, drinkAutomat.getAvailableCoinForChange().size());
assertEquals(1, drinkMachine.getAvailableCoinForChange().size());

assertEquals(CoinValue.TEN_CENT, drinkAutomat.getAvailableCoinForChange().get(0).getType());
assertEquals(CoinValue.TEN_CENT, drinkMachine.getAvailableCoinForChange().get(0).getType());
}
}

0 comments on commit f0c030c

Please sign in to comment.