From 423356e85990a0f88b6d33e93475fa42406e1474 Mon Sep 17 00:00:00 2001 From: Stephen Date: Wed, 22 Jan 2020 14:35:21 -0500 Subject: [PATCH 01/29] inclass work. Created new tests --- .gitignore | 2 ++ .idea/encodings.xml | 1 + .idea/misc.xml | 2 +- .idea/vcs.xml | 6 ++++++ SoftwareEngineeringPractice.iml | 2 -- .../ithaca/dragon/bank/BankAccountTest.java | 20 +++++++++++++++++++ 6 files changed, 30 insertions(+), 3 deletions(-) create mode 100644 .idea/vcs.xml delete mode 100644 SoftwareEngineeringPractice.iml diff --git a/.gitignore b/.gitignore index 3c8b8dd5..4cc292d8 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,5 @@ +target/ + # Covers JetBrains IDEs: IntelliJ, RubyMine, PhpStorm, AppCode, PyCharm, CLion, Android Studio and WebStorm # Reference: https://intellij-support.jetbrains.com/hc/en-us/articles/206544839 diff --git a/.idea/encodings.xml b/.idea/encodings.xml index b26911bd..fade66b8 100644 --- a/.idea/encodings.xml +++ b/.idea/encodings.xml @@ -2,5 +2,6 @@ + \ No newline at end of file diff --git a/.idea/misc.xml b/.idea/misc.xml index d87af9ac..7548b72e 100644 --- a/.idea/misc.xml +++ b/.idea/misc.xml @@ -8,7 +8,7 @@ - + \ No newline at end of file diff --git a/.idea/vcs.xml b/.idea/vcs.xml new file mode 100644 index 00000000..94a25f7f --- /dev/null +++ b/.idea/vcs.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/SoftwareEngineeringPractice.iml b/SoftwareEngineeringPractice.iml deleted file mode 100644 index 78b2cc53..00000000 --- a/SoftwareEngineeringPractice.iml +++ /dev/null @@ -1,2 +0,0 @@ - - \ No newline at end of file diff --git a/src/test/java/edu/ithaca/dragon/bank/BankAccountTest.java b/src/test/java/edu/ithaca/dragon/bank/BankAccountTest.java index d19ecb02..00103482 100644 --- a/src/test/java/edu/ithaca/dragon/bank/BankAccountTest.java +++ b/src/test/java/edu/ithaca/dragon/bank/BankAccountTest.java @@ -25,6 +25,26 @@ void withdrawTest() { void isEmailValidTest(){ assertTrue(BankAccount.isEmailValid( "a@b.com")); assertFalse( BankAccount.isEmailValid("")); + + assertFalse(BankAccount.isEmailValid("a..b@male.com")); + assertFalse(BankAccount.isEmailValid("abc-@mail.com")); + assertFalse(BankAccount.isEmailValid(".abc@mail.com")); + assertFalse(BankAccount.isEmailValid("abc#def@mail.com")); + + assertTrue(BankAccount.isEmailValid("abc-d@mail.com")); + assertTrue(BankAccount.isEmailValid("abc.def@mail.com")); + assertTrue(BankAccount.isEmailValid("abc@mail.com")); + assertTrue(BankAccount.isEmailValid("abc_def@mail.com")); + + assertFalse(BankAccount.isEmailValid("abc.def@mail.c")); + assertFalse(BankAccount.isEmailValid("abc.def@mail#archive.com")); + assertFalse(BankAccount.isEmailValid("bc.def@mail")); + assertFalse(BankAccount.isEmailValid("abc.def@mail..com")); + + assertTrue(BankAccount.isEmailValid("abc.def@mail.cc")); + assertTrue(BankAccount.isEmailValid("abc.def@mail-archive.com")); + assertTrue(BankAccount.isEmailValid("abc.def@mail.org")); + assertTrue(BankAccount.isEmailValid("abc.def@mail.com")); } @Test From 9313e80c30bdb4a09995bd635fb9775b06a03393 Mon Sep 17 00:00:00 2001 From: jmendezdietsch Date: Wed, 22 Jan 2020 19:41:32 -0500 Subject: [PATCH 02/29] BankAccount is email valid given a definition --- .idea/compiler.xml | 1 + .idea/misc.xml | 2 +- .../edu/ithaca/dragon/bank/BankAccount.java | 42 ++++++++++++++++++- .../ithaca/dragon/bank/BankAccountTest.java | 3 ++ 4 files changed, 46 insertions(+), 2 deletions(-) diff --git a/.idea/compiler.xml b/.idea/compiler.xml index 28c6362f..b6353da8 100644 --- a/.idea/compiler.xml +++ b/.idea/compiler.xml @@ -6,6 +6,7 @@ + diff --git a/.idea/misc.xml b/.idea/misc.xml index 7548b72e..b8266aca 100644 --- a/.idea/misc.xml +++ b/.idea/misc.xml @@ -8,7 +8,7 @@ - + \ No newline at end of file diff --git a/src/main/java/edu/ithaca/dragon/bank/BankAccount.java b/src/main/java/edu/ithaca/dragon/bank/BankAccount.java index e340e0ea..28442369 100644 --- a/src/main/java/edu/ithaca/dragon/bank/BankAccount.java +++ b/src/main/java/edu/ithaca/dragon/bank/BankAccount.java @@ -39,7 +39,47 @@ public static boolean isEmailValid(String email){ if (email.indexOf('@') == -1){ return false; } - else { + + else if(email.indexOf(".") == 0){ + return false; + } + + else if(email.indexOf("..") != -1){ + return false; + } + + + else if(email.indexOf("-@") != -1){ + return false; + } + + else if(email.indexOf("#") != -1){ + return false; + } + + else{ + String emDomain = email.substring(email.indexOf("@")); + + if(emDomain.indexOf(".") == -1){ + return false; + } + + else if(emDomain.indexOf("#") != -1){ + return false; + } + + String emEnd = emDomain.substring(emDomain.indexOf(".")); + + //Check if end portion length is less than 2 and 3 but not checking + //All other tests passed + if(emEnd.length() < 2 && emEnd.length() < 3){ + return false; + } + + else if(emDomain.indexOf(".") == -1){ + return false; + } + return true; } } diff --git a/src/test/java/edu/ithaca/dragon/bank/BankAccountTest.java b/src/test/java/edu/ithaca/dragon/bank/BankAccountTest.java index 00103482..495a8e1a 100644 --- a/src/test/java/edu/ithaca/dragon/bank/BankAccountTest.java +++ b/src/test/java/edu/ithaca/dragon/bank/BankAccountTest.java @@ -36,7 +36,10 @@ void isEmailValidTest(){ assertTrue(BankAccount.isEmailValid("abc@mail.com")); assertTrue(BankAccount.isEmailValid("abc_def@mail.com")); + //The BankAccount check for this is not working assertFalse(BankAccount.isEmailValid("abc.def@mail.c")); + + //All other tests passed assertFalse(BankAccount.isEmailValid("abc.def@mail#archive.com")); assertFalse(BankAccount.isEmailValid("bc.def@mail")); assertFalse(BankAccount.isEmailValid("abc.def@mail..com")); From 4a00338b161f7a3b3acad6234d07d075ff66423d Mon Sep 17 00:00:00 2001 From: jmendezdietsch Date: Wed, 22 Jan 2020 20:12:20 -0500 Subject: [PATCH 03/29] Gave withdraw tests as well as described how to fix withdraw tests to pass --- .../java/edu/ithaca/dragon/bank/BankAccount.java | 13 +++++++++++-- .../edu/ithaca/dragon/bank/BankAccountTest.java | 9 +++++++++ 2 files changed, 20 insertions(+), 2 deletions(-) diff --git a/src/main/java/edu/ithaca/dragon/bank/BankAccount.java b/src/main/java/edu/ithaca/dragon/bank/BankAccount.java index 28442369..101c8f9e 100644 --- a/src/main/java/edu/ithaca/dragon/bank/BankAccount.java +++ b/src/main/java/edu/ithaca/dragon/bank/BankAccount.java @@ -28,10 +28,19 @@ public String getEmail(){ /** * @post reduces the balance by amount if amount is non-negative and smaller than balance + if the amount is less than 0 + print out "Amount wanted is less than 0" error + Don't change the original balance + + if the amount is less than the current balance + print out "Amount wanted is less than the current balance" error + Don't change the original balance + + if all past if statements failed/was not used + subtract the amount from the current balance regularly */ - public void withdraw (double amount) { + public void withdraw (double amount){ balance -= amount; - } diff --git a/src/test/java/edu/ithaca/dragon/bank/BankAccountTest.java b/src/test/java/edu/ithaca/dragon/bank/BankAccountTest.java index 495a8e1a..c01cd6aa 100644 --- a/src/test/java/edu/ithaca/dragon/bank/BankAccountTest.java +++ b/src/test/java/edu/ithaca/dragon/bank/BankAccountTest.java @@ -19,6 +19,15 @@ void withdrawTest() { bankAccount.withdraw(100); assertEquals(100, bankAccount.getBalance()); + + //Added tests + BankAccount newAccount1 = new BankAccount("c@d.com", 200); + newAccount1.withdraw( 300); + assertEquals(200, newAccount1.getBalance()); + + BankAccount newAccount2 = new BankAccount("c@d.com", 200); + newAccount2.withdraw(-200); + assertEquals(200, newAccount2.getBalance()); } @Test From 615fb77e4be90b629731bf24fe3735e69d869c3c Mon Sep 17 00:00:00 2001 From: jmendezdietsch Date: Wed, 22 Jan 2020 22:13:10 -0500 Subject: [PATCH 04/29] Comments about partitions and boundary values added to withraw and valid email tests --- .../edu/ithaca/dragon/bank/BankAccount.java | 32 +++++++++------- .../ithaca/dragon/bank/BankAccountTest.java | 38 +++++++++++++++++-- 2 files changed, 54 insertions(+), 16 deletions(-) diff --git a/src/main/java/edu/ithaca/dragon/bank/BankAccount.java b/src/main/java/edu/ithaca/dragon/bank/BankAccount.java index 101c8f9e..065a676a 100644 --- a/src/main/java/edu/ithaca/dragon/bank/BankAccount.java +++ b/src/main/java/edu/ithaca/dragon/bank/BankAccount.java @@ -32,6 +32,9 @@ public String getEmail(){ print out "Amount wanted is less than 0" error Don't change the original balance + if the amount is 0 + return the balance as is/do nothing and have the subtraction be 0 + if the amount is less than the current balance print out "Amount wanted is less than the current balance" error Don't change the original balance @@ -45,6 +48,9 @@ public void withdraw (double amount){ public static boolean isEmailValid(String email){ + if(email == ""){ + return false; + } if (email.indexOf('@') == -1){ return false; } @@ -76,20 +82,20 @@ else if(email.indexOf("#") != -1){ else if(emDomain.indexOf("#") != -1){ return false; } - - String emEnd = emDomain.substring(emDomain.indexOf(".")); - - //Check if end portion length is less than 2 and 3 but not checking - //All other tests passed - if(emEnd.length() < 2 && emEnd.length() < 3){ - return false; - } - - else if(emDomain.indexOf(".") == -1){ - return false; + else { + String emEnd = emDomain.substring(emDomain.indexOf(".")); + + /** + * Check if end portion length is less than 2 and 3 but not checking + * All other tests passed + */ + if (emEnd.length() < 2 && emEnd.length() < 3) { + return false; + } else if (emDomain.indexOf(".") == -1) { + return false; + } } - - return true; } + return true; } } diff --git a/src/test/java/edu/ithaca/dragon/bank/BankAccountTest.java b/src/test/java/edu/ithaca/dragon/bank/BankAccountTest.java index c01cd6aa..774d74f0 100644 --- a/src/test/java/edu/ithaca/dragon/bank/BankAccountTest.java +++ b/src/test/java/edu/ithaca/dragon/bank/BankAccountTest.java @@ -20,14 +20,38 @@ void withdrawTest() { assertEquals(100, bankAccount.getBalance()); - //Added tests + //New tests + //Partitions of -0.01=invalid partition, 0.00->100.0 first, 101.00->200.00 second, 201.00+ third + + //Equivalence class above the maximum balance as a third, with a invalid boundary value above 200.00 maximum BankAccount newAccount1 = new BankAccount("c@d.com", 200); newAccount1.withdraw( 300); assertEquals(200, newAccount1.getBalance()); + //Equivalence class less being an invalid partition, with the boundary value of -0.01 BankAccount newAccount2 = new BankAccount("c@d.com", 200); newAccount2.withdraw(-200); assertEquals(200, newAccount2.getBalance()); + + //Equivalence class being valid with a staring partition of 0 with first, with boundary value 0.00 + BankAccount newAccount3 = new BankAccount("c@d.com", 200); + newAccount3.withdraw(0); + assertEquals(200, newAccount3.getBalance()); + + //Equivalence class being valid as the maximum partition with second, with a boundary value of 200.00 maximum + BankAccount newAccount4 = new BankAccount("c@d.com", 200); + newAccount4.withdraw(200); + assertEquals(0, newAccount4.getBalance()); + + //Equivalence class being valid as the second partition, with a boundary value of 0.00 and 100.00 maximum + BankAccount newAccount5 = new BankAccount("c@d.com", 200); + newAccount5.withdraw(67); + assertEquals(133, newAccount5.getBalance()); + + //Equivalence class being valid as the third partition, with a boundary value between 101.00 and 200.00 maximum + BankAccount newAccount6 = new BankAccount("c@d.com", 200); + newAccount6.withdraw(146); + assertEquals(54, newAccount6.getBalance()); } @Test @@ -35,24 +59,32 @@ void isEmailValidTest(){ assertTrue(BankAccount.isEmailValid( "a@b.com")); assertFalse( BankAccount.isEmailValid("")); + //Partitions of ""=invalid partition, address first, domain second, extension third + + //Equivalence class being in first partitions, with boundary value to index[0]->indexOf(@) assertFalse(BankAccount.isEmailValid("a..b@male.com")); assertFalse(BankAccount.isEmailValid("abc-@mail.com")); assertFalse(BankAccount.isEmailValid(".abc@mail.com")); assertFalse(BankAccount.isEmailValid("abc#def@mail.com")); + //Equivalence class being in first partitions, with boundary value to index[0]->indexOf(@) assertTrue(BankAccount.isEmailValid("abc-d@mail.com")); assertTrue(BankAccount.isEmailValid("abc.def@mail.com")); assertTrue(BankAccount.isEmailValid("abc@mail.com")); assertTrue(BankAccount.isEmailValid("abc_def@mail.com")); - //The BankAccount check for this is not working + /** + * The BankAccount check for this is not working + */ + //Equivalence class being in third partition, with boundary value to indexOf(".") to end) assertFalse(BankAccount.isEmailValid("abc.def@mail.c")); - //All other tests passed + //Equivalence class being in second partitions, with boundary value to indexOf("@")->indexOf(".") assertFalse(BankAccount.isEmailValid("abc.def@mail#archive.com")); assertFalse(BankAccount.isEmailValid("bc.def@mail")); assertFalse(BankAccount.isEmailValid("abc.def@mail..com")); + //Equivalence class being in second partitions, with boundary value to indexOf("@)->indexOf(extensions) assertTrue(BankAccount.isEmailValid("abc.def@mail.cc")); assertTrue(BankAccount.isEmailValid("abc.def@mail-archive.com")); assertTrue(BankAccount.isEmailValid("abc.def@mail.org")); From 117b1244fbce372bb3eb584bc177382e2f3714f1 Mon Sep 17 00:00:00 2001 From: jmendezdietsch Date: Wed, 22 Jan 2020 22:17:59 -0500 Subject: [PATCH 05/29] isEmailValid updated so all tests pass --- src/main/java/edu/ithaca/dragon/bank/BankAccount.java | 6 +----- src/test/java/edu/ithaca/dragon/bank/BankAccountTest.java | 8 +++----- 2 files changed, 4 insertions(+), 10 deletions(-) diff --git a/src/main/java/edu/ithaca/dragon/bank/BankAccount.java b/src/main/java/edu/ithaca/dragon/bank/BankAccount.java index 065a676a..80336b20 100644 --- a/src/main/java/edu/ithaca/dragon/bank/BankAccount.java +++ b/src/main/java/edu/ithaca/dragon/bank/BankAccount.java @@ -85,11 +85,7 @@ else if(emDomain.indexOf("#") != -1){ else { String emEnd = emDomain.substring(emDomain.indexOf(".")); - /** - * Check if end portion length is less than 2 and 3 but not checking - * All other tests passed - */ - if (emEnd.length() < 2 && emEnd.length() < 3) { + if (emEnd.length() < 3 && emEnd.length() < 4) { return false; } else if (emDomain.indexOf(".") == -1) { return false; diff --git a/src/test/java/edu/ithaca/dragon/bank/BankAccountTest.java b/src/test/java/edu/ithaca/dragon/bank/BankAccountTest.java index 774d74f0..ecca6562 100644 --- a/src/test/java/edu/ithaca/dragon/bank/BankAccountTest.java +++ b/src/test/java/edu/ithaca/dragon/bank/BankAccountTest.java @@ -73,15 +73,13 @@ void isEmailValidTest(){ assertTrue(BankAccount.isEmailValid("abc@mail.com")); assertTrue(BankAccount.isEmailValid("abc_def@mail.com")); - /** - * The BankAccount check for this is not working - */ - //Equivalence class being in third partition, with boundary value to indexOf(".") to end) + //Equivalence class being in second partitions, with boundary value to indexOf(".")->end assertFalse(BankAccount.isEmailValid("abc.def@mail.c")); - //Equivalence class being in second partitions, with boundary value to indexOf("@")->indexOf(".") assertFalse(BankAccount.isEmailValid("abc.def@mail#archive.com")); + //Equivalence class being in third partitions, with boundary value to indexOf("@")->end assertFalse(BankAccount.isEmailValid("bc.def@mail")); + //Equivalence class being in second partitions, with boundary value to indexOf("@")->indexOf(".") assertFalse(BankAccount.isEmailValid("abc.def@mail..com")); //Equivalence class being in second partitions, with boundary value to indexOf("@)->indexOf(extensions) From e1f225dc4a3be946c36804262ca3c2999437e6e2 Mon Sep 17 00:00:00 2001 From: Stephen Date: Fri, 24 Jan 2020 15:17:05 -0500 Subject: [PATCH 06/29] switching to desktop --- .idea/SoftwareEngineeringPractice.iml | 2 ++ .idea/misc.xml | 2 +- .../edu/ithaca/dragon/bank/BankAccount.java | 2 +- .../ithaca/dragon/bank/BankAccountTest.java | 23 +++++++++++++++---- 4 files changed, 22 insertions(+), 7 deletions(-) create mode 100644 .idea/SoftwareEngineeringPractice.iml diff --git a/.idea/SoftwareEngineeringPractice.iml b/.idea/SoftwareEngineeringPractice.iml new file mode 100644 index 00000000..78b2cc53 --- /dev/null +++ b/.idea/SoftwareEngineeringPractice.iml @@ -0,0 +1,2 @@ + + \ No newline at end of file diff --git a/.idea/misc.xml b/.idea/misc.xml index b8266aca..7548b72e 100644 --- a/.idea/misc.xml +++ b/.idea/misc.xml @@ -8,7 +8,7 @@ - + \ No newline at end of file diff --git a/src/main/java/edu/ithaca/dragon/bank/BankAccount.java b/src/main/java/edu/ithaca/dragon/bank/BankAccount.java index 80336b20..89c98676 100644 --- a/src/main/java/edu/ithaca/dragon/bank/BankAccount.java +++ b/src/main/java/edu/ithaca/dragon/bank/BankAccount.java @@ -42,7 +42,7 @@ public String getEmail(){ if all past if statements failed/was not used subtract the amount from the current balance regularly */ - public void withdraw (double amount){ + public void withdraw (double amount) throws InsufficientFundsException{ balance -= amount; } diff --git a/src/test/java/edu/ithaca/dragon/bank/BankAccountTest.java b/src/test/java/edu/ithaca/dragon/bank/BankAccountTest.java index ecca6562..ad486a8b 100644 --- a/src/test/java/edu/ithaca/dragon/bank/BankAccountTest.java +++ b/src/test/java/edu/ithaca/dragon/bank/BankAccountTest.java @@ -14,7 +14,7 @@ void getBalanceTest() { } @Test - void withdrawTest() { + void withdrawTest() throws InsufficientFundsException{ BankAccount bankAccount = new BankAccount("a@b.com", 200); bankAccount.withdraw(100); @@ -62,16 +62,29 @@ void isEmailValidTest(){ //Partitions of ""=invalid partition, address first, domain second, extension third //Equivalence class being in first partitions, with boundary value to index[0]->indexOf(@) + //Multiple periods Partition tests assertFalse(BankAccount.isEmailValid("a..b@male.com")); + assertTrue(BankAccount.isEmailValid("a.f.a@tah.com")); + assertTrue(BankAccount.isEmailValid("a.ffff.a@gasd.asd")); + assertFalse(BankAccount.isEmailValid("a...f@asdf.asd")); + + //Slash partitionTest assertFalse(BankAccount.isEmailValid("abc-@mail.com")); + assertTrue(BankAccount.isEmailValid("abc-d@mail.com")); + + //Invalid period Location assertFalse(BankAccount.isEmailValid(".abc@mail.com")); - assertFalse(BankAccount.isEmailValid("abc#def@mail.com")); + assertTrue(BankAccount.isEmailValid("a.a@gasd.com")); - //Equivalence class being in first partitions, with boundary value to index[0]->indexOf(@) - assertTrue(BankAccount.isEmailValid("abc-d@mail.com")); - assertTrue(BankAccount.isEmailValid("abc.def@mail.com")); + //Invalid Character Partitions + assertFalse(BankAccount.isEmailValid("abc#def@mail.com")); assertTrue(BankAccount.isEmailValid("abc@mail.com")); assertTrue(BankAccount.isEmailValid("abc_def@mail.com")); + assertFalse(BankAccount.isEmailValid("abc.def@mail#archive.com")); + //Equivalence class being in first partitions, with boundary value to index[0]->indexOf(@) + + assertTrue(BankAccount.isEmailValid("abc.def@mail.com")); + //Equivalence class being in second partitions, with boundary value to indexOf(".")->end assertFalse(BankAccount.isEmailValid("abc.def@mail.c")); From 9b3cbcd4ece50aa3a1458522158d28febbf61d10 Mon Sep 17 00:00:00 2001 From: Stephen Date: Fri, 24 Jan 2020 20:17:03 -0500 Subject: [PATCH 07/29] updated tests --- .idea/misc.xml | 5 +- .../ithaca/dragon/bank/BankAccountTest.java | 89 +++++++++---------- 2 files changed, 47 insertions(+), 47 deletions(-) diff --git a/.idea/misc.xml b/.idea/misc.xml index 7548b72e..70edba37 100644 --- a/.idea/misc.xml +++ b/.idea/misc.xml @@ -1,6 +1,9 @@ + + - + \ No newline at end of file diff --git a/src/test/java/edu/ithaca/dragon/bank/BankAccountTest.java b/src/test/java/edu/ithaca/dragon/bank/BankAccountTest.java index ad486a8b..3b03d4d0 100644 --- a/src/test/java/edu/ithaca/dragon/bank/BankAccountTest.java +++ b/src/test/java/edu/ithaca/dragon/bank/BankAccountTest.java @@ -8,9 +8,17 @@ class BankAccountTest { @Test void getBalanceTest() { + //Equivalence Class starting positive balance BankAccount bankAccount = new BankAccount("a@b.com", 200); - assertEquals(200, bankAccount.getBalance()); + bankAccount = new BankAccount("a@b.com", 0); + assertEquals(0, bankAccount.getBalance()); + + //Equivalence Class Negative Starting Balance + bankAccount = new BankAccount("a@b.com", -200); + assertEquals(-200, bankAccount.getBalance()); + bankAccount = new BankAccount("a@b.com", -1); + assertEquals(-1, bankAccount.getBalance()); } @Test @@ -20,38 +28,26 @@ void withdrawTest() throws InsufficientFundsException{ assertEquals(100, bankAccount.getBalance()); - //New tests - //Partitions of -0.01=invalid partition, 0.00->100.0 first, 101.00->200.00 second, 201.00+ third - - //Equivalence class above the maximum balance as a third, with a invalid boundary value above 200.00 maximum - BankAccount newAccount1 = new BankAccount("c@d.com", 200); - newAccount1.withdraw( 300); - assertEquals(200, newAccount1.getBalance()); - - //Equivalence class less being an invalid partition, with the boundary value of -0.01 - BankAccount newAccount2 = new BankAccount("c@d.com", 200); - newAccount2.withdraw(-200); - assertEquals(200, newAccount2.getBalance()); - - //Equivalence class being valid with a staring partition of 0 with first, with boundary value 0.00 - BankAccount newAccount3 = new BankAccount("c@d.com", 200); - newAccount3.withdraw(0); - assertEquals(200, newAccount3.getBalance()); - - //Equivalence class being valid as the maximum partition with second, with a boundary value of 200.00 maximum - BankAccount newAccount4 = new BankAccount("c@d.com", 200); - newAccount4.withdraw(200); - assertEquals(0, newAccount4.getBalance()); - - //Equivalence class being valid as the second partition, with a boundary value of 0.00 and 100.00 maximum - BankAccount newAccount5 = new BankAccount("c@d.com", 200); - newAccount5.withdraw(67); - assertEquals(133, newAccount5.getBalance()); - - //Equivalence class being valid as the third partition, with a boundary value between 101.00 and 200.00 maximum - BankAccount newAccount6 = new BankAccount("c@d.com", 200); - newAccount6.withdraw(146); - assertEquals(54, newAccount6.getBalance()); + //Equivalence Class Has balance + BankAccount bankAccount1 = new BankAccount("a@c.com", 300); + bankAccount1.withdraw(100);//valid withdraw + assertEquals(200, bankAccount1.getBalance()); + bankAccount1.withdraw(0);//valid withdraw edgecase + assertEquals(200, bankAccount1.getBalance()); + bankAccount1.withdraw(201);//overdraw + assertEquals(200, bankAccount1.getBalance()); + bankAccount1.withdraw(20100);//major overdraw + assertEquals(200, bankAccount1.getBalance()); + bankAccount1.withdraw(200);//perfect withdraw edgecase + assertEquals(0, bankAccount1.getBalance()); + + //Equivalence Class No balance + BankAccount ba2 = new BankAccount("a@c.cm", 0); + ba2.withdraw(0); //only valid withdraw + assertEquals(0, ba2.getBalance()); + ba2.withdraw(1);//overdraw + assertEquals(0, ba2.getBalance()); + } @Test @@ -67,6 +63,7 @@ void isEmailValidTest(){ assertTrue(BankAccount.isEmailValid("a.f.a@tah.com")); assertTrue(BankAccount.isEmailValid("a.ffff.a@gasd.asd")); assertFalse(BankAccount.isEmailValid("a...f@asdf.asd")); + assertFalse(BankAccount.isEmailValid("abc.def@mail..com")); //Only one is allowed in the second half regardless //Slash partitionTest assertFalse(BankAccount.isEmailValid("abc-@mail.com")); @@ -75,31 +72,31 @@ void isEmailValidTest(){ //Invalid period Location assertFalse(BankAccount.isEmailValid(".abc@mail.com")); assertTrue(BankAccount.isEmailValid("a.a@gasd.com")); + assertTrue(BankAccount.isEmailValid("abc.def@mail.com")); //Invalid Character Partitions assertFalse(BankAccount.isEmailValid("abc#def@mail.com")); + assertFalse(BankAccount.isEmailValid("abc.def@mail#archive.com")); assertTrue(BankAccount.isEmailValid("abc@mail.com")); assertTrue(BankAccount.isEmailValid("abc_def@mail.com")); - assertFalse(BankAccount.isEmailValid("abc.def@mail#archive.com")); - //Equivalence class being in first partitions, with boundary value to index[0]->indexOf(@) - assertTrue(BankAccount.isEmailValid("abc.def@mail.com")); - - - //Equivalence class being in second partitions, with boundary value to indexOf(".")->end + //Equivalence class Short or missing extentions assertFalse(BankAccount.isEmailValid("abc.def@mail.c")); - //Equivalence class being in second partitions, with boundary value to indexOf("@")->indexOf(".") - assertFalse(BankAccount.isEmailValid("abc.def@mail#archive.com")); - //Equivalence class being in third partitions, with boundary value to indexOf("@")->end assertFalse(BankAccount.isEmailValid("bc.def@mail")); - //Equivalence class being in second partitions, with boundary value to indexOf("@")->indexOf(".") - assertFalse(BankAccount.isEmailValid("abc.def@mail..com")); + assertFalse(BankAccount.isEmailValid("asd@mail.")); + assertTrue(BankAccount.isEmailValid("asd@asd.cc")); + assertTrue(BankAccount.isEmailValid("asd@asd.ccc")); - //Equivalence class being in second partitions, with boundary value to indexOf("@)->indexOf(extensions) - assertTrue(BankAccount.isEmailValid("abc.def@mail.cc")); + //Equivalence Class different extentions assertTrue(BankAccount.isEmailValid("abc.def@mail-archive.com")); assertTrue(BankAccount.isEmailValid("abc.def@mail.org")); assertTrue(BankAccount.isEmailValid("abc.def@mail.com")); + + //Equivalence Class @ symbols + assertFalse(BankAccount.isEmailValid("as@as@asd.com")); + assertFalse(BankAccount.isEmailValid("ASDF@ADSA.F@ASCOM")); + assertFalse(BankAccount.isEmailValid("asdfasdfsadf.sad")); + assertFalse(BankAccount.isEmailValid("asdfasdfasdf")); } @Test From 740efc56fb34a338e96ac9bfc9f78ff78f0ef2a3 Mon Sep 17 00:00:00 2001 From: jmendezdietsch Date: Sun, 26 Jan 2020 14:02:39 -0500 Subject: [PATCH 08/29] Withdraw and isEmailValid work --- .idea/misc.xml | 2 +- .../edu/ithaca/dragon/bank/BankAccount.java | 26 ++++++++++++++++--- 2 files changed, 23 insertions(+), 5 deletions(-) diff --git a/.idea/misc.xml b/.idea/misc.xml index 70edba37..367a03a3 100644 --- a/.idea/misc.xml +++ b/.idea/misc.xml @@ -11,7 +11,7 @@ - + \ No newline at end of file diff --git a/src/main/java/edu/ithaca/dragon/bank/BankAccount.java b/src/main/java/edu/ithaca/dragon/bank/BankAccount.java index 89c98676..cdf27492 100644 --- a/src/main/java/edu/ithaca/dragon/bank/BankAccount.java +++ b/src/main/java/edu/ithaca/dragon/bank/BankAccount.java @@ -35,19 +35,38 @@ public String getEmail(){ if the amount is 0 return the balance as is/do nothing and have the subtraction be 0 - if the amount is less than the current balance - print out "Amount wanted is less than the current balance" error + if the amount is greater than the current balance + print out "Amount wanted is greater than the current balance" error Don't change the original balance if all past if statements failed/was not used subtract the amount from the current balance regularly */ public void withdraw (double amount) throws InsufficientFundsException{ - balance -= amount; + if(amount <= 0){ + balance = balance; + } + else if(amount > balance){ + balance = balance; + } + else{ + balance -= amount; + } } public static boolean isEmailValid(String email){ + char atChar = '@'; //The "@" as a string has to be char to work + int atCount = 0; //To count the amount of @ symbols + for (int i = 0; i < email.length(); i++) { + if (email.charAt(i) == atChar) { + atCount++; + } + } + if(atCount >= 2){ + return false; + } + if(email == ""){ return false; } @@ -71,7 +90,6 @@ else if(email.indexOf("-@") != -1){ else if(email.indexOf("#") != -1){ return false; } - else{ String emDomain = email.substring(email.indexOf("@")); From 712230e087a012619b9d1e361ee07e4254f017a4 Mon Sep 17 00:00:00 2001 From: Stephen Date: Tue, 28 Jan 2020 15:05:35 -0500 Subject: [PATCH 09/29] Tests for isAmountValid --- .idea/misc.xml | 2 +- .../edu/ithaca/dragon/bank/BankAccount.java | 8 ++++++ .../ithaca/dragon/bank/BankAccountTest.java | 28 +++++++++++++++++++ 3 files changed, 37 insertions(+), 1 deletion(-) diff --git a/.idea/misc.xml b/.idea/misc.xml index 367a03a3..f11b0ebd 100644 --- a/.idea/misc.xml +++ b/.idea/misc.xml @@ -11,7 +11,7 @@ - + \ No newline at end of file diff --git a/src/main/java/edu/ithaca/dragon/bank/BankAccount.java b/src/main/java/edu/ithaca/dragon/bank/BankAccount.java index cdf27492..ec569f27 100644 --- a/src/main/java/edu/ithaca/dragon/bank/BankAccount.java +++ b/src/main/java/edu/ithaca/dragon/bank/BankAccount.java @@ -54,6 +54,14 @@ else if(amount > balance){ } } + /** + * Returns true if amountIn is positive and has 2 or less decimal places. Returns false otherwise. + * @param amountIn + * @return + */ + public static boolean isAmountValid(double amountIn){ + return false; + } public static boolean isEmailValid(String email){ char atChar = '@'; //The "@" as a string has to be char to work diff --git a/src/test/java/edu/ithaca/dragon/bank/BankAccountTest.java b/src/test/java/edu/ithaca/dragon/bank/BankAccountTest.java index 3b03d4d0..90994bb5 100644 --- a/src/test/java/edu/ithaca/dragon/bank/BankAccountTest.java +++ b/src/test/java/edu/ithaca/dragon/bank/BankAccountTest.java @@ -109,4 +109,32 @@ void constructorTest() { assertThrows(IllegalArgumentException.class, ()-> new BankAccount("", 100)); } + @Test + void isAmountValidTest(){ + assertTrue(BankAccount.isAmountValid(10)); + assertTrue(BankAccount.isAmountValid(10.0)); + assertTrue(BankAccount.isAmountValid(10.00)); + assertTrue(BankAccount.isAmountValid(10.000000000)); + assertTrue(BankAccount.isAmountValid(10.1)); + assertTrue(BankAccount.isAmountValid(10.11)); + assertTrue(BankAccount.isAmountValid(0.0000000)); + assertTrue(BankAccount.isAmountValid(0.1)); + assertTrue(BankAccount.isAmountValid(0.01)); + assertTrue(BankAccount.isAmountValid(0.00000000001)); + + assertFalse(BankAccount.isAmountValid(10.001)); + assertFalse(BankAccount.isAmountValid(10.0001)); + assertFalse(BankAccount.isAmountValid(10.00000001)); + assertFalse(BankAccount.isAmountValid(-10)); + assertFalse(BankAccount.isAmountValid(-10.0)); + assertFalse(BankAccount.isAmountValid(-10.00)); + assertFalse(BankAccount.isAmountValid(-10.00000)); + assertFalse(BankAccount.isAmountValid(-10.1)); + assertFalse(BankAccount.isAmountValid(-10.01)); + assertFalse(BankAccount.isAmountValid(-10.001)); + assertFalse(BankAccount.isAmountValid(-0.1)); + assertFalse(BankAccount.isAmountValid(-0.01)); + assertFalse(BankAccount.isAmountValid(-0.001)); + } + } \ No newline at end of file From 60dc2ef448ff7ee7adbb6cb306b2e7a5ed0e0bba Mon Sep 17 00:00:00 2001 From: stephen Date: Tue, 28 Jan 2020 15:47:02 -0500 Subject: [PATCH 10/29] end of class --- .gitignore | 194 ++++++------ .idea/SoftwareEngineeringPractice.iml | 2 +- .idea/compiler.xml | 26 +- .idea/encodings.xml | 12 +- .idea/misc.xml | 32 +- .idea/sbt.xml | 10 +- .idea/vcs.xml | 10 +- README.md | 20 +- pom.xml | 126 ++++---- .../edu/ithaca/dragon/bank/BankAccount.java | 246 ++++++++-------- .../bank/InsufficientFundsException.java | 16 +- .../ithaca/dragon/bank/BankAccountTest.java | 278 +++++++++--------- 12 files changed, 486 insertions(+), 486 deletions(-) diff --git a/.gitignore b/.gitignore index 4cc292d8..7c5067c2 100644 --- a/.gitignore +++ b/.gitignore @@ -1,98 +1,98 @@ -target/ - -# Covers JetBrains IDEs: IntelliJ, RubyMine, PhpStorm, AppCode, PyCharm, CLion, Android Studio and WebStorm -# Reference: https://intellij-support.jetbrains.com/hc/en-us/articles/206544839 - -# User-specific stuff -.idea/**/workspace.xml -.idea/**/tasks.xml -.idea/**/usage.statistics.xml -.idea/**/dictionaries -.idea/**/shelf - -# Generated files -.idea/**/contentModel.xml - -# Sensitive or high-churn files -.idea/**/dataSources/ -.idea/**/dataSources.ids -.idea/**/dataSources.local.xml -.idea/**/sqlDataSources.xml -.idea/**/dynamic.xml -.idea/**/uiDesigner.xml -.idea/**/dbnavigator.xml - -# Gradle -.idea/**/gradle.xml -.idea/**/libraries - -# Gradle and Maven with auto-import -# When using Gradle or Maven with auto-import, you should exclude module files, -# since they will be recreated, and may cause churn. Uncomment if using -# auto-import. -# .idea/modules.xml -# .idea/*.iml -# .idea/modules - -# CMake -cmake-build-*/ - -# Mongo Explorer plugin -.idea/**/mongoSettings.xml - -# File-based project format -*.iws - -# IntelliJ -out/ - -# mpeltonen/sbt-idea plugin -.idea_modules/ - -# JIRA plugin -atlassian-ide-plugin.xml - -# Cursive Clojure plugin -.idea/replstate.xml - -# Crashlytics plugin (for Android Studio and IntelliJ) -com_crashlytics_export_strings.xml -crashlytics.properties -crashlytics-build.properties -fabric.properties - -# Editor-based Rest Client -.idea/httpRequests - -# Android studio 3.1+ serialized cache file -.idea/caches/build_file_checksums.ser - -##### mac specific - -# General -.DS_Store -.AppleDouble -.LSOverride - -# Icon must end with two \r -Icon - - -# Thumbnails -._* - -# Files that might appear in the root of a volume -.DocumentRevisions-V100 -.fseventsd -.Spotlight-V100 -.TemporaryItems -.Trashes -.VolumeIcon.icns -.com.apple.timemachine.donotpresent - -# Directories potentially created on remote AFP share -.AppleDB -.AppleDesktop -Network Trash Folder -Temporary Items +target/ + +# Covers JetBrains IDEs: IntelliJ, RubyMine, PhpStorm, AppCode, PyCharm, CLion, Android Studio and WebStorm +# Reference: https://intellij-support.jetbrains.com/hc/en-us/articles/206544839 + +# User-specific stuff +.idea/**/workspace.xml +.idea/**/tasks.xml +.idea/**/usage.statistics.xml +.idea/**/dictionaries +.idea/**/shelf + +# Generated files +.idea/**/contentModel.xml + +# Sensitive or high-churn files +.idea/**/dataSources/ +.idea/**/dataSources.ids +.idea/**/dataSources.local.xml +.idea/**/sqlDataSources.xml +.idea/**/dynamic.xml +.idea/**/uiDesigner.xml +.idea/**/dbnavigator.xml + +# Gradle +.idea/**/gradle.xml +.idea/**/libraries + +# Gradle and Maven with auto-import +# When using Gradle or Maven with auto-import, you should exclude module files, +# since they will be recreated, and may cause churn. Uncomment if using +# auto-import. +# .idea/modules.xml +# .idea/*.iml +# .idea/modules + +# CMake +cmake-build-*/ + +# Mongo Explorer plugin +.idea/**/mongoSettings.xml + +# File-based project format +*.iws + +# IntelliJ +out/ + +# mpeltonen/sbt-idea plugin +.idea_modules/ + +# JIRA plugin +atlassian-ide-plugin.xml + +# Cursive Clojure plugin +.idea/replstate.xml + +# Crashlytics plugin (for Android Studio and IntelliJ) +com_crashlytics_export_strings.xml +crashlytics.properties +crashlytics-build.properties +fabric.properties + +# Editor-based Rest Client +.idea/httpRequests + +# Android studio 3.1+ serialized cache file +.idea/caches/build_file_checksums.ser + +##### mac specific + +# General +.DS_Store +.AppleDouble +.LSOverride + +# Icon must end with two \r +Icon + + +# Thumbnails +._* + +# Files that might appear in the root of a volume +.DocumentRevisions-V100 +.fseventsd +.Spotlight-V100 +.TemporaryItems +.Trashes +.VolumeIcon.icns +.com.apple.timemachine.donotpresent + +# Directories potentially created on remote AFP share +.AppleDB +.AppleDesktop +Network Trash Folder +Temporary Items .apdisk \ No newline at end of file diff --git a/.idea/SoftwareEngineeringPractice.iml b/.idea/SoftwareEngineeringPractice.iml index 78b2cc53..40981982 100644 --- a/.idea/SoftwareEngineeringPractice.iml +++ b/.idea/SoftwareEngineeringPractice.iml @@ -1,2 +1,2 @@ - + \ No newline at end of file diff --git a/.idea/compiler.xml b/.idea/compiler.xml index b6353da8..693bf3b1 100644 --- a/.idea/compiler.xml +++ b/.idea/compiler.xml @@ -1,14 +1,14 @@ - - - - - - - - - - - - - + + + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/encodings.xml b/.idea/encodings.xml index fade66b8..11e485db 100644 --- a/.idea/encodings.xml +++ b/.idea/encodings.xml @@ -1,7 +1,7 @@ - - - - - - + + + + + + \ No newline at end of file diff --git a/.idea/misc.xml b/.idea/misc.xml index f11b0ebd..ea57d31b 100644 --- a/.idea/misc.xml +++ b/.idea/misc.xml @@ -1,17 +1,17 @@ - - - - - - - - - - - + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/sbt.xml b/.idea/sbt.xml index 20187435..8c004fbf 100644 --- a/.idea/sbt.xml +++ b/.idea/sbt.xml @@ -1,6 +1,6 @@ - - - - + + + + \ No newline at end of file diff --git a/.idea/vcs.xml b/.idea/vcs.xml index 94a25f7f..9661ac71 100644 --- a/.idea/vcs.xml +++ b/.idea/vcs.xml @@ -1,6 +1,6 @@ - - - - - + + + + + \ No newline at end of file diff --git a/README.md b/README.md index 87c23b2d..16904e5c 100644 --- a/README.md +++ b/README.md @@ -1,10 +1,10 @@ -# SoftwareEngineeringPractice -## grading - -To Do | correct ----|--- -at least 8 commits| -isEmailValid| -withdraw| -isamountValid| -constructor & withdraw fix| +# SoftwareEngineeringPractice +## grading + +To Do | correct +---|--- +at least 8 commits| +isEmailValid| +withdraw| +isamountValid| +constructor & withdraw fix| diff --git a/pom.xml b/pom.xml index 416ce09a..edb078b9 100644 --- a/pom.xml +++ b/pom.xml @@ -1,64 +1,64 @@ - - - 4.0.0 - - edu.ithaca.dragon - SoftwareEngineeringPractice - 1.0-SNAPSHOT - - - UTF-8 - 1.10 - - 4.12 - 5.0.0 - ${junit.version}.0 - 5.0.0 - 1.0.0 - - - - - - maven-compiler-plugin - 3.1 - - ${java.version} - ${java.version} - - - - - - - - - org.junit.jupiter - junit-jupiter-engine - ${junit.jupiter.version} - test - - - - junit - junit - ${junit.version} - test - - - org.junit.platform - junit-platform-runner - ${junit.platform.version} - test - - - org.junit.vintage - junit-vintage-engine - ${junit.vintage.version} - test - - - + + + 4.0.0 + + edu.ithaca.dragon + SoftwareEngineeringPractice + 1.0-SNAPSHOT + + + UTF-8 + 1.10 + + 4.12 + 5.0.0 + ${junit.version}.0 + 5.0.0 + 1.0.0 + + + + + + maven-compiler-plugin + 3.1 + + ${java.version} + ${java.version} + + + + + + + + + org.junit.jupiter + junit-jupiter-engine + ${junit.jupiter.version} + test + + + + junit + junit + ${junit.version} + test + + + org.junit.platform + junit-platform-runner + ${junit.platform.version} + test + + + org.junit.vintage + junit-vintage-engine + ${junit.vintage.version} + test + + + \ No newline at end of file diff --git a/src/main/java/edu/ithaca/dragon/bank/BankAccount.java b/src/main/java/edu/ithaca/dragon/bank/BankAccount.java index ec569f27..917eea54 100644 --- a/src/main/java/edu/ithaca/dragon/bank/BankAccount.java +++ b/src/main/java/edu/ithaca/dragon/bank/BankAccount.java @@ -1,123 +1,123 @@ -package edu.ithaca.dragon.bank; - -public class BankAccount { - - private String email; - private double balance; - - /** - * @throws IllegalArgumentException if email is invalid - */ - public BankAccount(String email, double startingBalance){ - if (isEmailValid(email)){ - this.email = email; - this.balance = startingBalance; - } - else { - throw new IllegalArgumentException("Email address: " + email + " is invalid, cannot create account"); - } - } - - public double getBalance(){ - return balance; - } - - public String getEmail(){ - return email; - } - - /** - * @post reduces the balance by amount if amount is non-negative and smaller than balance - if the amount is less than 0 - print out "Amount wanted is less than 0" error - Don't change the original balance - - if the amount is 0 - return the balance as is/do nothing and have the subtraction be 0 - - if the amount is greater than the current balance - print out "Amount wanted is greater than the current balance" error - Don't change the original balance - - if all past if statements failed/was not used - subtract the amount from the current balance regularly - */ - public void withdraw (double amount) throws InsufficientFundsException{ - if(amount <= 0){ - balance = balance; - } - else if(amount > balance){ - balance = balance; - } - else{ - balance -= amount; - } - } - - /** - * Returns true if amountIn is positive and has 2 or less decimal places. Returns false otherwise. - * @param amountIn - * @return - */ - public static boolean isAmountValid(double amountIn){ - return false; - } - - public static boolean isEmailValid(String email){ - char atChar = '@'; //The "@" as a string has to be char to work - int atCount = 0; //To count the amount of @ symbols - for (int i = 0; i < email.length(); i++) { - if (email.charAt(i) == atChar) { - atCount++; - } - } - if(atCount >= 2){ - return false; - } - - if(email == ""){ - return false; - } - if (email.indexOf('@') == -1){ - return false; - } - - else if(email.indexOf(".") == 0){ - return false; - } - - else if(email.indexOf("..") != -1){ - return false; - } - - - else if(email.indexOf("-@") != -1){ - return false; - } - - else if(email.indexOf("#") != -1){ - return false; - } - else{ - String emDomain = email.substring(email.indexOf("@")); - - if(emDomain.indexOf(".") == -1){ - return false; - } - - else if(emDomain.indexOf("#") != -1){ - return false; - } - else { - String emEnd = emDomain.substring(emDomain.indexOf(".")); - - if (emEnd.length() < 3 && emEnd.length() < 4) { - return false; - } else if (emDomain.indexOf(".") == -1) { - return false; - } - } - } - return true; - } -} +package edu.ithaca.dragon.bank; + +public class BankAccount { + + private String email; + private double balance; + + /** + * @throws IllegalArgumentException if email is invalid + */ + public BankAccount(String email, double startingBalance){ + if (isEmailValid(email)){ + this.email = email; + this.balance = startingBalance; + } + else { + throw new IllegalArgumentException("Email address: " + email + " is invalid, cannot create account"); + } + } + + public double getBalance(){ + return balance; + } + + public String getEmail(){ + return email; + } + + /** + * @post reduces the balance by amount if amount is non-negative and smaller than balance + if the amount is less than 0 + print out "Amount wanted is less than 0" error + Don't change the original balance + + if the amount is 0 + return the balance as is/do nothing and have the subtraction be 0 + + if the amount is greater than the current balance + print out "Amount wanted is greater than the current balance" error + Don't change the original balance + + if all past if statements failed/was not used + subtract the amount from the current balance regularly + */ + public void withdraw (double amount) throws InsufficientFundsException{ + if(amount <= 0){ + balance = balance; + } + else if(amount > balance){ + balance = balance; + } + else{ + balance -= amount; + } + } + + /** + * Returns true if amountIn is positive and has 2 or less decimal places. Returns false otherwise. + * @param amountIn + * @return + */ + public static boolean isAmountValid(double amountIn){ + return false; + } + + public static boolean isEmailValid(String email){ + char atChar = '@'; //The "@" as a string has to be char to work + int atCount = 0; //To count the amount of @ symbols + for (int i = 0; i < email.length(); i++) { + if (email.charAt(i) == atChar) { + atCount++; + } + } + if(atCount >= 2){ + return false; + } + + if(email == ""){ + return false; + } + if (email.indexOf('@') == -1){ + return false; + } + + else if(email.indexOf(".") == 0){ + return false; + } + + else if(email.indexOf("..") != -1){ + return false; + } + + + else if(email.indexOf("-@") != -1){ + return false; + } + + else if(email.indexOf("#") != -1){ + return false; + } + else{ + String emDomain = email.substring(email.indexOf("@")); + + if(emDomain.indexOf(".") == -1){ + return false; + } + + else if(emDomain.indexOf("#") != -1){ + return false; + } + else { + String emEnd = emDomain.substring(emDomain.indexOf(".")); + + if (emEnd.length() < 3 && emEnd.length() < 4) { + return false; + } else if (emDomain.indexOf(".") == -1) { + return false; + } + } + } + return true; + } +} diff --git a/src/main/java/edu/ithaca/dragon/bank/InsufficientFundsException.java b/src/main/java/edu/ithaca/dragon/bank/InsufficientFundsException.java index 8c794be8..eabc6863 100644 --- a/src/main/java/edu/ithaca/dragon/bank/InsufficientFundsException.java +++ b/src/main/java/edu/ithaca/dragon/bank/InsufficientFundsException.java @@ -1,9 +1,9 @@ -package edu.ithaca.dragon.bank; - -public class InsufficientFundsException extends Exception{ - - public InsufficientFundsException(String s){ - super(s); - } - +package edu.ithaca.dragon.bank; + +public class InsufficientFundsException extends Exception{ + + public InsufficientFundsException(String s){ + super(s); + } + } \ No newline at end of file diff --git a/src/test/java/edu/ithaca/dragon/bank/BankAccountTest.java b/src/test/java/edu/ithaca/dragon/bank/BankAccountTest.java index 90994bb5..e46b5084 100644 --- a/src/test/java/edu/ithaca/dragon/bank/BankAccountTest.java +++ b/src/test/java/edu/ithaca/dragon/bank/BankAccountTest.java @@ -1,140 +1,140 @@ -package edu.ithaca.dragon.bank; - -import org.junit.jupiter.api.Test; - -import static org.junit.jupiter.api.Assertions.*; - -class BankAccountTest { - - @Test - void getBalanceTest() { - //Equivalence Class starting positive balance - BankAccount bankAccount = new BankAccount("a@b.com", 200); - assertEquals(200, bankAccount.getBalance()); - bankAccount = new BankAccount("a@b.com", 0); - assertEquals(0, bankAccount.getBalance()); - - //Equivalence Class Negative Starting Balance - bankAccount = new BankAccount("a@b.com", -200); - assertEquals(-200, bankAccount.getBalance()); - bankAccount = new BankAccount("a@b.com", -1); - assertEquals(-1, bankAccount.getBalance()); - } - - @Test - void withdrawTest() throws InsufficientFundsException{ - BankAccount bankAccount = new BankAccount("a@b.com", 200); - bankAccount.withdraw(100); - - assertEquals(100, bankAccount.getBalance()); - - //Equivalence Class Has balance - BankAccount bankAccount1 = new BankAccount("a@c.com", 300); - bankAccount1.withdraw(100);//valid withdraw - assertEquals(200, bankAccount1.getBalance()); - bankAccount1.withdraw(0);//valid withdraw edgecase - assertEquals(200, bankAccount1.getBalance()); - bankAccount1.withdraw(201);//overdraw - assertEquals(200, bankAccount1.getBalance()); - bankAccount1.withdraw(20100);//major overdraw - assertEquals(200, bankAccount1.getBalance()); - bankAccount1.withdraw(200);//perfect withdraw edgecase - assertEquals(0, bankAccount1.getBalance()); - - //Equivalence Class No balance - BankAccount ba2 = new BankAccount("a@c.cm", 0); - ba2.withdraw(0); //only valid withdraw - assertEquals(0, ba2.getBalance()); - ba2.withdraw(1);//overdraw - assertEquals(0, ba2.getBalance()); - - } - - @Test - void isEmailValidTest(){ - assertTrue(BankAccount.isEmailValid( "a@b.com")); - assertFalse( BankAccount.isEmailValid("")); - - //Partitions of ""=invalid partition, address first, domain second, extension third - - //Equivalence class being in first partitions, with boundary value to index[0]->indexOf(@) - //Multiple periods Partition tests - assertFalse(BankAccount.isEmailValid("a..b@male.com")); - assertTrue(BankAccount.isEmailValid("a.f.a@tah.com")); - assertTrue(BankAccount.isEmailValid("a.ffff.a@gasd.asd")); - assertFalse(BankAccount.isEmailValid("a...f@asdf.asd")); - assertFalse(BankAccount.isEmailValid("abc.def@mail..com")); //Only one is allowed in the second half regardless - - //Slash partitionTest - assertFalse(BankAccount.isEmailValid("abc-@mail.com")); - assertTrue(BankAccount.isEmailValid("abc-d@mail.com")); - - //Invalid period Location - assertFalse(BankAccount.isEmailValid(".abc@mail.com")); - assertTrue(BankAccount.isEmailValid("a.a@gasd.com")); - assertTrue(BankAccount.isEmailValid("abc.def@mail.com")); - - //Invalid Character Partitions - assertFalse(BankAccount.isEmailValid("abc#def@mail.com")); - assertFalse(BankAccount.isEmailValid("abc.def@mail#archive.com")); - assertTrue(BankAccount.isEmailValid("abc@mail.com")); - assertTrue(BankAccount.isEmailValid("abc_def@mail.com")); - - //Equivalence class Short or missing extentions - assertFalse(BankAccount.isEmailValid("abc.def@mail.c")); - assertFalse(BankAccount.isEmailValid("bc.def@mail")); - assertFalse(BankAccount.isEmailValid("asd@mail.")); - assertTrue(BankAccount.isEmailValid("asd@asd.cc")); - assertTrue(BankAccount.isEmailValid("asd@asd.ccc")); - - //Equivalence Class different extentions - assertTrue(BankAccount.isEmailValid("abc.def@mail-archive.com")); - assertTrue(BankAccount.isEmailValid("abc.def@mail.org")); - assertTrue(BankAccount.isEmailValid("abc.def@mail.com")); - - //Equivalence Class @ symbols - assertFalse(BankAccount.isEmailValid("as@as@asd.com")); - assertFalse(BankAccount.isEmailValid("ASDF@ADSA.F@ASCOM")); - assertFalse(BankAccount.isEmailValid("asdfasdfsadf.sad")); - assertFalse(BankAccount.isEmailValid("asdfasdfasdf")); - } - - @Test - void constructorTest() { - BankAccount bankAccount = new BankAccount("a@b.com", 200); - - assertEquals("a@b.com", bankAccount.getEmail()); - assertEquals(200, bankAccount.getBalance()); - //check for exception thrown correctly - assertThrows(IllegalArgumentException.class, ()-> new BankAccount("", 100)); - } - - @Test - void isAmountValidTest(){ - assertTrue(BankAccount.isAmountValid(10)); - assertTrue(BankAccount.isAmountValid(10.0)); - assertTrue(BankAccount.isAmountValid(10.00)); - assertTrue(BankAccount.isAmountValid(10.000000000)); - assertTrue(BankAccount.isAmountValid(10.1)); - assertTrue(BankAccount.isAmountValid(10.11)); - assertTrue(BankAccount.isAmountValid(0.0000000)); - assertTrue(BankAccount.isAmountValid(0.1)); - assertTrue(BankAccount.isAmountValid(0.01)); - assertTrue(BankAccount.isAmountValid(0.00000000001)); - - assertFalse(BankAccount.isAmountValid(10.001)); - assertFalse(BankAccount.isAmountValid(10.0001)); - assertFalse(BankAccount.isAmountValid(10.00000001)); - assertFalse(BankAccount.isAmountValid(-10)); - assertFalse(BankAccount.isAmountValid(-10.0)); - assertFalse(BankAccount.isAmountValid(-10.00)); - assertFalse(BankAccount.isAmountValid(-10.00000)); - assertFalse(BankAccount.isAmountValid(-10.1)); - assertFalse(BankAccount.isAmountValid(-10.01)); - assertFalse(BankAccount.isAmountValid(-10.001)); - assertFalse(BankAccount.isAmountValid(-0.1)); - assertFalse(BankAccount.isAmountValid(-0.01)); - assertFalse(BankAccount.isAmountValid(-0.001)); - } - +package edu.ithaca.dragon.bank; + +import org.junit.jupiter.api.Test; + +import static org.junit.jupiter.api.Assertions.*; + +class BankAccountTest { + + @Test + void getBalanceTest() { + //Equivalence Class starting positive balance + BankAccount bankAccount = new BankAccount("a@b.com", 200); + assertEquals(200, bankAccount.getBalance()); + bankAccount = new BankAccount("a@b.com", 0); + assertEquals(0, bankAccount.getBalance()); + + //Equivalence Class Negative Starting Balance + bankAccount = new BankAccount("a@b.com", -200); + assertEquals(-200, bankAccount.getBalance()); + bankAccount = new BankAccount("a@b.com", -1); + assertEquals(-1, bankAccount.getBalance()); + } + + @Test + void withdrawTest() throws InsufficientFundsException{ + BankAccount bankAccount = new BankAccount("a@b.com", 200); + bankAccount.withdraw(100); + + assertEquals(100, bankAccount.getBalance()); + + //Equivalence Class Has balance + BankAccount bankAccount1 = new BankAccount("a@c.com", 300); + bankAccount1.withdraw(100);//valid withdraw + assertEquals(200, bankAccount1.getBalance()); + bankAccount1.withdraw(0);//valid withdraw edgecase + assertEquals(200, bankAccount1.getBalance()); + bankAccount1.withdraw(201);//overdraw + assertEquals(200, bankAccount1.getBalance()); + bankAccount1.withdraw(20100);//major overdraw + assertEquals(200, bankAccount1.getBalance()); + bankAccount1.withdraw(200);//perfect withdraw edgecase + assertEquals(0, bankAccount1.getBalance()); + + //Equivalence Class No balance + BankAccount ba2 = new BankAccount("a@c.cm", 0); + ba2.withdraw(0); //only valid withdraw + assertEquals(0, ba2.getBalance()); + ba2.withdraw(1);//overdraw + assertEquals(0, ba2.getBalance()); + + } + + @Test + void isEmailValidTest(){ + assertTrue(BankAccount.isEmailValid( "a@b.com")); + assertFalse( BankAccount.isEmailValid("")); + + //Partitions of ""=invalid partition, address first, domain second, extension third + + //Equivalence class being in first partitions, with boundary value to index[0]->indexOf(@) + //Multiple periods Partition tests + assertFalse(BankAccount.isEmailValid("a..b@male.com")); + assertTrue(BankAccount.isEmailValid("a.f.a@tah.com")); + assertTrue(BankAccount.isEmailValid("a.ffff.a@gasd.asd")); + assertFalse(BankAccount.isEmailValid("a...f@asdf.asd")); + assertFalse(BankAccount.isEmailValid("abc.def@mail..com")); //Only one is allowed in the second half regardless + + //Slash partitionTest + assertFalse(BankAccount.isEmailValid("abc-@mail.com")); + assertTrue(BankAccount.isEmailValid("abc-d@mail.com")); + + //Invalid period Location + assertFalse(BankAccount.isEmailValid(".abc@mail.com")); + assertTrue(BankAccount.isEmailValid("a.a@gasd.com")); + assertTrue(BankAccount.isEmailValid("abc.def@mail.com")); + + //Invalid Character Partitions + assertFalse(BankAccount.isEmailValid("abc#def@mail.com")); + assertFalse(BankAccount.isEmailValid("abc.def@mail#archive.com")); + assertTrue(BankAccount.isEmailValid("abc@mail.com")); + assertTrue(BankAccount.isEmailValid("abc_def@mail.com")); + + //Equivalence class Short or missing extentions + assertFalse(BankAccount.isEmailValid("abc.def@mail.c")); + assertFalse(BankAccount.isEmailValid("bc.def@mail")); + assertFalse(BankAccount.isEmailValid("asd@mail.")); + assertTrue(BankAccount.isEmailValid("asd@asd.cc")); + assertTrue(BankAccount.isEmailValid("asd@asd.ccc")); + + //Equivalence Class different extentions + assertTrue(BankAccount.isEmailValid("abc.def@mail-archive.com")); + assertTrue(BankAccount.isEmailValid("abc.def@mail.org")); + assertTrue(BankAccount.isEmailValid("abc.def@mail.com")); + + //Equivalence Class @ symbols + assertFalse(BankAccount.isEmailValid("as@as@asd.com")); + assertFalse(BankAccount.isEmailValid("ASDF@ADSA.F@ASCOM")); + assertFalse(BankAccount.isEmailValid("asdfasdfsadf.sad")); + assertFalse(BankAccount.isEmailValid("asdfasdfasdf")); + } + + @Test + void constructorTest() { + BankAccount bankAccount = new BankAccount("a@b.com", 200); + + assertEquals("a@b.com", bankAccount.getEmail()); + assertEquals(200, bankAccount.getBalance()); + //check for exception thrown correctly + assertThrows(IllegalArgumentException.class, ()-> new BankAccount("", 100)); + } + + @Test + void isAmountValidTest(){ + assertTrue(BankAccount.isAmountValid(10)); + assertTrue(BankAccount.isAmountValid(10.0)); + assertTrue(BankAccount.isAmountValid(10.00)); + assertTrue(BankAccount.isAmountValid(10.000000000)); + assertTrue(BankAccount.isAmountValid(10.1)); + assertTrue(BankAccount.isAmountValid(10.11)); + assertTrue(BankAccount.isAmountValid(0.0000000)); + assertTrue(BankAccount.isAmountValid(0.1)); + assertTrue(BankAccount.isAmountValid(0.01)); + assertTrue(BankAccount.isAmountValid(0.00000000001)); + + assertFalse(BankAccount.isAmountValid(10.001)); + assertFalse(BankAccount.isAmountValid(10.0001)); + assertFalse(BankAccount.isAmountValid(10.00000001)); + assertFalse(BankAccount.isAmountValid(-10)); + assertFalse(BankAccount.isAmountValid(-10.0)); + assertFalse(BankAccount.isAmountValid(-10.00)); + assertFalse(BankAccount.isAmountValid(-10.00000)); + assertFalse(BankAccount.isAmountValid(-10.1)); + assertFalse(BankAccount.isAmountValid(-10.01)); + assertFalse(BankAccount.isAmountValid(-10.001)); + assertFalse(BankAccount.isAmountValid(-0.1)); + assertFalse(BankAccount.isAmountValid(-0.01)); + assertFalse(BankAccount.isAmountValid(-0.001)); + } + } \ No newline at end of file From c5da040d3ffe729de66db053b641b015a5a77ebd Mon Sep 17 00:00:00 2001 From: Stephen Date: Tue, 28 Jan 2020 20:57:49 -0500 Subject: [PATCH 11/29] isAmountValid implamentation added --- .idea/misc.xml | 2 +- src/main/java/edu/ithaca/dragon/bank/BankAccount.java | 6 +++++- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/.idea/misc.xml b/.idea/misc.xml index ea57d31b..12af44ef 100644 --- a/.idea/misc.xml +++ b/.idea/misc.xml @@ -11,7 +11,7 @@ - + \ No newline at end of file diff --git a/src/main/java/edu/ithaca/dragon/bank/BankAccount.java b/src/main/java/edu/ithaca/dragon/bank/BankAccount.java index 917eea54..b213a53c 100644 --- a/src/main/java/edu/ithaca/dragon/bank/BankAccount.java +++ b/src/main/java/edu/ithaca/dragon/bank/BankAccount.java @@ -60,7 +60,11 @@ else if(amount > balance){ * @return */ public static boolean isAmountValid(double amountIn){ - return false; + if (amountIn < 0) return false; + double scale = Math.pow(10, 9); + amountIn = Math.round(amountIn*scale)/scale; + if(Double.compare(amountIn, Math.round(amountIn*100)/100.0)!= 0) return false; + else return true; } public static boolean isEmailValid(String email){ From 2726723f79afd66027d37799fa067a6c02adb9e0 Mon Sep 17 00:00:00 2001 From: Stephen Date: Tue, 28 Jan 2020 21:06:58 -0500 Subject: [PATCH 12/29] tests for illegal aurguments with amounts for constructor and withdraw --- .../edu/ithaca/dragon/bank/BankAccountTest.java | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/src/test/java/edu/ithaca/dragon/bank/BankAccountTest.java b/src/test/java/edu/ithaca/dragon/bank/BankAccountTest.java index e46b5084..e4ec9eda 100644 --- a/src/test/java/edu/ithaca/dragon/bank/BankAccountTest.java +++ b/src/test/java/edu/ithaca/dragon/bank/BankAccountTest.java @@ -30,9 +30,9 @@ void withdrawTest() throws InsufficientFundsException{ //Equivalence Class Has balance BankAccount bankAccount1 = new BankAccount("a@c.com", 300); - bankAccount1.withdraw(100);//valid withdraw - assertEquals(200, bankAccount1.getBalance()); - bankAccount1.withdraw(0);//valid withdraw edgecase + bankAccount1.withdraw(99);//valid withdraw + assertEquals(201, bankAccount1.getBalance()); + bankAccount1.withdraw(1);//valid withdraw edgecase assertEquals(200, bankAccount1.getBalance()); bankAccount1.withdraw(201);//overdraw assertEquals(200, bankAccount1.getBalance()); @@ -43,11 +43,15 @@ void withdrawTest() throws InsufficientFundsException{ //Equivalence Class No balance BankAccount ba2 = new BankAccount("a@c.cm", 0); - ba2.withdraw(0); //only valid withdraw - assertEquals(0, ba2.getBalance()); ba2.withdraw(1);//overdraw assertEquals(0, ba2.getBalance()); + BankAccount ba3 = new BankAccount("a@c.cm", 200); + assertThrows(IllegalArgumentException.class, ()-> ba3.withdraw(0)); + assertThrows(IllegalArgumentException.class, ()-> ba3.withdraw(1.001)); + assertThrows(IllegalArgumentException.class, ()-> ba3.withdraw(-14)); + assertThrows(IllegalArgumentException.class, ()-> ba3.withdraw(-0.001)); + } @Test @@ -107,6 +111,8 @@ void constructorTest() { assertEquals(200, bankAccount.getBalance()); //check for exception thrown correctly assertThrows(IllegalArgumentException.class, ()-> new BankAccount("", 100)); + assertThrows(IllegalArgumentException.class, ()-> new BankAccount("a@basd.com", 100.001)); + assertThrows(IllegalArgumentException.class, ()-> new BankAccount("a@basd.com", -100)); } @Test From 9fe92143e4505ab5d9c4489fe17b554b6b8376bf Mon Sep 17 00:00:00 2001 From: Stephen Date: Tue, 28 Jan 2020 21:14:44 -0500 Subject: [PATCH 13/29] added implementation for illegal arguments with constructor and withdraw. Also removed getbalance tests for negitive starting balance since this is no longer possible --- .../edu/ithaca/dragon/bank/BankAccount.java | 26 +++++++------------ .../ithaca/dragon/bank/BankAccountTest.java | 6 ----- 2 files changed, 9 insertions(+), 23 deletions(-) diff --git a/src/main/java/edu/ithaca/dragon/bank/BankAccount.java b/src/main/java/edu/ithaca/dragon/bank/BankAccount.java index b213a53c..d25613aa 100644 --- a/src/main/java/edu/ithaca/dragon/bank/BankAccount.java +++ b/src/main/java/edu/ithaca/dragon/bank/BankAccount.java @@ -9,13 +9,10 @@ public class BankAccount { * @throws IllegalArgumentException if email is invalid */ public BankAccount(String email, double startingBalance){ - if (isEmailValid(email)){ - this.email = email; - this.balance = startingBalance; - } - else { - throw new IllegalArgumentException("Email address: " + email + " is invalid, cannot create account"); - } + if (isEmailValid(email)) this.email = email; + else throw new IllegalArgumentException("Email address: " + email + " is invalid, cannot create account"); + if (isAmountValid(startingBalance)) this.balance = startingBalance; + else throw new IllegalArgumentException(Double.toString(startingBalance)+" is an invalid starting Balance"); } public double getBalance(){ @@ -42,16 +39,11 @@ public String getEmail(){ if all past if statements failed/was not used subtract the amount from the current balance regularly */ - public void withdraw (double amount) throws InsufficientFundsException{ - if(amount <= 0){ - balance = balance; - } - else if(amount > balance){ - balance = balance; - } - else{ - balance -= amount; - } + public void withdraw (double amount) throws InsufficientFundsException, IllegalArgumentException{ + if (Double.compare(amount, 0.0)==0) throw new IllegalArgumentException("Cannot withdraw zero dollars"); + if (!isAmountValid(amount)) throw new IllegalArgumentException(Double.toString(amount)+" is not a valid withdraw amount"); + if(amount > balance); + else balance -= amount; } /** diff --git a/src/test/java/edu/ithaca/dragon/bank/BankAccountTest.java b/src/test/java/edu/ithaca/dragon/bank/BankAccountTest.java index e4ec9eda..c2fb251f 100644 --- a/src/test/java/edu/ithaca/dragon/bank/BankAccountTest.java +++ b/src/test/java/edu/ithaca/dragon/bank/BankAccountTest.java @@ -13,12 +13,6 @@ void getBalanceTest() { assertEquals(200, bankAccount.getBalance()); bankAccount = new BankAccount("a@b.com", 0); assertEquals(0, bankAccount.getBalance()); - - //Equivalence Class Negative Starting Balance - bankAccount = new BankAccount("a@b.com", -200); - assertEquals(-200, bankAccount.getBalance()); - bankAccount = new BankAccount("a@b.com", -1); - assertEquals(-1, bankAccount.getBalance()); } @Test From 0bdafbefc50eb49c302851fd2647f1ee571dcfca Mon Sep 17 00:00:00 2001 From: Stephen Date: Tue, 28 Jan 2020 21:21:47 -0500 Subject: [PATCH 14/29] added tests for inseficient funds and decimal withdraws --- .../ithaca/dragon/bank/BankAccountTest.java | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/src/test/java/edu/ithaca/dragon/bank/BankAccountTest.java b/src/test/java/edu/ithaca/dragon/bank/BankAccountTest.java index c2fb251f..5de9db88 100644 --- a/src/test/java/edu/ithaca/dragon/bank/BankAccountTest.java +++ b/src/test/java/edu/ithaca/dragon/bank/BankAccountTest.java @@ -28,16 +28,21 @@ void withdrawTest() throws InsufficientFundsException{ assertEquals(201, bankAccount1.getBalance()); bankAccount1.withdraw(1);//valid withdraw edgecase assertEquals(200, bankAccount1.getBalance()); - bankAccount1.withdraw(201);//overdraw - assertEquals(200, bankAccount1.getBalance()); - bankAccount1.withdraw(20100);//major overdraw - assertEquals(200, bankAccount1.getBalance()); - bankAccount1.withdraw(200);//perfect withdraw edgecase - assertEquals(0, bankAccount1.getBalance()); + bankAccount1.withdraw(0.1); + assertEquals(199.9, bankAccount1.getBalance(),10); + bankAccount1.withdraw(0.01); + System.out.println(bankAccount1.getBalance()); + assertEquals(199.89, bankAccount1.getBalance(), 10); + assertThrows(InsufficientFundsException.class, ()-> bankAccount1.withdraw(201)); + assertEquals(199.89, bankAccount1.getBalance(), 10); + assertThrows(InsufficientFundsException.class, ()-> bankAccount1.withdraw(20100)); + assertEquals(199.89, bankAccount1.getBalance(), 10); + bankAccount1.withdraw(199.89);//perfect withdraw edgecase + assertEquals(0, bankAccount1.getBalance(), 10); //Equivalence Class No balance BankAccount ba2 = new BankAccount("a@c.cm", 0); - ba2.withdraw(1);//overdraw + assertThrows(InsufficientFundsException.class, ()-> bankAccount.withdraw(1)); assertEquals(0, ba2.getBalance()); BankAccount ba3 = new BankAccount("a@c.cm", 200); From f5c4b316a98e5e9b6afe3e9ad6d1cfb6423b48bf Mon Sep 17 00:00:00 2001 From: Stephen Date: Tue, 28 Jan 2020 21:26:02 -0500 Subject: [PATCH 15/29] added implementation of inseficeint funds error being throw in withdraw --- src/main/java/edu/ithaca/dragon/bank/BankAccount.java | 2 +- src/test/java/edu/ithaca/dragon/bank/BankAccountTest.java | 3 +-- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/src/main/java/edu/ithaca/dragon/bank/BankAccount.java b/src/main/java/edu/ithaca/dragon/bank/BankAccount.java index d25613aa..d4fd1d7c 100644 --- a/src/main/java/edu/ithaca/dragon/bank/BankAccount.java +++ b/src/main/java/edu/ithaca/dragon/bank/BankAccount.java @@ -42,7 +42,7 @@ public String getEmail(){ public void withdraw (double amount) throws InsufficientFundsException, IllegalArgumentException{ if (Double.compare(amount, 0.0)==0) throw new IllegalArgumentException("Cannot withdraw zero dollars"); if (!isAmountValid(amount)) throw new IllegalArgumentException(Double.toString(amount)+" is not a valid withdraw amount"); - if(amount > balance); + if(amount > balance) throw new InsufficientFundsException("Not enough Money"); else balance -= amount; } diff --git a/src/test/java/edu/ithaca/dragon/bank/BankAccountTest.java b/src/test/java/edu/ithaca/dragon/bank/BankAccountTest.java index 5de9db88..bcd87f76 100644 --- a/src/test/java/edu/ithaca/dragon/bank/BankAccountTest.java +++ b/src/test/java/edu/ithaca/dragon/bank/BankAccountTest.java @@ -31,7 +31,6 @@ void withdrawTest() throws InsufficientFundsException{ bankAccount1.withdraw(0.1); assertEquals(199.9, bankAccount1.getBalance(),10); bankAccount1.withdraw(0.01); - System.out.println(bankAccount1.getBalance()); assertEquals(199.89, bankAccount1.getBalance(), 10); assertThrows(InsufficientFundsException.class, ()-> bankAccount1.withdraw(201)); assertEquals(199.89, bankAccount1.getBalance(), 10); @@ -42,7 +41,7 @@ void withdrawTest() throws InsufficientFundsException{ //Equivalence Class No balance BankAccount ba2 = new BankAccount("a@c.cm", 0); - assertThrows(InsufficientFundsException.class, ()-> bankAccount.withdraw(1)); + assertThrows(InsufficientFundsException.class, ()-> ba2.withdraw(1)); assertEquals(0, ba2.getBalance()); BankAccount ba3 = new BankAccount("a@c.cm", 200); From f9c27f576b2cea3e84da4e9a1444ea96eaf5a430 Mon Sep 17 00:00:00 2001 From: Stephen Date: Tue, 28 Jan 2020 21:28:46 -0500 Subject: [PATCH 16/29] added a few more tests for isEmailValid --- src/main/java/edu/ithaca/dragon/bank/BankAccount.java | 5 +++++ src/test/java/edu/ithaca/dragon/bank/BankAccountTest.java | 3 +++ 2 files changed, 8 insertions(+) diff --git a/src/main/java/edu/ithaca/dragon/bank/BankAccount.java b/src/main/java/edu/ithaca/dragon/bank/BankAccount.java index d4fd1d7c..8dc2d486 100644 --- a/src/main/java/edu/ithaca/dragon/bank/BankAccount.java +++ b/src/main/java/edu/ithaca/dragon/bank/BankAccount.java @@ -59,6 +59,11 @@ public static boolean isAmountValid(double amountIn){ else return true; } + /** + * returns true if email is valid and false if not + * @param email + * @return if email is valid + */ public static boolean isEmailValid(String email){ char atChar = '@'; //The "@" as a string has to be char to work int atCount = 0; //To count the amount of @ symbols diff --git a/src/test/java/edu/ithaca/dragon/bank/BankAccountTest.java b/src/test/java/edu/ithaca/dragon/bank/BankAccountTest.java index bcd87f76..caf21e84 100644 --- a/src/test/java/edu/ithaca/dragon/bank/BankAccountTest.java +++ b/src/test/java/edu/ithaca/dragon/bank/BankAccountTest.java @@ -99,6 +99,9 @@ void isEmailValidTest(){ assertFalse(BankAccount.isEmailValid("ASDF@ADSA.F@ASCOM")); assertFalse(BankAccount.isEmailValid("asdfasdfsadf.sad")); assertFalse(BankAccount.isEmailValid("asdfasdfasdf")); + + assertFalse(BankAccount.isEmailValid("asd%@asddff.coc")); + assertFalse(BankAccount.isEmailValid("asd@asddff.coco")); } @Test From ab3adb11420501ee66448f9ccc8bf02e9ce7e686 Mon Sep 17 00:00:00 2001 From: Stephen Date: Tue, 28 Jan 2020 22:27:26 -0500 Subject: [PATCH 17/29] Updated isEmailValid function to include more cases --- .../edu/ithaca/dragon/bank/BankAccount.java | 81 ++++++++----------- .../ithaca/dragon/bank/BankAccountTest.java | 1 - 2 files changed, 34 insertions(+), 48 deletions(-) diff --git a/src/main/java/edu/ithaca/dragon/bank/BankAccount.java b/src/main/java/edu/ithaca/dragon/bank/BankAccount.java index 8dc2d486..fb1f6de6 100644 --- a/src/main/java/edu/ithaca/dragon/bank/BankAccount.java +++ b/src/main/java/edu/ithaca/dragon/bank/BankAccount.java @@ -1,5 +1,7 @@ package edu.ithaca.dragon.bank; +import java.util.ArrayList; + public class BankAccount { private String email; @@ -65,60 +67,45 @@ public static boolean isAmountValid(double amountIn){ * @return if email is valid */ public static boolean isEmailValid(String email){ - char atChar = '@'; //The "@" as a string has to be char to work - int atCount = 0; //To count the amount of @ symbols - for (int i = 0; i < email.length(); i++) { - if (email.charAt(i) == atChar) { - atCount++; - } - } - if(atCount >= 2){ - return false; - } + ArrayList validChar = validCharsList(); - if(email == ""){ - return false; - } - if (email.indexOf('@') == -1){ - return false; - } - else if(email.indexOf(".") == 0){ - return false; - } + int atId = email.indexOf('@'); //gets the index of the first @ + if(atId== -1) return false; //if no @ invalid email + if(email.lastIndexOf('@')!=atId) return false; // if last @ is not the first @ invalid email + if(atId == 0||atId == email.length()-1) return false; // if the @ is the first or the last char the email is invalid - else if(email.indexOf("..") != -1){ - return false; - } + int lastPeriod = email.lastIndexOf('.'); + if(lastPeriod==-1)return false;//if there is no period there is no extension + if(lastPeriod validCharsList (){ + ArrayList validChar = new ArrayList(); + for(int x = 0; x < 26; x++){ + validChar.add((char)(x+65)); + validChar.add((char)(x+97)); } - return true; + validChar.add('-'); + validChar.add('_'); + validChar.add('@'); + validChar.add('.'); + return validChar; } } diff --git a/src/test/java/edu/ithaca/dragon/bank/BankAccountTest.java b/src/test/java/edu/ithaca/dragon/bank/BankAccountTest.java index caf21e84..4104672c 100644 --- a/src/test/java/edu/ithaca/dragon/bank/BankAccountTest.java +++ b/src/test/java/edu/ithaca/dragon/bank/BankAccountTest.java @@ -107,7 +107,6 @@ void isEmailValidTest(){ @Test void constructorTest() { BankAccount bankAccount = new BankAccount("a@b.com", 200); - assertEquals("a@b.com", bankAccount.getEmail()); assertEquals(200, bankAccount.getBalance()); //check for exception thrown correctly From 4be5d39ea020de73aff7e7a652f583510c667e1a Mon Sep 17 00:00:00 2001 From: Stephen Date: Tue, 28 Jan 2020 22:49:38 -0500 Subject: [PATCH 18/29] added tests for deposit --- .../edu/ithaca/dragon/bank/BankAccount.java | 9 +++++++++ .../ithaca/dragon/bank/BankAccountTest.java | 18 ++++++++++++++++++ 2 files changed, 27 insertions(+) diff --git a/src/main/java/edu/ithaca/dragon/bank/BankAccount.java b/src/main/java/edu/ithaca/dragon/bank/BankAccount.java index fb1f6de6..8d8d4c54 100644 --- a/src/main/java/edu/ithaca/dragon/bank/BankAccount.java +++ b/src/main/java/edu/ithaca/dragon/bank/BankAccount.java @@ -102,10 +102,19 @@ private static ArrayList validCharsList (){ validChar.add((char)(x+65)); validChar.add((char)(x+97)); } + for(int x = 0; x < 10; x++){ + validChar.add((char)(x+'0')); + } validChar.add('-'); validChar.add('_'); validChar.add('@'); validChar.add('.'); return validChar; } + + + public void deposit(double amount) throws IllegalArgumentException{ + } + + public void transfer(double amount, String email) throws IllegalArgumentException{} } diff --git a/src/test/java/edu/ithaca/dragon/bank/BankAccountTest.java b/src/test/java/edu/ithaca/dragon/bank/BankAccountTest.java index 4104672c..042c2785 100644 --- a/src/test/java/edu/ithaca/dragon/bank/BankAccountTest.java +++ b/src/test/java/edu/ithaca/dragon/bank/BankAccountTest.java @@ -143,4 +143,22 @@ void isAmountValidTest(){ assertFalse(BankAccount.isAmountValid(-0.001)); } + @Test + void depositTest(){ + BankAccount bankAccount = new BankAccount("a@a.cc", 0); + bankAccount.deposit(100); + assertEquals(100, bankAccount.getBalance(), 10); + bankAccount.deposit(0.1); + assertEquals(100.1, bankAccount.getBalance(), 10); + bankAccount.deposit(0.01); + assertEquals(100.11, bankAccount.getBalance(), 10); + bankAccount.deposit(0); + assertEquals(100.11, bankAccount.getBalance(), 10); + + assertThrows(IllegalArgumentException.class, ()-> bankAccount.deposit(-1)); + assertThrows(IllegalArgumentException.class, ()-> bankAccount.deposit(-1.01)); + assertThrows(IllegalArgumentException.class, ()-> bankAccount.deposit(1.001)); + assertThrows(IllegalArgumentException.class, ()-> bankAccount.deposit(-1.001)); + } + } \ No newline at end of file From aca3775164b6a9e8738619589f2607ca2b08c3d1 Mon Sep 17 00:00:00 2001 From: Stephen Date: Tue, 28 Jan 2020 23:07:12 -0500 Subject: [PATCH 19/29] added tests for transfer --- .../ithaca/dragon/bank/BankAccountTest.java | 24 +++++++++++++++++-- 1 file changed, 22 insertions(+), 2 deletions(-) diff --git a/src/test/java/edu/ithaca/dragon/bank/BankAccountTest.java b/src/test/java/edu/ithaca/dragon/bank/BankAccountTest.java index 042c2785..302f52a5 100644 --- a/src/test/java/edu/ithaca/dragon/bank/BankAccountTest.java +++ b/src/test/java/edu/ithaca/dragon/bank/BankAccountTest.java @@ -146,19 +146,39 @@ void isAmountValidTest(){ @Test void depositTest(){ BankAccount bankAccount = new BankAccount("a@a.cc", 0); + bankAccount.deposit(100); assertEquals(100, bankAccount.getBalance(), 10); bankAccount.deposit(0.1); assertEquals(100.1, bankAccount.getBalance(), 10); bankAccount.deposit(0.01); assertEquals(100.11, bankAccount.getBalance(), 10); - bankAccount.deposit(0); - assertEquals(100.11, bankAccount.getBalance(), 10); assertThrows(IllegalArgumentException.class, ()-> bankAccount.deposit(-1)); + assertThrows(IllegalArgumentException.class, ()-> bankAccount.deposit(0)); assertThrows(IllegalArgumentException.class, ()-> bankAccount.deposit(-1.01)); assertThrows(IllegalArgumentException.class, ()-> bankAccount.deposit(1.001)); assertThrows(IllegalArgumentException.class, ()-> bankAccount.deposit(-1.001)); } + @Test + void transferTest(){ + BankAccount bankAccount = new BankAccount("a@a.cc", 300); + + bankAccount.transfer(100, "a@a.com"); + assertEquals(200, bankAccount.getBalance(), 10); + bankAccount.transfer(0.1, "a@a.com"); + assertEquals(199.9, bankAccount.getBalance(), 10); + bankAccount.transfer(0.01, "a@a.com"); + assertEquals(199.89, bankAccount.getBalance(), 10); + + assertThrows(IllegalArgumentException.class, ()-> bankAccount.transfer(0, "a@a.com")); + assertThrows(IllegalArgumentException.class, ()-> bankAccount.transfer(-1, "a@a.com")); + assertThrows(IllegalArgumentException.class, ()-> bankAccount.transfer(-1.01, "a@a.com")); + assertThrows(IllegalArgumentException.class, ()-> bankAccount.transfer(-1.0001, "a@a.com")); + assertThrows(IllegalArgumentException.class, ()-> bankAccount.transfer(0.001, "a@a.com")); + assertThrows(IllegalArgumentException.class, ()-> bankAccount.transfer(1, "a@a.c"));//invalid email + assertThrows(IllegalArgumentException.class, ()-> bankAccount.transfer(1, "a@a.cc"));//same email as account + } + } \ No newline at end of file From 40853591d57ef8f2034e0e2e94ef4e1bd79774e9 Mon Sep 17 00:00:00 2001 From: Stephen Date: Tue, 28 Jan 2020 23:17:43 -0500 Subject: [PATCH 20/29] changes to tests to be transfer from one object to another rather than to a theretical email --- .../ithaca/dragon/bank/BankAccountTest.java | 22 ++++++++++--------- 1 file changed, 12 insertions(+), 10 deletions(-) diff --git a/src/test/java/edu/ithaca/dragon/bank/BankAccountTest.java b/src/test/java/edu/ithaca/dragon/bank/BankAccountTest.java index 302f52a5..4595f43b 100644 --- a/src/test/java/edu/ithaca/dragon/bank/BankAccountTest.java +++ b/src/test/java/edu/ithaca/dragon/bank/BankAccountTest.java @@ -164,21 +164,23 @@ void depositTest(){ @Test void transferTest(){ BankAccount bankAccount = new BankAccount("a@a.cc", 300); + BankAccount bankAccount1 = new BankAccount("A@AA.CC", 0); - bankAccount.transfer(100, "a@a.com"); + bankAccount.transfer(100, bankAccount1); assertEquals(200, bankAccount.getBalance(), 10); - bankAccount.transfer(0.1, "a@a.com"); + assertEquals(100, bankAccount1.getBalance(), 10); + bankAccount.transfer(0.1, bankAccount1); assertEquals(199.9, bankAccount.getBalance(), 10); - bankAccount.transfer(0.01, "a@a.com"); + assertEquals(100.1, bankAccount1.getBalance(), 10); + bankAccount.transfer(0.01, bankAccount1); assertEquals(199.89, bankAccount.getBalance(), 10); + assertEquals(100.11, bankAccount1.getBalance(), 10); - assertThrows(IllegalArgumentException.class, ()-> bankAccount.transfer(0, "a@a.com")); - assertThrows(IllegalArgumentException.class, ()-> bankAccount.transfer(-1, "a@a.com")); - assertThrows(IllegalArgumentException.class, ()-> bankAccount.transfer(-1.01, "a@a.com")); - assertThrows(IllegalArgumentException.class, ()-> bankAccount.transfer(-1.0001, "a@a.com")); - assertThrows(IllegalArgumentException.class, ()-> bankAccount.transfer(0.001, "a@a.com")); - assertThrows(IllegalArgumentException.class, ()-> bankAccount.transfer(1, "a@a.c"));//invalid email - assertThrows(IllegalArgumentException.class, ()-> bankAccount.transfer(1, "a@a.cc"));//same email as account + assertThrows(IllegalArgumentException.class, ()-> bankAccount.transfer(0, bankAccount1)); + assertThrows(IllegalArgumentException.class, ()-> bankAccount.transfer(-1, bankAccount1)); + assertThrows(IllegalArgumentException.class, ()-> bankAccount.transfer(-1.01, bankAccount1)); + assertThrows(IllegalArgumentException.class, ()-> bankAccount.transfer(-1.0001, bankAccount1)); + assertThrows(IllegalArgumentException.class, ()-> bankAccount.transfer(0.001, bankAccount1)); } } \ No newline at end of file From b9b9d71b50cdf6346642d7e82f7c452825eedcae Mon Sep 17 00:00:00 2001 From: Stephen Date: Tue, 28 Jan 2020 23:21:22 -0500 Subject: [PATCH 21/29] added tests for transfer to include invalid funds exception --- src/test/java/edu/ithaca/dragon/bank/BankAccountTest.java | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/test/java/edu/ithaca/dragon/bank/BankAccountTest.java b/src/test/java/edu/ithaca/dragon/bank/BankAccountTest.java index 4595f43b..0b73b9e8 100644 --- a/src/test/java/edu/ithaca/dragon/bank/BankAccountTest.java +++ b/src/test/java/edu/ithaca/dragon/bank/BankAccountTest.java @@ -162,7 +162,7 @@ void depositTest(){ } @Test - void transferTest(){ + void transferTest() throws InsufficientFundsException{ BankAccount bankAccount = new BankAccount("a@a.cc", 300); BankAccount bankAccount1 = new BankAccount("A@AA.CC", 0); @@ -181,6 +181,8 @@ void transferTest(){ assertThrows(IllegalArgumentException.class, ()-> bankAccount.transfer(-1.01, bankAccount1)); assertThrows(IllegalArgumentException.class, ()-> bankAccount.transfer(-1.0001, bankAccount1)); assertThrows(IllegalArgumentException.class, ()-> bankAccount.transfer(0.001, bankAccount1)); + + assertThrows(InsufficientFundsException.class, ()->bankAccount.transfer(1000, bankAccount1)); } } \ No newline at end of file From 53d20c1047a7ede40079d571d9e97ff5e4303e0c Mon Sep 17 00:00:00 2001 From: Stephen Date: Tue, 28 Jan 2020 23:23:07 -0500 Subject: [PATCH 22/29] added implemntation of deposit and transfer --- .../edu/ithaca/dragon/bank/BankAccount.java | 20 +++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/src/main/java/edu/ithaca/dragon/bank/BankAccount.java b/src/main/java/edu/ithaca/dragon/bank/BankAccount.java index 8d8d4c54..fe897779 100644 --- a/src/main/java/edu/ithaca/dragon/bank/BankAccount.java +++ b/src/main/java/edu/ithaca/dragon/bank/BankAccount.java @@ -112,9 +112,25 @@ private static ArrayList validCharsList (){ return validChar; } - + /** + * If non zero valid amount add amount ot balance + * @param amount + * @throws IllegalArgumentException + */ public void deposit(double amount) throws IllegalArgumentException{ + if(Double.compare(amount, 0)==0)throw new IllegalArgumentException("Cannot deposit zero dollars"); + if(!isAmountValid(amount))throw new IllegalArgumentException(Double.toString(amount)+" is not a valid deposit amount"); + else balance+=amount; } - public void transfer(double amount, String email) throws IllegalArgumentException{} + /** + * transfers amount from this to transferTo if amount is non zero and valid + * @param amount + * @param transferTo + * @throws IllegalArgumentException + */ + public void transfer(double amount, BankAccount transferTo) throws IllegalArgumentException, InsufficientFundsException { + this.withdraw(amount); + transferTo.deposit(amount); + } } From 77e7c1e1422f7a09beabb30650d98abf3910f394 Mon Sep 17 00:00:00 2001 From: Stephen Date: Mon, 3 Feb 2020 14:43:56 -0500 Subject: [PATCH 23/29] files from class --- .idea/misc.xml | 2 +- 345-08-BankInterfaceFiles/AdminAPI.java | 15 ++++++ 345-08-BankInterfaceFiles/AdvancedAPI.java | 9 ++++ 345-08-BankInterfaceFiles/BasicAPI.java | 18 +++++++ 345-08-BankInterfaceFiles/CentralBank.java | 63 ++++++++++++++++++++++ 5 files changed, 106 insertions(+), 1 deletion(-) create mode 100644 345-08-BankInterfaceFiles/AdminAPI.java create mode 100644 345-08-BankInterfaceFiles/AdvancedAPI.java create mode 100644 345-08-BankInterfaceFiles/BasicAPI.java create mode 100644 345-08-BankInterfaceFiles/CentralBank.java diff --git a/.idea/misc.xml b/.idea/misc.xml index 12af44ef..ea57d31b 100644 --- a/.idea/misc.xml +++ b/.idea/misc.xml @@ -11,7 +11,7 @@ - + \ No newline at end of file diff --git a/345-08-BankInterfaceFiles/AdminAPI.java b/345-08-BankInterfaceFiles/AdminAPI.java new file mode 100644 index 00000000..b11e2b4e --- /dev/null +++ b/345-08-BankInterfaceFiles/AdminAPI.java @@ -0,0 +1,15 @@ +package edu.ithaca.dragon.bank; + +import java.util.Collection; + +public interface AdminAPI { + + public double calcTotalAssets(); + + public Collection findAcctIdsWithSuspiciousActivity(); + + public void freezeAccount(String acctId); + + public void unfreezeAcct(String acctId); + +} diff --git a/345-08-BankInterfaceFiles/AdvancedAPI.java b/345-08-BankInterfaceFiles/AdvancedAPI.java new file mode 100644 index 00000000..26253541 --- /dev/null +++ b/345-08-BankInterfaceFiles/AdvancedAPI.java @@ -0,0 +1,9 @@ +package edu.ithaca.dragon.bank; + +//API to be used by Teller systems +public interface AdvancedAPI extends BasicAPI { + + public void createAccount(String acctId, double startingBalance); + + public void closeAccount(String acctId); +} diff --git a/345-08-BankInterfaceFiles/BasicAPI.java b/345-08-BankInterfaceFiles/BasicAPI.java new file mode 100644 index 00000000..bd65b941 --- /dev/null +++ b/345-08-BankInterfaceFiles/BasicAPI.java @@ -0,0 +1,18 @@ +package edu.ithaca.dragon.bank; + +//API to be used by ATMs +public interface BasicAPI { + + boolean confirmCredentials(String acctId, String password); + + double checkBalance(String acctId); + + void withdraw(String acctId, double amount) throws InsufficientFundsException; + + void deposit(String acctId, double amount); + + void transfer(String acctIdToWithdrawFrom, String acctIdToDepositTo, double amount) throws InsufficientFundsException; + + String transactionHistory(String acctId); + +} diff --git a/345-08-BankInterfaceFiles/CentralBank.java b/345-08-BankInterfaceFiles/CentralBank.java new file mode 100644 index 00000000..37508848 --- /dev/null +++ b/345-08-BankInterfaceFiles/CentralBank.java @@ -0,0 +1,63 @@ +package edu.ithaca.dragon.bank; + +import java.util.Collection; + +public class CentralBank implements AdvancedAPI, AdminAPI { + + //----------------- BasicAPI methods -------------------------// + + public boolean confirmCredentials(String acctId, String password) { + return false; + } + + public double checkBalance(String acctId) { + return 0; + } + + public void withdraw(String acctId, double amount) throws InsufficientFundsException { + + } + + public void deposit(String acctId, double amount) { + + } + + public void transfer(String acctIdToWithdrawFrom, String acctIdToDepositTo, double amount) throws InsufficientFundsException { + + } + + public String transactionHistory(String acctId) { + return null; + } + + + //----------------- AdvancedAPI methods -------------------------// + + public void createAccount(String acctId, double startingBalance) { + + } + + public void closeAccount(String acctId) { + + } + + + //------------------ AdminAPI methods -------------------------// + + public double checkTotalAssets() { + return 0; + } + + public Collection findAcctIdsWithSuspiciousActivity() { + return null; + } + + public void freezeAccount(String acctId) { + + } + + public void unfreezeAcct(String acctId) { + + } + +} From 4fec65485ed564e0b9834887787e4600e7c47f95 Mon Sep 17 00:00:00 2001 From: Stephen Date: Mon, 3 Feb 2020 14:46:53 -0500 Subject: [PATCH 24/29] moving files to the right location --- .../main/java/edu/ithaca/dragon/bank}/AdminAPI.java | 0 .../main/java/edu/ithaca/dragon/bank}/AdvancedAPI.java | 0 .../main/java/edu/ithaca/dragon/bank}/BasicAPI.java | 0 .../main/java/edu/ithaca/dragon/bank}/CentralBank.java | 0 4 files changed, 0 insertions(+), 0 deletions(-) rename {345-08-BankInterfaceFiles => src/main/java/edu/ithaca/dragon/bank}/AdminAPI.java (100%) rename {345-08-BankInterfaceFiles => src/main/java/edu/ithaca/dragon/bank}/AdvancedAPI.java (100%) rename {345-08-BankInterfaceFiles => src/main/java/edu/ithaca/dragon/bank}/BasicAPI.java (100%) rename {345-08-BankInterfaceFiles => src/main/java/edu/ithaca/dragon/bank}/CentralBank.java (100%) diff --git a/345-08-BankInterfaceFiles/AdminAPI.java b/src/main/java/edu/ithaca/dragon/bank/AdminAPI.java similarity index 100% rename from 345-08-BankInterfaceFiles/AdminAPI.java rename to src/main/java/edu/ithaca/dragon/bank/AdminAPI.java diff --git a/345-08-BankInterfaceFiles/AdvancedAPI.java b/src/main/java/edu/ithaca/dragon/bank/AdvancedAPI.java similarity index 100% rename from 345-08-BankInterfaceFiles/AdvancedAPI.java rename to src/main/java/edu/ithaca/dragon/bank/AdvancedAPI.java diff --git a/345-08-BankInterfaceFiles/BasicAPI.java b/src/main/java/edu/ithaca/dragon/bank/BasicAPI.java similarity index 100% rename from 345-08-BankInterfaceFiles/BasicAPI.java rename to src/main/java/edu/ithaca/dragon/bank/BasicAPI.java diff --git a/345-08-BankInterfaceFiles/CentralBank.java b/src/main/java/edu/ithaca/dragon/bank/CentralBank.java similarity index 100% rename from 345-08-BankInterfaceFiles/CentralBank.java rename to src/main/java/edu/ithaca/dragon/bank/CentralBank.java From ecaa624db66fbedffbb01b7c8dc3a44ac3985820 Mon Sep 17 00:00:00 2001 From: Stephen Date: Mon, 3 Feb 2020 14:52:56 -0500 Subject: [PATCH 25/29] fixed spelling error --- src/main/java/edu/ithaca/dragon/bank/CentralBank.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/edu/ithaca/dragon/bank/CentralBank.java b/src/main/java/edu/ithaca/dragon/bank/CentralBank.java index 37508848..7f6eba4f 100644 --- a/src/main/java/edu/ithaca/dragon/bank/CentralBank.java +++ b/src/main/java/edu/ithaca/dragon/bank/CentralBank.java @@ -44,7 +44,7 @@ public void closeAccount(String acctId) { //------------------ AdminAPI methods -------------------------// - public double checkTotalAssets() { + public double calcTotalAssets() { return 0; } From 71c80e73addccb581c4f9add6184847be85200f1 Mon Sep 17 00:00:00 2001 From: Stephen Date: Wed, 5 Feb 2020 14:18:55 -0500 Subject: [PATCH 26/29] added accounts --- .../java/edu/ithaca/dragon/bank/Account.java | 17 +++++++++++++++++ .../edu/ithaca/dragon/bank/CheckingAccount.java | 7 +++++++ 2 files changed, 24 insertions(+) create mode 100644 src/main/java/edu/ithaca/dragon/bank/Account.java create mode 100644 src/main/java/edu/ithaca/dragon/bank/CheckingAccount.java diff --git a/src/main/java/edu/ithaca/dragon/bank/Account.java b/src/main/java/edu/ithaca/dragon/bank/Account.java new file mode 100644 index 00000000..4528fdd6 --- /dev/null +++ b/src/main/java/edu/ithaca/dragon/bank/Account.java @@ -0,0 +1,17 @@ +package edu.ithaca.dragon.bank; + +public abstract class Account { + private String ID; + private double balance; + private boolean frozen; + + public double getBalance(){return balance;} + public String getID(){return ID;} + public boolean getFrozen(){return frozen;} + public void toggleFrozen(){frozen = !frozen;} + public abstract void deposit(double amount); + public abstract void withdraw(double amount) throws InsufficientFundsException; + public abstract void transfer(Account transferTo, double amount) throws InsufficientFundsException; + + +} diff --git a/src/main/java/edu/ithaca/dragon/bank/CheckingAccount.java b/src/main/java/edu/ithaca/dragon/bank/CheckingAccount.java new file mode 100644 index 00000000..4ceccf97 --- /dev/null +++ b/src/main/java/edu/ithaca/dragon/bank/CheckingAccount.java @@ -0,0 +1,7 @@ +package edu.ithaca.dragon.bank; + +public class CheckingAccount extends Account { + public void deposit(double amount){} + public void withdraw(double amount) throws InsufficientFundsException{} + public void transfer(Account transferTo, double amount) throws InsufficientFundsException{} +} From d6324cdd40044eeac11297caacf457f1584063a1 Mon Sep 17 00:00:00 2001 From: Stephen Date: Wed, 5 Feb 2020 14:34:27 -0500 Subject: [PATCH 27/29] withdraw tests --- .../java/edu/ithaca/dragon/bank/Account.java | 8 +++- .../ithaca/dragon/bank/CheckingAccount.java | 16 ++++++- .../ithaca/dragon/bank/BankAccountTest.java | 2 + .../dragon/bank/CheckingAccountTest.java | 45 +++++++++++++++++++ 4 files changed, 69 insertions(+), 2 deletions(-) create mode 100644 src/test/java/edu/ithaca/dragon/bank/CheckingAccountTest.java diff --git a/src/main/java/edu/ithaca/dragon/bank/Account.java b/src/main/java/edu/ithaca/dragon/bank/Account.java index 4528fdd6..e90046e7 100644 --- a/src/main/java/edu/ithaca/dragon/bank/Account.java +++ b/src/main/java/edu/ithaca/dragon/bank/Account.java @@ -5,12 +5,18 @@ public abstract class Account { private double balance; private boolean frozen; + + public Account(String IDIn, double startingBalance){ + ID = IDIn; + balance = startingBalance; + frozen = false; + } public double getBalance(){return balance;} public String getID(){return ID;} public boolean getFrozen(){return frozen;} public void toggleFrozen(){frozen = !frozen;} public abstract void deposit(double amount); - public abstract void withdraw(double amount) throws InsufficientFundsException; + public abstract void withdraw(double amount) throws InsufficientFundsException, IllegalArgumentException; public abstract void transfer(Account transferTo, double amount) throws InsufficientFundsException; diff --git a/src/main/java/edu/ithaca/dragon/bank/CheckingAccount.java b/src/main/java/edu/ithaca/dragon/bank/CheckingAccount.java index 4ceccf97..70aab5e4 100644 --- a/src/main/java/edu/ithaca/dragon/bank/CheckingAccount.java +++ b/src/main/java/edu/ithaca/dragon/bank/CheckingAccount.java @@ -1,7 +1,21 @@ package edu.ithaca.dragon.bank; public class CheckingAccount extends Account { + public CheckingAccount(String ID, double balance){ + super(ID, balance); + } public void deposit(double amount){} - public void withdraw(double amount) throws InsufficientFundsException{} + public void withdraw(double amount) throws InsufficientFundsException, IllegalArgumentException{ + if(!CheckingAccount.isAmountValid(amount))throw new IllegalArgumentException("Not a valid Amount"); + if(Double.compare(amount, 0.0)==0)throw new IllegalArgumentException("Cannot Withdraw zero dollars"); + + } public void transfer(Account transferTo, double amount) throws InsufficientFundsException{} + public static boolean isAmountValid(double amountIn){ + if (amountIn < 0) return false; + double scale = Math.pow(10, 9); + amountIn = Math.round(amountIn*scale)/scale; + if(Double.compare(amountIn, Math.round(amountIn*100)/100.0)!= 0) return false; + else return true; + } } diff --git a/src/test/java/edu/ithaca/dragon/bank/BankAccountTest.java b/src/test/java/edu/ithaca/dragon/bank/BankAccountTest.java index 0b73b9e8..8371d7ac 100644 --- a/src/test/java/edu/ithaca/dragon/bank/BankAccountTest.java +++ b/src/test/java/edu/ithaca/dragon/bank/BankAccountTest.java @@ -185,4 +185,6 @@ void transferTest() throws InsufficientFundsException{ assertThrows(InsufficientFundsException.class, ()->bankAccount.transfer(1000, bankAccount1)); } + + } \ No newline at end of file diff --git a/src/test/java/edu/ithaca/dragon/bank/CheckingAccountTest.java b/src/test/java/edu/ithaca/dragon/bank/CheckingAccountTest.java new file mode 100644 index 00000000..2ec0375b --- /dev/null +++ b/src/test/java/edu/ithaca/dragon/bank/CheckingAccountTest.java @@ -0,0 +1,45 @@ +package edu.ithaca.dragon.bank; + +import org.junit.jupiter.api.Test; + +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertThrows; + +public class CheckingAccountTest { + @Test + void withdrawCheckingTest() throws InsufficientFundsException{ + CheckingAccount bankAccount = new CheckingAccount("a@b.com", 200); + bankAccount.withdraw(100); + + assertEquals(100, bankAccount.getBalance()); + + //Equivalence Class Has balance + BankAccount bankAccount1 = new BankAccount("a@c.com", 300); + bankAccount1.withdraw(99);//valid withdraw + assertEquals(201, bankAccount1.getBalance()); + bankAccount1.withdraw(1);//valid withdraw edgecase + assertEquals(200, bankAccount1.getBalance()); + bankAccount1.withdraw(0.1); + assertEquals(199.9, bankAccount1.getBalance(),10); + bankAccount1.withdraw(0.01); + assertEquals(199.89, bankAccount1.getBalance(), 10); + assertThrows(InsufficientFundsException.class, ()-> bankAccount1.withdraw(201)); + assertEquals(199.89, bankAccount1.getBalance(), 10); + assertThrows(InsufficientFundsException.class, ()-> bankAccount1.withdraw(20100)); + assertEquals(199.89, bankAccount1.getBalance(), 10); + bankAccount1.withdraw(199.89);//perfect withdraw edgecase + assertEquals(0, bankAccount1.getBalance(), 10); + + //Equivalence Class No balance + CheckingAccount ba2 = new CheckingAccount("a@c.cm", 0); + assertThrows(InsufficientFundsException.class, ()-> ba2.withdraw(1)); + assertEquals(0, ba2.getBalance()); + + CheckingAccount ba3 = new CheckingAccount("a@c.cm", 200); + assertThrows(IllegalArgumentException.class, ()-> ba3.withdraw(0)); + assertThrows(IllegalArgumentException.class, ()-> ba3.withdraw(1.001)); + assertThrows(IllegalArgumentException.class, ()-> ba3.withdraw(-14)); + assertThrows(IllegalArgumentException.class, ()-> ba3.withdraw(-0.001)); + + } +} From be8fd6e29a5221553b2f18ea3b52fef6e607d6ad Mon Sep 17 00:00:00 2001 From: Stephen Date: Wed, 5 Feb 2020 14:41:04 -0500 Subject: [PATCH 28/29] finished implementation of withdraw --- src/main/java/edu/ithaca/dragon/bank/Account.java | 6 +++--- src/main/java/edu/ithaca/dragon/bank/CheckingAccount.java | 3 +++ 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/src/main/java/edu/ithaca/dragon/bank/Account.java b/src/main/java/edu/ithaca/dragon/bank/Account.java index e90046e7..e3196d22 100644 --- a/src/main/java/edu/ithaca/dragon/bank/Account.java +++ b/src/main/java/edu/ithaca/dragon/bank/Account.java @@ -1,9 +1,9 @@ package edu.ithaca.dragon.bank; public abstract class Account { - private String ID; - private double balance; - private boolean frozen; + protected String ID; + protected double balance; + protected boolean frozen; public Account(String IDIn, double startingBalance){ diff --git a/src/main/java/edu/ithaca/dragon/bank/CheckingAccount.java b/src/main/java/edu/ithaca/dragon/bank/CheckingAccount.java index 70aab5e4..9ec3751b 100644 --- a/src/main/java/edu/ithaca/dragon/bank/CheckingAccount.java +++ b/src/main/java/edu/ithaca/dragon/bank/CheckingAccount.java @@ -8,9 +8,12 @@ public void deposit(double amount){} public void withdraw(double amount) throws InsufficientFundsException, IllegalArgumentException{ if(!CheckingAccount.isAmountValid(amount))throw new IllegalArgumentException("Not a valid Amount"); if(Double.compare(amount, 0.0)==0)throw new IllegalArgumentException("Cannot Withdraw zero dollars"); + if(Double.compare(this.balance-amount, 0.0)==-1)throw new InsufficientFundsException("Not enough Funds"); + else this.balance -= amount; } public void transfer(Account transferTo, double amount) throws InsufficientFundsException{} + public static boolean isAmountValid(double amountIn){ if (amountIn < 0) return false; double scale = Math.pow(10, 9); From 97351c222e3878334499b108160c84f7f70a7efc Mon Sep 17 00:00:00 2001 From: Mariama Date: Wed, 5 Feb 2020 20:51:36 -0500 Subject: [PATCH 29/29] withdraw test and implementation --- .idea/SoftwareEngineeringPractice.iml | 2 +- .idea/misc.xml | 32 +++++----- .../java/edu/ithaca/dragon/bank/Account.java | 15 +++-- .../ithaca/dragon/bank/CheckingAccount.java | 36 ++++++++++- .../edu/ithaca/dragon/bank/AccountTest.java | 61 +++++++++++++++++++ 5 files changed, 123 insertions(+), 23 deletions(-) create mode 100644 src/test/java/edu/ithaca/dragon/bank/AccountTest.java diff --git a/.idea/SoftwareEngineeringPractice.iml b/.idea/SoftwareEngineeringPractice.iml index 40981982..78b2cc53 100644 --- a/.idea/SoftwareEngineeringPractice.iml +++ b/.idea/SoftwareEngineeringPractice.iml @@ -1,2 +1,2 @@ - + \ No newline at end of file diff --git a/.idea/misc.xml b/.idea/misc.xml index ea57d31b..8f7dab3a 100644 --- a/.idea/misc.xml +++ b/.idea/misc.xml @@ -1,17 +1,17 @@ - - - - - - - - - - - + + + + + + + + + + + \ No newline at end of file diff --git a/src/main/java/edu/ithaca/dragon/bank/Account.java b/src/main/java/edu/ithaca/dragon/bank/Account.java index 4528fdd6..8df25456 100644 --- a/src/main/java/edu/ithaca/dragon/bank/Account.java +++ b/src/main/java/edu/ithaca/dragon/bank/Account.java @@ -1,9 +1,16 @@ package edu.ithaca.dragon.bank; -public abstract class Account { - private String ID; - private double balance; - private boolean frozen; +public abstract class Account{ + + protected String ID; + protected double balance; + protected boolean frozen; + + public Account(String ID, double startingBalance){ + ID = ID; + balance = startingBalance; + frozen = false; + } public double getBalance(){return balance;} public String getID(){return ID;} diff --git a/src/main/java/edu/ithaca/dragon/bank/CheckingAccount.java b/src/main/java/edu/ithaca/dragon/bank/CheckingAccount.java index 4ceccf97..a7615dd0 100644 --- a/src/main/java/edu/ithaca/dragon/bank/CheckingAccount.java +++ b/src/main/java/edu/ithaca/dragon/bank/CheckingAccount.java @@ -1,7 +1,39 @@ package edu.ithaca.dragon.bank; +import java.math.BigDecimal; + public class CheckingAccount extends Account { - public void deposit(double amount){} - public void withdraw(double amount) throws InsufficientFundsException{} + + public CheckingAccount(String ID, double balance){ + super(ID,balance); + } + + public void deposit(double amount){ + + } + /** + * @post reduces the balance by amount if amount is non-negative and smaller than balance + * @throws IllegalArgumentException if amount is invalid + */ + public void withdraw(double amount) throws InsufficientFundsException{ + if (isAmountValid(amount) && amount <= balance){ + balance -= amount; + } + else if (!isAmountValid(amount)) { + throw new IllegalArgumentException("invalid amount "); + + } + else { + throw new InsufficientFundsException("Not enough money"); + + } + } + + public static boolean isAmountValid(double amount) { + + + return BigDecimal.valueOf(amount).scale() <= 2 && amount > 0; + + } public void transfer(Account transferTo, double amount) throws InsufficientFundsException{} } diff --git a/src/test/java/edu/ithaca/dragon/bank/AccountTest.java b/src/test/java/edu/ithaca/dragon/bank/AccountTest.java new file mode 100644 index 00000000..cd6743f7 --- /dev/null +++ b/src/test/java/edu/ithaca/dragon/bank/AccountTest.java @@ -0,0 +1,61 @@ +package edu.ithaca.dragon.bank; + +import org.junit.jupiter.api.Test; + +import static org.junit.jupiter.api.Assertions.*; + +class AccountTest { + @Test + void withdrawTest() throws InsufficientFundsException { + + CheckingAccount account1 = new CheckingAccount("a@b.com", 200); + account1.withdraw(100); + + assertEquals(100, account1.getBalance()); + + + //Equivalence Class-InsufficientFundsException + assertThrows(IllegalArgumentException.class, ()-> account1.withdraw(0)); + + assertThrows(InsufficientFundsException.class, () -> account1.withdraw(101)); + + + //Equivalence Class-IllegalArgumentException more than 2 decimal places + assertThrows(IllegalArgumentException.class, () -> account1.withdraw(1045.078)); + //Equivalence Class-IllegalArgumentException more than 2 decimal places + assertThrows(IllegalArgumentException.class, () -> account1.withdraw(1.02839)); + + + //Equivalence Class-Invalid withdraw amount 0 + assertThrows(IllegalArgumentException.class, () -> account1.withdraw(0)); + + //Equivalence Class-IllegalArgumentException negative amount + assertThrows(IllegalArgumentException.class, () -> account1.withdraw(-1)); + + //Equivalence Class-IllegalArgumentException negative amount + assertThrows(IllegalArgumentException.class, () -> account1.withdraw(-10)); + //Equivalence Class-IllegalArgumentException exceeds balance + assertThrows(InsufficientFundsException.class, () -> account1.withdraw(1000)); + + + //Equivalence Class- withdraw $1 + account1.withdraw(1); + assertEquals(99, account1.getBalance()); + + //Equivalence Class- withdraw $.1 + account1.withdraw(.1); + assertEquals(98.9, account1.getBalance()); + + //Equivalence Class- withdraw $.01 + account1.withdraw(.01); + assertEquals(98.89, account1.getBalance()); + + //Equivalence Class No balance + CheckingAccount account2 = new CheckingAccount("a@c.cm", 0); + assertThrows(InsufficientFundsException.class, ()-> account2.withdraw(1)); + assertEquals(0, account2.getBalance()); + + + + } +}