summaryrefslogtreecommitdiff
path: root/src/test/java/ca
diff options
context:
space:
mode:
authormokha <mokha@cisco.com>2019-05-05 19:25:48 -0600
committermokha <mokha@cisco.com>2019-05-05 19:25:48 -0600
commit46e409f3ca33ec3c7546d0589301c2a4f967c10a (patch)
tree55ed5a3297517719af1856f8fd0fa848dd4b94b5 /src/test/java/ca
parentc66b9591c81f93e3966050cc7c88981018e9b542 (diff)
collapse assignment1 dir
Diffstat (limited to 'src/test/java/ca')
-rw-r--r--src/test/java/ca/mokhan/assignment1/AddressBookTest.java92
-rw-r--r--src/test/java/ca/mokhan/assignment1/AppTest.java19
-rw-r--r--src/test/java/ca/mokhan/assignment1/BanffMarathonRunnerTest.java61
-rw-r--r--src/test/java/ca/mokhan/assignment1/BonusOnSavingsTest.java26
-rw-r--r--src/test/java/ca/mokhan/assignment1/CandidateTest.java62
-rw-r--r--src/test/java/ca/mokhan/assignment1/CartesianCoordinateSystemTest.java22
-rw-r--r--src/test/java/ca/mokhan/assignment1/CommunicationTest.java43
-rw-r--r--src/test/java/ca/mokhan/assignment1/EmployeeSavingsTest.java83
-rw-r--r--src/test/java/ca/mokhan/assignment1/HailstoneSequenceTest.java39
-rw-r--r--src/test/java/ca/mokhan/assignment1/NumberTest.java58
-rw-r--r--src/test/java/ca/mokhan/assignment1/TaxReturnTest.java85
-rw-r--r--src/test/java/ca/mokhan/assignment1/TriangleTest.java25
12 files changed, 615 insertions, 0 deletions
diff --git a/src/test/java/ca/mokhan/assignment1/AddressBookTest.java b/src/test/java/ca/mokhan/assignment1/AddressBookTest.java
new file mode 100644
index 0000000..fc2361d
--- /dev/null
+++ b/src/test/java/ca/mokhan/assignment1/AddressBookTest.java
@@ -0,0 +1,92 @@
+package ca.mokhan.assignment1;
+
+import junit.framework.Test;
+import junit.framework.TestCase;
+import junit.framework.TestSuite;
+
+public class AddressBookTest extends TestCase {
+ private AddressBook subject;
+
+ public AddressBookTest(String testName) {
+ super(testName);
+ this.subject = new AddressBook();
+ }
+
+ public static Test suite() {
+ return new TestSuite(AddressBookTest.class);
+ }
+
+ public void testFirstName() {
+ subject.setFirstName("mo");
+ assertEquals(subject.getFirstName(), "mo");
+ }
+
+ public void testMiddleName() {
+ subject.setMiddleName("tsuyoshi");
+ assertEquals(subject.getMiddleName(), "tsuyoshi");
+ }
+
+ public void testLastName() {
+ subject.setLastName("garrett");
+ assertEquals(subject.getLastName(), "garrett");
+ }
+
+ public void testHomeAddress() {
+ subject.setHomeAddress("1 University Dr, Athabasca, AB T9S 3A3");
+ assertEquals(subject.getHomeAddress(), "1 University Dr, Athabasca, AB T9S 3A3");
+ }
+
+ public void testBusinessPhone() {
+ subject.setBusinessPhone("1-800-788-9041");
+ assertEquals(subject.getBusinessPhone(), "1-800-788-9041");
+ }
+
+ public void testHomePhone() {
+ subject.setHomePhone("1-800-788-9041");
+ assertEquals(subject.getHomePhone(), "1-800-788-9041");
+ }
+
+ public void testCellPhone() {
+ subject.setCellPhone("1-800-788-9041");
+ assertEquals(subject.getCellPhone(), "1-800-788-9041");
+ }
+
+ public void testSkypeId() {
+ subject.setSkypeId("1-800-788-9041");
+ assertEquals(subject.getSkypeId(), "1-800-788-9041");
+ }
+
+ public void testFacebookId() {
+ subject.setFacebookId("1-800-788-9041");
+ assertEquals(subject.getFacebookId(), "1-800-788-9041");
+ }
+
+ public void testPersonalWebsite() {
+ subject.setPersonalWebSite("https://www.mokhan.ca/");
+ assertEquals(subject.getPersonalWebSite(), "https://www.mokhan.ca/");
+ }
+
+ public void testCompareNames() {
+ assertTrue(
+ Integer.parseInt(AddressBook.compareNames("Tsuyoshi M. Garret", "Takashi Shirogane")) > 0);
+ assertTrue(
+ Integer.parseInt(AddressBook.compareNames("Takashi Shirogane", "Tsuyoshi M. Garret")) < 0);
+ assertTrue(
+ Integer.parseInt(AddressBook.compareNames("Tsuyoshi Garret", "Tsuyoshi Garret")) == 0);
+ }
+
+ public void testCompareTo() {
+ AddressBook hunk = new AddressBook();
+ hunk.setFirstName("Tsuyoshi");
+ hunk.setLastName("Garrett");
+
+ AddressBook shiro = new AddressBook();
+ shiro.setFirstName("Takashi");
+ shiro.setLastName("Shirogane");
+
+ assertTrue(hunk.compareTo(shiro) > 0);
+ assertTrue(shiro.compareTo(hunk) < 0);
+ assertTrue(hunk.compareTo(hunk) == 0);
+ assertTrue(shiro.compareTo(shiro) == 0);
+ }
+}
diff --git a/src/test/java/ca/mokhan/assignment1/AppTest.java b/src/test/java/ca/mokhan/assignment1/AppTest.java
new file mode 100644
index 0000000..f4c16b8
--- /dev/null
+++ b/src/test/java/ca/mokhan/assignment1/AppTest.java
@@ -0,0 +1,19 @@
+package ca.mokhan.assignment1;
+
+import junit.framework.Test;
+import junit.framework.TestCase;
+import junit.framework.TestSuite;
+
+public class AppTest extends TestCase {
+ public AppTest(String testName) {
+ super(testName);
+ }
+
+ public static Test suite() {
+ return new TestSuite(AppTest.class);
+ }
+
+ public void testApp() {
+ assertTrue(true);
+ }
+}
diff --git a/src/test/java/ca/mokhan/assignment1/BanffMarathonRunnerTest.java b/src/test/java/ca/mokhan/assignment1/BanffMarathonRunnerTest.java
new file mode 100644
index 0000000..4b04ae0
--- /dev/null
+++ b/src/test/java/ca/mokhan/assignment1/BanffMarathonRunnerTest.java
@@ -0,0 +1,61 @@
+package ca.mokhan.assignment1;
+
+import junit.framework.Test;
+import junit.framework.TestCase;
+import junit.framework.TestSuite;
+
+public class BanffMarathonRunnerTest extends TestCase {
+ private BanffMarathonRunner john = new BanffMarathonRunner("John", "Lenthen", 243, 1);
+ private BanffMarathonRunner kate = new BanffMarathonRunner("Kate", "Hen", 265, 8);
+ private BanffMarathonRunner[] runners = {
+ new BanffMarathonRunner("Elena", "Brandon", 341, 1),
+ new BanffMarathonRunner("Thomas", "Molson", 273, 2),
+ new BanffMarathonRunner("Hamilton", "Winn", 278, 5),
+ new BanffMarathonRunner("Suzie", "Sarandin", 329, 7),
+ new BanffMarathonRunner("Philip", "Winne", 445, 9),
+ new BanffMarathonRunner("Alex", "Trebok", 275, 3),
+ new BanffMarathonRunner("Emma", "Pivoto", 275, 4),
+ this.john,
+ new BanffMarathonRunner("James", "Lean", 334, 1),
+ new BanffMarathonRunner("Jane", "Ostin", 412, 1),
+ new BanffMarathonRunner("Emily", "Car", 393, 4),
+ new BanffMarathonRunner("Daniel", "Hamshire", 299, 4),
+ new BanffMarathonRunner("Neda", "Bazdar", 343, 3),
+ new BanffMarathonRunner("Aaron", "Smith", 317, 6),
+ this.kate
+ };
+
+ public BanffMarathonRunnerTest(String testName) {
+ super(testName);
+ }
+
+ public static Test suite() {
+ return new TestSuite(BanffMarathonRunnerTest.class);
+ }
+
+ public void testGetFastestRunner() {
+ assertEquals(this.john, BanffMarathonRunner.getFastestRunner(this.runners));
+ }
+
+ public void testGetSecondFastestRunner() {
+ assertEquals(this.kate, BanffMarathonRunner.getSecondFastestRunner(this.runners));
+ }
+
+ public void testGetAverageTime() {
+ assertEquals(321, BanffMarathonRunner.getAverageTime(this.runners));
+ }
+
+ public void testGetAboveAverageRunners() {
+ String expected =
+ String.join(
+ System.lineSeparator(),
+ "Elena 1",
+ "Suzie 7",
+ "Philip 9",
+ "James 1",
+ "Jane 1",
+ "Emily 4",
+ "Neda 3");
+ assertEquals(expected, BanffMarathonRunner.getAboveAverageRunners(this.runners));
+ }
+}
diff --git a/src/test/java/ca/mokhan/assignment1/BonusOnSavingsTest.java b/src/test/java/ca/mokhan/assignment1/BonusOnSavingsTest.java
new file mode 100644
index 0000000..e19d447
--- /dev/null
+++ b/src/test/java/ca/mokhan/assignment1/BonusOnSavingsTest.java
@@ -0,0 +1,26 @@
+package ca.mokhan.assignment1;
+
+import junit.framework.Test;
+import junit.framework.TestCase;
+import junit.framework.TestSuite;
+
+public class BonusOnSavingsTest extends TestCase {
+ private BonusOnSavings subject;
+
+ public BonusOnSavingsTest(String testName) {
+ super(testName);
+ this.subject = new BonusOnSavings();
+ }
+
+ public static Test suite() {
+ return new TestSuite(BonusOnSavingsTest.class);
+ }
+
+ public void testComputeBonusEmployeeOne() {
+ assertEquals(1650.00, subject.computeBonus(2000, 5000, 7000, 4000, 8000));
+ }
+
+ public void testComputeBonusEmployeeTwo() {
+ assertEquals(4680.00, subject.computeBonus(3000, 6000, 9000, 10000, 17000));
+ }
+}
diff --git a/src/test/java/ca/mokhan/assignment1/CandidateTest.java b/src/test/java/ca/mokhan/assignment1/CandidateTest.java
new file mode 100644
index 0000000..6d2ca5e
--- /dev/null
+++ b/src/test/java/ca/mokhan/assignment1/CandidateTest.java
@@ -0,0 +1,62 @@
+package ca.mokhan.assignment1;
+
+import java.util.ArrayList;
+import junit.framework.Test;
+import junit.framework.TestCase;
+import junit.framework.TestSuite;
+
+public class CandidateTest extends TestCase {
+ private Candidate[] candidates = {
+ new Candidate("Elena", "Brandon", 82.30, "poor", true, 0.5),
+ new Candidate("Thomas", "Molson", 85.10, "poor", false, 1.0),
+ new Candidate("Hamilton", "Winn", 77.77, "average", false, 0.8),
+ new Candidate("Suzie", "Sarandin", 69.93, "average", false, 0.0),
+ new Candidate("Philip", "Winne", 93.03, "average", true, 1.0),
+ new Candidate("Alex", "Trebok", 88.61, "poor", true, 0.7),
+ new Candidate("Emma", "Pivoto", 55.99, "excellent", false, 0.8),
+ new Candidate("John", "Lenthen", 87.49, "excellent", true, 0.9),
+ new Candidate("James", "Lean", 88.00, "excellent", false, 0.5),
+ new Candidate("Jane", "Ostin", 91.20, "average", true, 0.6),
+ new Candidate("Emily", "Car", 66.79, "excellent", false, 0.3),
+ new Candidate("Daniel", "Hamshire", 76.65, "average", true, 0.2),
+ new Candidate("Neda", "Bazdar", 55.89, "excellent", true, 0.5),
+ new Candidate("Aaron", "Smith", 90.01, "excellent", false, 0.3),
+ new Candidate("Kate", "Hen", 87.9, "poor", false, 0.8)
+ };
+
+ public CandidateTest(String testName) {
+ super(testName);
+ }
+
+ public static Test suite() {
+ return new TestSuite(CandidateTest.class);
+ }
+
+ public void testGetEligibleCandidates() {
+ ArrayList<Candidate> eligibleCandidates = Candidate.getEligibleCandidates(this.candidates);
+ for (String expected :
+ new String[] {
+ "Hamilton", "Philip", "Alex", "Emma", "John", "James", "Jane", "Neda", "Aaron"
+ }) {
+ assertNotNull(
+ eligibleCandidates.stream()
+ .filter(x -> expected.equals(x.getFirstName()))
+ .findAny()
+ .orElse(null));
+ }
+ }
+
+ public void testIsElligibleWithGreaterThanRequiredGrade() {
+ assertTrue(new Candidate("Tsuyoshi", "Garrett", 85.0, "excellent", false, 0.0).isEligible());
+ }
+
+ public void testIsElligibleWithLessThanRequiredGrade() {
+ assertFalse(new Candidate("Tsuyoshi", "Garrett", 84.9, "average", false, 0.0).isEligible());
+ assertTrue(new Candidate("Tsuyoshi", "Garrett", 84.9, "average", false, 0.5).isEligible());
+ }
+
+ public void testIsElligibleWithPoorCommunication() {
+ assertTrue(new Candidate("Tsuyoshi", "Garrett", 85.0, "poor", true, 0.0).isEligible());
+ assertFalse(new Candidate("Tsuyoshi", "Garrett", 85.0, "poor", false, 0.0).isEligible());
+ }
+}
diff --git a/src/test/java/ca/mokhan/assignment1/CartesianCoordinateSystemTest.java b/src/test/java/ca/mokhan/assignment1/CartesianCoordinateSystemTest.java
new file mode 100644
index 0000000..6696ce1
--- /dev/null
+++ b/src/test/java/ca/mokhan/assignment1/CartesianCoordinateSystemTest.java
@@ -0,0 +1,22 @@
+package ca.mokhan.assignment1;
+
+import junit.framework.Test;
+import junit.framework.TestCase;
+import junit.framework.TestSuite;
+
+public class CartesianCoordinateSystemTest extends TestCase {
+ private CartesianCoordinateSystem subject;
+
+ public CartesianCoordinateSystemTest(String testName) {
+ super(testName);
+ this.subject = new CartesianCoordinateSystem();
+ }
+
+ public static Test suite() {
+ return new TestSuite(CartesianCoordinateSystemTest.class);
+ }
+
+ public void testDistanceBetweenPoints() {
+ assertEquals(7.28, subject.calculateDistance(-2, -3, -4, 4));
+ }
+}
diff --git a/src/test/java/ca/mokhan/assignment1/CommunicationTest.java b/src/test/java/ca/mokhan/assignment1/CommunicationTest.java
new file mode 100644
index 0000000..675492f
--- /dev/null
+++ b/src/test/java/ca/mokhan/assignment1/CommunicationTest.java
@@ -0,0 +1,43 @@
+package ca.mokhan.assignment1;
+
+import junit.framework.Test;
+import junit.framework.TestCase;
+import junit.framework.TestSuite;
+
+public class CommunicationTest extends TestCase {
+ public CommunicationTest(String testName) {
+ super(testName);
+ }
+
+ public static Test suite() {
+ return new TestSuite(CommunicationTest.class);
+ }
+
+ public void testCompareTo() {
+ assertEquals(-1, Communication.Poor.compareTo(Communication.Average));
+ assertEquals(-1, Communication.Poor.compareTo(Communication.Excellent));
+ assertEquals(0, Communication.Poor.compareTo(Communication.Poor));
+
+ assertEquals(-1, Communication.Average.compareTo(Communication.Excellent));
+ assertEquals(1, Communication.Average.compareTo(Communication.Poor));
+ assertEquals(0, Communication.Average.compareTo(Communication.Average));
+
+ assertEquals(1, Communication.Excellent.compareTo(Communication.Average));
+ assertEquals(1, Communication.Excellent.compareTo(Communication.Poor));
+ assertEquals(0, Communication.Excellent.compareTo(Communication.Excellent));
+ }
+
+ public void testIsAtLeast() {
+ assertFalse(Communication.Poor.isAtLeast(Communication.Average));
+ assertFalse(Communication.Poor.isAtLeast(Communication.Excellent));
+ assertTrue(Communication.Poor.isAtLeast(Communication.Poor));
+
+ assertFalse(Communication.Average.isAtLeast(Communication.Excellent));
+ assertTrue(Communication.Average.isAtLeast(Communication.Poor));
+ assertTrue(Communication.Average.isAtLeast(Communication.Average));
+
+ assertTrue(Communication.Excellent.isAtLeast(Communication.Average));
+ assertTrue(Communication.Excellent.isAtLeast(Communication.Poor));
+ assertTrue(Communication.Excellent.isAtLeast(Communication.Excellent));
+ }
+}
diff --git a/src/test/java/ca/mokhan/assignment1/EmployeeSavingsTest.java b/src/test/java/ca/mokhan/assignment1/EmployeeSavingsTest.java
new file mode 100644
index 0000000..5e9374b
--- /dev/null
+++ b/src/test/java/ca/mokhan/assignment1/EmployeeSavingsTest.java
@@ -0,0 +1,83 @@
+package ca.mokhan.assignment1;
+
+import junit.framework.Test;
+import junit.framework.TestCase;
+import junit.framework.TestSuite;
+
+public class EmployeeSavingsTest extends TestCase {
+ private EmployeeSavings subject;
+
+ public EmployeeSavingsTest(String testName) {
+ super(testName);
+ double monthlyContribution = 100.00;
+ this.subject = new EmployeeSavings("Tsuyoshi", "Garrett", monthlyContribution);
+ }
+
+ public static Test suite() {
+ return new TestSuite(EmployeeSavingsTest.class);
+ }
+
+ public void testPredictSavingsAfter1Month() {
+ // Bankers rounding rules would round this amount down to $100.41
+ // the $0.007 would go to the bank.
+ assertEquals(100.417, subject.predictBalanceAfterMonths(1));
+ assertEquals(201.252, subject.predictBalanceAfterMonths(2));
+ assertEquals(302.507, subject.predictBalanceAfterMonths(3));
+ }
+
+ public void testPredictInterestAfter1Month() {
+ // Bankers rounding rules would round this amount down to $100.41
+ // the $0.007 would go to the bank.
+ assertEquals(0.417, subject.predictInterestAfterMonths(1));
+ assertEquals(1.252, subject.predictInterestAfterMonths(2));
+ assertEquals(2.507, subject.predictInterestAfterMonths(3));
+ }
+
+ public void testGetAccountValue() {
+ assertEquals(subject.predictBalanceAfterMonths(12), subject.getAccountValue());
+ }
+
+ public void testCalculateInterests() {
+ assertEquals(0.417, subject.calculateInterests()[0]);
+ assertEquals(1.252, subject.calculateInterests()[1]);
+ assertEquals(2.507, subject.calculateInterests()[2]);
+ assertEquals(4.184, subject.calculateInterests()[3]);
+ assertEquals(6.285, subject.calculateInterests()[4]);
+ assertEquals(8.811, subject.calculateInterests()[5]);
+ assertEquals(11.764, subject.calculateInterests()[6]);
+ assertEquals(15.147, subject.calculateInterests()[7]);
+ assertEquals(18.96, subject.calculateInterests()[8]);
+ assertEquals(23.206, subject.calculateInterests()[9]);
+ assertEquals(27.886, subject.calculateInterests()[10]);
+ assertEquals(33.002, subject.calculateInterests()[11]);
+ }
+
+ public void testGenerateMonthlySavings() {
+ assertEquals(100.417, subject.generateMonthlySavings()[0]);
+ assertEquals(201.252, subject.generateMonthlySavings()[1]);
+ assertEquals(302.507, subject.generateMonthlySavings()[2]);
+ }
+
+ public void testGetReport() {
+ EmployeeSavings[] accounts =
+ new EmployeeSavings[] {
+ new EmployeeSavings("Elena", "Brandon"),
+ new EmployeeSavings("Thomas", "Molson"),
+ new EmployeeSavings("Hamilton", "Winn"),
+ new EmployeeSavings("Suzie", "Sarandin"),
+ new EmployeeSavings("Philip", "Winne"),
+ new EmployeeSavings("Alex", "Trebok"),
+ new EmployeeSavings("Emma", "Pivoto"),
+ new EmployeeSavings("John", "Lenthen"),
+ new EmployeeSavings("James", "Lean"),
+ new EmployeeSavings("Jane", "Ostin"),
+ new EmployeeSavings("Emily", "Car"),
+ new EmployeeSavings("Daniel", "Hamshire"),
+ new EmployeeSavings("Neda", "Bazdar"),
+ new EmployeeSavings("Aaron", "Smith"),
+ new EmployeeSavings("Kate", "Hen")
+ };
+ String report = EmployeeSavings.getReport(accounts);
+ for (EmployeeSavings account : accounts) assertTrue(report.contains(account.getFirstName()));
+ }
+}
diff --git a/src/test/java/ca/mokhan/assignment1/HailstoneSequenceTest.java b/src/test/java/ca/mokhan/assignment1/HailstoneSequenceTest.java
new file mode 100644
index 0000000..6dc1fea
--- /dev/null
+++ b/src/test/java/ca/mokhan/assignment1/HailstoneSequenceTest.java
@@ -0,0 +1,39 @@
+package ca.mokhan.assignment1;
+
+import java.util.ArrayList;
+import junit.framework.Test;
+import junit.framework.TestCase;
+import junit.framework.TestSuite;
+
+public class HailstoneSequenceTest extends TestCase {
+ public HailstoneSequenceTest(String testName) {
+ super(testName);
+ }
+
+ public static Test suite() {
+ return new TestSuite(HailstoneSequenceTest.class);
+ }
+
+ public void testGetHailstoneSequence() {
+ ArrayList<Integer> results = HailstoneSequence.getHailstoneSequence(15);
+
+ assertTrue(15 == results.get(0));
+ assertTrue(46 == results.get(1));
+ assertTrue(23 == results.get(2));
+ assertTrue(70 == results.get(3));
+ assertTrue(35 == results.get(4));
+ assertTrue(106 == results.get(5));
+ assertTrue(53 == results.get(6));
+ assertTrue(160 == results.get(7));
+ assertTrue(80 == results.get(8));
+ assertTrue(40 == results.get(9));
+ assertTrue(20 == results.get(10));
+ assertTrue(10 == results.get(11));
+ assertTrue(5 == results.get(12));
+ assertTrue(16 == results.get(13));
+ assertTrue(8 == results.get(14));
+ assertTrue(4 == results.get(15));
+ assertTrue(2 == results.get(16));
+ assertTrue(1 == results.get(17));
+ }
+}
diff --git a/src/test/java/ca/mokhan/assignment1/NumberTest.java b/src/test/java/ca/mokhan/assignment1/NumberTest.java
new file mode 100644
index 0000000..1ef9d96
--- /dev/null
+++ b/src/test/java/ca/mokhan/assignment1/NumberTest.java
@@ -0,0 +1,58 @@
+package ca.mokhan.assignment1;
+
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.List;
+import junit.framework.Test;
+import junit.framework.TestCase;
+import junit.framework.TestSuite;
+
+public class NumberTest extends TestCase {
+ public NumberTest(String testName) {
+ super(testName);
+ }
+
+ public static Test suite() {
+ return new TestSuite(NumberTest.class);
+ }
+
+ public void testIsDivisibleBy5() {
+ for (int i = 0; i < 113; i++)
+ if (i % 5 == 0) assertTrue(Number.isDivisibleBy5(i));
+ else assertFalse(Number.isDivisibleBy5(i));
+ }
+
+ public void testIsDivisibleBy7() {
+ for (int i = 0; i < 113; i++)
+ if (i % 7 == 0) assertTrue(Number.isDivisibleBy7(i));
+ else assertFalse(Number.isDivisibleBy7(i));
+ }
+
+ public void testIsOdd() {
+ for (int i = 0; i < 113; i++)
+ if (i % 2 == 0) assertFalse(Number.isOdd(i));
+ else assertTrue(Number.isOdd(i));
+ }
+
+ public void testIsPrime() {
+ List<Integer> primes =
+ Arrays.asList(
+ new Integer[] {
+ 2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67, 71, 73, 79,
+ 83, 89, 97, 101, 103, 107, 109, 113
+ });
+
+ for (Integer i = 0; i < 113; i++)
+ if (primes.contains(i)) assertTrue(Number.isPrime(i));
+ else assertFalse(Number.isPrime(i));
+ }
+
+ public void testIterate() {
+ ArrayList<String> results = Number.iterate();
+ assertTrue(results.contains("0,hi five"));
+ assertTrue(results.contains("1,1 is odd"));
+ assertTrue(results.contains("2,prime"));
+ assertTrue(results.contains("3,3 is odd,wow,prime"));
+ assertTrue(results.contains("4"));
+ }
+}
diff --git a/src/test/java/ca/mokhan/assignment1/TaxReturnTest.java b/src/test/java/ca/mokhan/assignment1/TaxReturnTest.java
new file mode 100644
index 0000000..474f899
--- /dev/null
+++ b/src/test/java/ca/mokhan/assignment1/TaxReturnTest.java
@@ -0,0 +1,85 @@
+package ca.mokhan.assignment1;
+
+import junit.framework.Test;
+import junit.framework.TestCase;
+import junit.framework.TestSuite;
+
+public class TaxReturnTest extends TestCase {
+ public TaxReturnTest(String testName) {
+ super(testName);
+ }
+
+ public static Test suite() {
+ return new TestSuite(TaxReturnTest.class);
+ }
+
+ public void test_SINGLE_BRACKET1() {
+ TaxReturn subject = new TaxReturn(TaxReturn.SINGLE_BRACKET1 - 0.01, TaxReturn.SINGLE);
+ assertEquals(3217.4985, subject.getTax());
+ }
+
+ public void test_SINGLE_BRACKET1_1_CHILD() {
+ TaxReturn subject = new TaxReturn(TaxReturn.SINGLE_BRACKET1 - 0.01, TaxReturn.SINGLE, 1);
+ assertEquals(2467.4985, subject.getTax());
+ }
+
+ public void test_SINGLE_BRACKET1_2_CHILDREN() {
+ TaxReturn subject = new TaxReturn(TaxReturn.SINGLE_BRACKET1 - 0.01, TaxReturn.SINGLE, 2);
+ assertEquals(1717.4985000000001, subject.getTax());
+ }
+
+ public void test_SINGLE_BRACKET1_3_CHILDREN() {
+ TaxReturn subject = new TaxReturn(TaxReturn.SINGLE_BRACKET1 - 0.01, TaxReturn.SINGLE, 3);
+ assertEquals(967.4985000000001, subject.getTax());
+ }
+
+ public void test_SINGLE_BRACKET2() {
+ TaxReturn subject = new TaxReturn(TaxReturn.SINGLE_BRACKET2 - 0.01, TaxReturn.SINGLE);
+ assertEquals(11743.4972, subject.getTax());
+ }
+
+ public void test_SINGLE_BRACKET3() {
+ TaxReturn subject = new TaxReturn(TaxReturn.SINGLE_BRACKET2 + 0.01, TaxReturn.SINGLE);
+ assertEquals(11743.5031, subject.getTax());
+ }
+
+ // if the income is greater than $249,999 for SINGLE, then add a tax of 25% on income amount above
+ // $150,000;
+ public void test_SINGLE_Income_Greater_Than_250K() {
+ // $0 - $21450: 0.15% = $3,217.5
+ // $21450 - $51900: 0.28% = $8,526.0
+ // $51900 - $250,000: 0.31% = $61411.0
+ // $150,000 - $250,000: 0.25% = $25,000.0
+ // total: $98,154.50
+
+ TaxReturn subject = new TaxReturn(250000, TaxReturn.SINGLE);
+ assertEquals(98154.50, subject.getTax());
+ }
+
+ public void test_MARRIED_BRACKET1() {
+ TaxReturn subject = new TaxReturn(TaxReturn.MARRIED_BRACKET1 - 0.01, TaxReturn.MARRIED);
+ assertEquals(5369.9985, subject.getTax());
+ }
+
+ public void test_MARRIED_BRACKET2() {
+ TaxReturn subject = new TaxReturn(TaxReturn.MARRIED_BRACKET2 - 0.01, TaxReturn.MARRIED);
+ assertEquals(19565.997200000005, subject.getTax());
+ }
+
+ public void test_MARRIED_BRACKET3() {
+ TaxReturn subject = new TaxReturn(TaxReturn.MARRIED_BRACKET2 + 0.01, TaxReturn.MARRIED);
+ assertEquals(19566.003099999998, subject.getTax());
+ }
+
+ // if the income is greater than $349,999 for MARRIED, then add a tax of 35% on income amount
+ // above $200,000.
+ public void test_MARRIED_Income_Greater_Than_350K() {
+ // $0 - $35,800: 0.15% = $5,370.0
+ // $35,800 - $86,500: 0.28% = $14196.000000000002
+ // $86,500 - $350,000: 0.31% = $81685.0
+ // $200,000 - $350,000: 0.35% = $52500.0
+ // total: $153,751.0
+ TaxReturn subject = new TaxReturn(350000, TaxReturn.MARRIED);
+ assertEquals(153751.0, subject.getTax());
+ }
+}
diff --git a/src/test/java/ca/mokhan/assignment1/TriangleTest.java b/src/test/java/ca/mokhan/assignment1/TriangleTest.java
new file mode 100644
index 0000000..7b85c01
--- /dev/null
+++ b/src/test/java/ca/mokhan/assignment1/TriangleTest.java
@@ -0,0 +1,25 @@
+package ca.mokhan.assignment1;
+
+import junit.framework.Test;
+import junit.framework.TestCase;
+import junit.framework.TestSuite;
+
+public class TriangleTest extends TestCase {
+ public TriangleTest(String testName) {
+ super(testName);
+ }
+
+ public static Test suite() {
+ return new TestSuite(TriangleTest.class);
+ }
+
+ public void testIsRightTriangle() {
+ assertFalse(new Triangle(45.0, 55.0, 75.0).isRightTriangle());
+ assertTrue(new Triangle(28.0, 45.0, 53.0).isRightTriangle());
+ }
+
+ public void testGetB() {
+ assertEquals(64.0, new Triangle(48.0, Triangle.NULL, 80.0).getB());
+ assertEquals(35.0, new Triangle(84.0, Triangle.NULL, 91.0).getB());
+ }
+}