diff --git a/bin/ATM.class b/bin/ATM.class deleted file mode 100644 index 76543bf..0000000 Binary files a/bin/ATM.class and /dev/null differ diff --git a/bin/ATMCaseStudy.class b/bin/ATMCaseStudy.class deleted file mode 100644 index 607c10d..0000000 Binary files a/bin/ATMCaseStudy.class and /dev/null differ diff --git a/bin/Account.class b/bin/Account.class deleted file mode 100644 index 5d2d636..0000000 Binary files a/bin/Account.class and /dev/null differ diff --git a/bin/BalanceInquiry.class b/bin/BalanceInquiry.class deleted file mode 100644 index 48f8e6a..0000000 Binary files a/bin/BalanceInquiry.class and /dev/null differ diff --git a/bin/BankDatabase.class b/bin/BankDatabase.class deleted file mode 100644 index 429aec1..0000000 Binary files a/bin/BankDatabase.class and /dev/null differ diff --git a/bin/CashDispenser.class b/bin/CashDispenser.class deleted file mode 100644 index b8cedba..0000000 Binary files a/bin/CashDispenser.class and /dev/null differ diff --git a/bin/Deposit.class b/bin/Deposit.class deleted file mode 100644 index 57b0c3f..0000000 Binary files a/bin/Deposit.class and /dev/null differ diff --git a/bin/DepositSlot.class b/bin/DepositSlot.class deleted file mode 100644 index a2664ad..0000000 Binary files a/bin/DepositSlot.class and /dev/null differ diff --git a/bin/Keypad.class b/bin/Keypad.class deleted file mode 100644 index 9b066e2..0000000 Binary files a/bin/Keypad.class and /dev/null differ diff --git a/bin/Screen.class b/bin/Screen.class deleted file mode 100644 index a036758..0000000 Binary files a/bin/Screen.class and /dev/null differ diff --git a/bin/Transaction.class b/bin/Transaction.class deleted file mode 100644 index 1330b55..0000000 Binary files a/bin/Transaction.class and /dev/null differ diff --git a/bin/Withdrawal.class b/bin/Withdrawal.class deleted file mode 100644 index 291d645..0000000 Binary files a/bin/Withdrawal.class and /dev/null differ diff --git a/bin/code/Business_logic/Account.class b/bin/code/Business_logic/Account.class new file mode 100644 index 0000000..2829ec1 Binary files /dev/null and b/bin/code/Business_logic/Account.class differ diff --git a/bin/code/Business_logic/Euro.class b/bin/code/Business_logic/Euro.class new file mode 100644 index 0000000..f89b16f Binary files /dev/null and b/bin/code/Business_logic/Euro.class differ diff --git a/bin/code/Business_logic/Transaction.class b/bin/code/Business_logic/Transaction.class new file mode 100644 index 0000000..68d8813 Binary files /dev/null and b/bin/code/Business_logic/Transaction.class differ diff --git a/bin/code/Database/BankDatabase.class b/bin/code/Database/BankDatabase.class new file mode 100644 index 0000000..9b9d2c3 Binary files /dev/null and b/bin/code/Database/BankDatabase.class differ diff --git a/bin/code/GUI/ATM.class b/bin/code/GUI/ATM.class new file mode 100644 index 0000000..3502a2e Binary files /dev/null and b/bin/code/GUI/ATM.class differ diff --git a/bin/code/GUI/ATMCaseStudy.class b/bin/code/GUI/ATMCaseStudy.class new file mode 100644 index 0000000..7827cba Binary files /dev/null and b/bin/code/GUI/ATMCaseStudy.class differ diff --git a/bin/code/GUI/BalanceInquiry.class b/bin/code/GUI/BalanceInquiry.class new file mode 100644 index 0000000..39d5b6c Binary files /dev/null and b/bin/code/GUI/BalanceInquiry.class differ diff --git a/bin/code/GUI/CashDispenser.class b/bin/code/GUI/CashDispenser.class new file mode 100644 index 0000000..8e8c9be Binary files /dev/null and b/bin/code/GUI/CashDispenser.class differ diff --git a/bin/code/GUI/Deposit.class b/bin/code/GUI/Deposit.class new file mode 100644 index 0000000..e22bd28 Binary files /dev/null and b/bin/code/GUI/Deposit.class differ diff --git a/bin/code/GUI/DepositSlot.class b/bin/code/GUI/DepositSlot.class new file mode 100644 index 0000000..a9f296b Binary files /dev/null and b/bin/code/GUI/DepositSlot.class differ diff --git a/bin/code/GUI/Keypad.class b/bin/code/GUI/Keypad.class new file mode 100644 index 0000000..de79de6 Binary files /dev/null and b/bin/code/GUI/Keypad.class differ diff --git a/bin/code/GUI/Screen.class b/bin/code/GUI/Screen.class new file mode 100644 index 0000000..6c4d2b9 Binary files /dev/null and b/bin/code/GUI/Screen.class differ diff --git a/bin/code/GUI/Withdrawal.class b/bin/code/GUI/Withdrawal.class new file mode 100644 index 0000000..c999345 Binary files /dev/null and b/bin/code/GUI/Withdrawal.class differ diff --git a/bin/test/TestAccount.class b/bin/test/TestAccount.class new file mode 100644 index 0000000..d071baa Binary files /dev/null and b/bin/test/TestAccount.class differ diff --git a/bin/test/TestBankDatabase.class b/bin/test/TestBankDatabase.class new file mode 100644 index 0000000..83370a3 Binary files /dev/null and b/bin/test/TestBankDatabase.class differ diff --git a/bin/test/TestEuro.class b/bin/test/TestEuro.class new file mode 100644 index 0000000..e96cea8 Binary files /dev/null and b/bin/test/TestEuro.class differ diff --git a/lib/junit-platform-console-standalone-1.10.1.jar b/lib/junit-platform-console-standalone-1.10.1.jar new file mode 100644 index 0000000..75ee9b7 Binary files /dev/null and b/lib/junit-platform-console-standalone-1.10.1.jar differ diff --git a/src/Account.java b/src/code/Business_logic/Account.java similarity index 72% rename from src/Account.java rename to src/code/Business_logic/Account.java index c308eca..51211a1 100644 --- a/src/Account.java +++ b/src/code/Business_logic/Account.java @@ -1,3 +1,4 @@ +package code.Business_logic; // Account.java // Represents a bank account @@ -5,12 +6,22 @@ public class Account { private int accountNumber; // account number private int pin; // PIN for authentication - private double availableBalance; // funds available for withdrawal - private double totalBalance; // funds available + pending deposits + private Euro availableBalance; // funds available for withdrawal + private Euro totalBalance; // funds available + pending deposits // Account constructor initializes attributes public Account( int theAccountNumber, int thePIN, double theAvailableBalance, double theTotalBalance ) + { + accountNumber = theAccountNumber; + pin = thePIN; + availableBalance = new Euro(theAvailableBalance); + totalBalance = new Euro(theTotalBalance); + } // end Account constructor + + // Account constructor initializes attributes + public Account( int theAccountNumber, int thePIN, + Euro theAvailableBalance, Euro theTotalBalance ) { accountNumber = theAccountNumber; pin = thePIN; @@ -28,28 +39,28 @@ public boolean validatePIN( int userPIN ) } // end method validatePIN // returns available balance - public double getAvailableBalance() + public Euro getAvailableBalance() { return availableBalance; } // end getAvailableBalance // returns the total balance - public double getTotalBalance() + public Euro getTotalBalance() { return totalBalance; } // end method getTotalBalance // credits an amount to the account - public void credit( double amount ) + public void credit( Euro amount ) { - totalBalance += amount; // add to total balance + totalBalance.somma(amount); // add to total balance } // end method credit // debits an amount from the account - public void debit( double amount ) + public void debit( Euro amount ) { - availableBalance -= amount; // subtract from available balance - totalBalance -= amount; // subtract from total balance + availableBalance.sottrai(amount); // subtract from available balance + totalBalance.sottrai(amount); // subtract from total balance } // end method debit // returns account number diff --git a/src/code/Business_logic/Euro.java b/src/code/Business_logic/Euro.java new file mode 100644 index 0000000..8eedac4 --- /dev/null +++ b/src/code/Business_logic/Euro.java @@ -0,0 +1,52 @@ +package code.Business_logic; + +public class Euro { + private long valore; + public Euro(long euro, long cent){ + if(euro>=0){ + valore = euro * 100 + cent; + } else{ + valore = euro * 100 - cent; + } + } + + public Euro(double d){ + valore=(long)(d*100); + } + + public long getValore(){ + return valore; + } + + public double getValoreD(){ + return ((double)valore)/100; + } + + public Euro somma(Euro e){ + this.valore=this.valore+e.getValore(); + return this; + } + + public Euro sottrai(Euro e){ + this.valore=this.valore-e.getValore(); + return this; + } + + public boolean ugualeA(Euro e){ + if(valore==e.getValore()) + return true; + else + return false; + } + + public boolean minoreDi(Euro e){ + if(valore<=e.getValore()) + return true; + else + return false; + } + + public String stampa(){ + return (double)valore/100 +" euro"; + } +} \ No newline at end of file diff --git a/src/Transaction.java b/src/code/Business_logic/Transaction.java similarity index 96% rename from src/Transaction.java rename to src/code/Business_logic/Transaction.java index 508fea8..5256dca 100644 --- a/src/Transaction.java +++ b/src/code/Business_logic/Transaction.java @@ -1,6 +1,10 @@ +package code.Business_logic; // Transaction.java // Abstract superclass Transaction represents an ATM transaction +import code.Database.BankDatabase; +import code.GUI.Screen; + public abstract class Transaction { private int accountNumber; // indicates account involved diff --git a/src/BankDatabase.java b/src/code/Database/BankDatabase.java similarity index 91% rename from src/BankDatabase.java rename to src/code/Database/BankDatabase.java index 3978497..9a94c6e 100644 --- a/src/BankDatabase.java +++ b/src/code/Database/BankDatabase.java @@ -1,6 +1,10 @@ +package code.Database; // BankDatabase.java // Represents the bank account information database +import code.Business_logic.Account; +import code.Business_logic.Euro; + public class BankDatabase { private Account accounts[]; // array of Accounts @@ -42,25 +46,25 @@ public boolean authenticateUser( int userAccountNumber, int userPIN ) } // end method authenticateUser // return available balance of Account with specified account number - public double getAvailableBalance( int userAccountNumber ) + public Euro getAvailableBalance( int userAccountNumber ) { return getAccount( userAccountNumber ).getAvailableBalance(); } // end method getAvailableBalance // return total balance of Account with specified account number - public double getTotalBalance( int userAccountNumber ) + public Euro getTotalBalance( int userAccountNumber ) { return getAccount( userAccountNumber ).getTotalBalance(); } // end method getTotalBalance // credit an amount to Account with specified account number - public void credit( int userAccountNumber, double amount ) + public void credit( int userAccountNumber, Euro amount ) { getAccount( userAccountNumber ).credit( amount ); } // end method credit // debit an amount from of Account with specified account number - public void debit( int userAccountNumber, double amount ) + public void debit( int userAccountNumber, Euro amount ) { getAccount( userAccountNumber ).debit( amount ); } // end method debit diff --git a/src/ATM.java b/src/code/GUI/ATM.java similarity index 98% rename from src/ATM.java rename to src/code/GUI/ATM.java index aa3d187..8c07bd8 100644 --- a/src/ATM.java +++ b/src/code/GUI/ATM.java @@ -1,6 +1,10 @@ +package code.GUI; // ATM.java // Represents an automated teller machine +import code.Business_logic.Transaction; +import code.Database.BankDatabase; + public class ATM { private boolean userAuthenticated; // whether user is authenticated diff --git a/src/ATMCaseStudy.java b/src/code/GUI/ATMCaseStudy.java similarity index 98% rename from src/ATMCaseStudy.java rename to src/code/GUI/ATMCaseStudy.java index b9033bd..5beedde 100644 --- a/src/ATMCaseStudy.java +++ b/src/code/GUI/ATMCaseStudy.java @@ -1,3 +1,4 @@ +package code.GUI; // ATMCaseStudy.java // Driver program for the ATM case study diff --git a/src/BalanceInquiry.java b/src/code/GUI/BalanceInquiry.java similarity index 92% rename from src/BalanceInquiry.java rename to src/code/GUI/BalanceInquiry.java index d45fa6a..6c89fb8 100644 --- a/src/BalanceInquiry.java +++ b/src/code/GUI/BalanceInquiry.java @@ -1,6 +1,11 @@ +package code.GUI; // BalanceInquiry.java // Represents a balance inquiry ATM transaction +import code.Business_logic.Transaction; +import code.Business_logic.Euro; +import code.Database.BankDatabase; + public class BalanceInquiry extends Transaction { // BalanceInquiry constructor @@ -18,11 +23,11 @@ public void execute() Screen screen = getScreen(); // get the available balance for the account involved - double availableBalance = + Euro availableBalance = bankDatabase.getAvailableBalance( getAccountNumber() ); // get the total balance for the account involved - double totalBalance = + Euro totalBalance = bankDatabase.getTotalBalance( getAccountNumber() ); // display the balance information on the screen diff --git a/src/CashDispenser.java b/src/code/GUI/CashDispenser.java similarity index 72% rename from src/CashDispenser.java rename to src/code/GUI/CashDispenser.java index b249faf..f1ce3de 100644 --- a/src/CashDispenser.java +++ b/src/code/GUI/CashDispenser.java @@ -1,31 +1,34 @@ +package code.GUI; // CashDispenser.java // Represents the cash dispenser of the ATM +import code.Business_logic.Euro; + public class CashDispenser { // the default initial number of bills in the cash dispenser - private final static int INITIAL_COUNT = 500; - private int count; // number of $20 bills remaining + private final static Euro INITIAL_COUNT = new Euro(500,0); + private Euro count; // number of $20 bills remaining // no-argument CashDispenser constructor initializes count to default public CashDispenser() { - count = INITIAL_COUNT; // set count attribute to default + count = new Euro(INITIAL_COUNT.getValoreD()); // set count attribute to default } // end CashDispenser constructor // simulates dispensing of specified amount of cash - public void dispenseCash( int amount ) + public void dispenseCash( Euro amount ) { - int billsRequired = amount / 20; // number of $20 bills required - count -= billsRequired; // update the count of bills + Euro billsRequired = new Euro(amount.getValoreD() / 20); // number of $20 bills required + count.sottrai(billsRequired);// update the count of bills } // end method dispenseCash // indicates whether cash dispenser can dispense desired amount - public boolean isSufficientCashAvailable( int amount ) + public boolean isSufficientCashAvailable( Euro amount ) { - int billsRequired = amount / 20; // number of $20 bills required + Euro billsRequired = new Euro(amount.getValoreD() / 20); // number of $20 bills required - if ( count >= billsRequired ) + if ( billsRequired.minoreDi(count)) return true; // enough bills available else return false; // not enough bills available diff --git a/src/Deposit.java b/src/code/GUI/Deposit.java similarity index 93% rename from src/Deposit.java rename to src/code/GUI/Deposit.java index 916ef70..5185d3c 100644 --- a/src/Deposit.java +++ b/src/code/GUI/Deposit.java @@ -1,9 +1,14 @@ +package code.GUI; // Deposit.java // Represents a deposit ATM transaction +import code.Business_logic.Transaction; +import code.Business_logic.Euro; +import code.Database.BankDatabase; + public class Deposit extends Transaction { - private double amount; // amount to deposit + private Euro amount; // amount to deposit private Keypad keypad; // reference to keypad private DepositSlot depositSlot; // reference to deposit slot private final static int CANCELED = 0; // constant for cancel option @@ -27,10 +32,10 @@ public void execute() BankDatabase bankDatabase = getBankDatabase(); // get reference Screen screen = getScreen(); // get reference - amount = promptForDepositAmount(); // get deposit amount from user + amount = new Euro(promptForDepositAmount()); // get deposit amount from user // check whether user entered a deposit amount or canceled - if ( amount != CANCELED ) + if ( amount.getValore() != CANCELED ) { // request deposit envelope containing specified amount screen.displayMessage( diff --git a/src/DepositSlot.java b/src/code/GUI/DepositSlot.java similarity index 98% rename from src/DepositSlot.java rename to src/code/GUI/DepositSlot.java index 64e02c2..bde0339 100644 --- a/src/DepositSlot.java +++ b/src/code/GUI/DepositSlot.java @@ -1,3 +1,4 @@ +package code.GUI; // DepositSlot.java // Represents the deposit slot of the ATM diff --git a/src/Keypad.java b/src/code/GUI/Keypad.java similarity index 98% rename from src/Keypad.java rename to src/code/GUI/Keypad.java index cd035c7..f0f716c 100644 --- a/src/Keypad.java +++ b/src/code/GUI/Keypad.java @@ -1,3 +1,4 @@ +package code.GUI; // Keypad.java // Represents the keypad of the ATM import java.util.Scanner; // program uses Scanner to obtain user input diff --git a/src/Screen.java b/src/code/GUI/Screen.java similarity index 90% rename from src/Screen.java rename to src/code/GUI/Screen.java index 44d3f30..0d30020 100644 --- a/src/Screen.java +++ b/src/code/GUI/Screen.java @@ -1,6 +1,9 @@ +package code.GUI; // Screen.java // Represents the screen of the ATM +import code.Business_logic.Euro; + public class Screen { // displays a message without a carriage return @@ -16,9 +19,9 @@ public void displayMessageLine( String message ) } // end method displayMessageLine // display a dollar amount - public void displayDollarAmount( double amount ) + public void displayDollarAmount( Euro amount ) { - System.out.printf( "$%,.2f", amount ); + System.out.printf( "$%,.2f", amount.getValoreD()); } // end method displayDollarAmount } // end class Screen diff --git a/src/Withdrawal.java b/src/code/GUI/Withdrawal.java similarity index 92% rename from src/Withdrawal.java rename to src/code/GUI/Withdrawal.java index 6e0af62..4c48795 100644 --- a/src/Withdrawal.java +++ b/src/code/GUI/Withdrawal.java @@ -1,14 +1,19 @@ +package code.GUI; // Withdrawal.java // Represents a withdrawal ATM transaction +import code.Business_logic.Transaction; +import code.Business_logic.Euro; +import code.Database.BankDatabase; + public class Withdrawal extends Transaction { - private int amount; // amount to withdraw + private Euro amount; // amount to withdraw private Keypad keypad; // reference to keypad private CashDispenser cashDispenser; // reference to cash dispenser // constant corresponding to menu option to cancel - private final static int CANCELED = 6; + private final static int CANCELED = -1; // Withdrawal constructor public Withdrawal( int userAccountNumber, Screen atmScreen, @@ -27,8 +32,8 @@ public Withdrawal( int userAccountNumber, Screen atmScreen, public void execute() { boolean cashDispensed = false; // cash was not dispensed yet - double availableBalance; // amount available for withdrawal - + Euro availableBalance; // amount available for withdrawal + int userChoice; // get references to bank database and screen BankDatabase bankDatabase = getBankDatabase(); Screen screen = getScreen(); @@ -37,17 +42,18 @@ public void execute() do { // obtain a chosen withdrawal amount from the user - amount = displayMenuOfAmounts(); + userChoice = displayMenuOfAmounts(); // check whether user chose a withdrawal amount or canceled - if ( amount != CANCELED ) + if ( userChoice != CANCELED ) { + amount = new Euro(userChoice, 0); // get available balance of account involved availableBalance = bankDatabase.getAvailableBalance( getAccountNumber() ); // check whether the user has enough money in the account - if ( amount <= availableBalance ) + if ( amount.minoreDi(availableBalance) ) { // check whether the cash dispenser has enough money if ( cashDispenser.isSufficientCashAvailable( amount ) ) diff --git a/src/componenti.txt b/src/componenti.txt new file mode 100644 index 0000000..9ef6ed1 --- /dev/null +++ b/src/componenti.txt @@ -0,0 +1,3 @@ +Lorenzo, Rossi, S4961068 +Mattia, Donzella, S5229269 +Maura, Simiras, S5161685 \ No newline at end of file diff --git a/src/test/TestAccount.java b/src/test/TestAccount.java new file mode 100644 index 0000000..b015d27 --- /dev/null +++ b/src/test/TestAccount.java @@ -0,0 +1,50 @@ +package test; +import static org.junit.Assert.*; +import org.junit.*; + +import code.Business_logic.Account; +import code.Business_logic.Euro; +/* + * Questo file contiene i test della classe Account, i test dei costruttori (ne abbiamo aggiunto uno parallelo con il tipo Euro) + * sono stati divisi in modo che venisse valutato ogni parametro richiesto dal costruttore. + * Infine sono stati fatti i test dei due metodi pubblici principali, credit e deposit. +*/ + + +public class TestAccount { + //i test valgono anche per il Constructor B1, B2, B3, B4 + @Test //controllo dell'account number + public void testConstructorA1(){ + Account user= new Account(000001, 1234, 100.0, 100.0); + assertEquals(000001, user.getAccountNumber()); + + } + @Test //controllo avaiable balance + public void testConstructorA3(){ + Account user= new Account(000001, 1234, 100.0, 100.0); + assertEquals(100.0, user.getAvailableBalance().getValoreD(),0.01); + } + @Test //controllo total balance + public void testConstructorA4(){ + Account user= new Account(000001, 1234, 100.0, 100.0); + assertEquals(100.0, user.getTotalBalance().getValoreD(),0.01); + } + //--------------- + @Test //controllo funzione credit + public void TestCredit(){ + Account account = new Account(0001, 1234, 100.0, 100.0); + Euro amount = new Euro(50, 25); + account.credit(amount); + Euro totalBalance = account.getTotalBalance(); + assertEquals(150.25, totalBalance.getValoreD(), 0.01); + } + + @Test //controllo funzione debit + public void testDebit() { + Account account = new Account(0001, 1234, 100.0, 100.0); + Euro amount = new Euro(50, 25); + account.debit(amount); + Euro totalBalance = account.getTotalBalance(); + assertEquals(49.75, totalBalance.getValoreD(), 0.01); + } +} \ No newline at end of file diff --git a/src/test/TestBankDatabase.java b/src/test/TestBankDatabase.java new file mode 100644 index 0000000..728c89d --- /dev/null +++ b/src/test/TestBankDatabase.java @@ -0,0 +1,78 @@ +package test; + +import static org.junit.Assert.*; +import static org.junit.jupiter.api.Assertions.assertThrows; + +import org.junit.*; +import code.Database.BankDatabase; +import code.Business_logic.Euro; + +/* + * Questo file contiene i test della classe BankDatabase, i test coinvolgono le funzioni principali, + * i getter, l'authenticate (che viene analizzata in tutte le casistiche possibili: il caso in cui + * l'utente ed il pin siano corretti, il caso in cui l'utente sia corretto, ma il pin sbagliato ed il caso in cui + * l'utente sia sbagliato) + */ + +public class TestBankDatabase { + private BankDatabase element; + private Euro amount; + + @Before //setup iniziale per evitare di ripetere il codice + public void setup() { + element = new BankDatabase(); + amount = new Euro(1000); + } + + @Test //primo test per authenticate, caso di utente e pin corretti + public void Test_authenticateUser_true(){ + assertTrue(element.authenticateUser(12345, 54321)); + } + + @Test //secondo test per authenticate, caso di utente corretto e pin errato + public void Test_authenticateUser_wrongPin(){ + assertFalse(element.authenticateUser(12345, 130)); + } + + @Test //terzo ed ultimo test di authenticate, caso di utente errato + public void Test_authenticateUser_wrongUser(){ + assertFalse(element.authenticateUser(67890, 54321)); + } + + @Test //getter di avaible balance, caso in cui l'utente esista + public void Test_getAvaiableBalance_existentAccount(){ + int expectedAvaiableBalance = 1000; + assertEquals(expectedAvaiableBalance, (int)(element.getAvailableBalance(12345).getValoreD())); + } + @Test //getter di avaible balance, caso in cui l'utente non esista + public void Test_getAvaiableBalance_nonExistentAccount(){ + assertThrows(NullPointerException.class, ()->{ + element.getAvailableBalance(-1); + }); + } + + @Test //getter di total balance, caso in cui l'utente esista + public void Test_getTotalBalance_existentAccount(){ + int expectedTotalBalance = 1200; + assertEquals(expectedTotalBalance, (int)(element.getTotalBalance(12345).getValoreD())); + } + + @Test //getter di total balance, caso in cui l'utente non esista + public void Test_getTotalBalance_nonExistentAccount(){ + assertThrows(NullPointerException.class, ()->{ + element.getTotalBalance(-1); + }); + } + + @Test //test del metodo BankDatabase.credit + public void Test_credit(){ + element.credit(12345,amount); + assertEquals(2200, (int)element.getTotalBalance(12345).getValoreD()); + } + + @Test //test del metodo BankDatabase.debit + public void Test_deposit(){ + element.debit(12345, amount); + assertEquals(200, (int)element.getTotalBalance(12345).getValoreD()); + } +} \ No newline at end of file diff --git a/src/test/TestEuro.java b/src/test/TestEuro.java new file mode 100644 index 0000000..66c70ad --- /dev/null +++ b/src/test/TestEuro.java @@ -0,0 +1,100 @@ +package test; + +import static org.junit.Assert.*; +import org.junit.*; + +import code.Business_logic.Euro; + +/*Questo file contiene i test della classe Euro, passa attraverso i costruttori principali + * A -> intero,intero + * B -> double + * e procede attraverso tutte le funzioni di variazione e confronto che sono disponibili + * nella suddetta classe. + */ + +public class TestEuro { + @Test + public void testConstructorA1(){ + Euro element = new Euro(1000, 30); + assertEquals(100030,element.getValore()); + } + + @Test + public void testConstructorA2(){ + Euro element = new Euro(-1000, 30); + assertEquals(-100030,element.getValore()); + } + + @Test + public void testConstructorB1(){ + Euro element = new Euro(12.34); + assertEquals(1234,element.getValore()); + } + + @Test //test del metodo somma + public void testSomma(){ + double num1 = 56789.23; + double num2 = 12345.67; + Euro a = new Euro(num1); + Euro b = new Euro(num2); + a.somma(b); + assertEquals((long)((num1+num2)*100),a.getValore()); + } + + @Test//test del metodo sottrai + public void testSottrai(){ + double num1 = 56789.23; + double num2 = 12345.67; + Euro a = new Euro(num1); + Euro b = new Euro(num2); + a.sottrai(b); + assertEquals((long)((num1-num2)*100),a.getValore()); + } + + @Test //test del metodo uguale 1 + public void testUgualea(){ + double num1 = 12345.67; + double num2 = 12345.67; + Euro a = new Euro(num1); + Euro b = new Euro(num2); + assertEquals(a.getValore(),b.getValore()); + assertTrue(a.ugualeA(b)); + } + + @Test //test del metodo uguale 2 + public void testUgualea2(){ + double num1 = 12345.22; + double num2 = 12345.67; + Euro a = new Euro(num1); + Euro b = new Euro(num2); + assertNotEquals(a.getValore(),b.getValore()); + assertFalse(a.ugualeA(b)); + } + + @Test //test 1 del metodo minore di + public void testMinoreDi_1(){ + double num1 = 12345.67; + double num2 = 12.34; + Euro a = new Euro(num1); + Euro b = new Euro(num2); + assertTrue(a.getValore()>=b.getValore()); + assertTrue(b.minoreDi(a)); + } + + @Test //test 2 del metodo minore di + public void testMinoreDi_2(){ + double num1 = 12345.67; + double num2 = 12.34; + Euro a = new Euro(num1); + Euro b = new Euro(num2); + assertFalse(a.minoreDi(b)); + } + + @Test //test del metodo stampa + public void stampa(){ + String s="12345.67 euro"; + Euro euro=new Euro(12345.67); + assertEquals(s,euro.stampa()); + } + +} \ No newline at end of file