diff --git a/README.md b/README.md
index 8402302c..e4f516f5 100644
--- a/README.md
+++ b/README.md
@@ -1,9 +1,14 @@
-# ScientificCalculator (maven) ZCW
+=======
+#Team Members
+teAM MEMBER
+Keerthana
+
+# com.zipcodewilmington.scientificcalculator.ScientificCalculator (maven) ZCW
## Description
-In this project your team will build a small app to function as a calculator. This app will be built in Java, and will use the topics and techniques discussed during the week.
+In this project your team will build a small app to function as a calculator. This app will be built in Java, and will use the topics and techniques discussed during the week..
Your team should work on this project in a single repository. Click the `fork` button in the top right corner to create a copy of this repository in one of your github accounts. You can go through the [GitHub forking tutorial](https://help.github.com/articles/fork-a-repo/) if you need additional practice with this.
diff --git a/Untitled Diagram.drawio b/Untitled Diagram.drawio
new file mode 100644
index 00000000..f94661ad
--- /dev/null
+++ b/Untitled Diagram.drawio
@@ -0,0 +1,126 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/pom.xml b/pom.xml
index e7cb4f6b..d8cd763e 100644
--- a/pom.xml
+++ b/pom.xml
@@ -7,6 +7,14 @@
com.zipcodewilmington
scientific_calculator
1.0-SNAPSHOT
+
+
+ junit
+ junit
+ 4.12
+ test
+
+
\ No newline at end of file
diff --git a/src/main/java/com/zipcodewilmington/scientificcalculator/BasicCalculator.java b/src/main/java/com/zipcodewilmington/scientificcalculator/BasicCalculator.java
new file mode 100644
index 00000000..69f1427c
--- /dev/null
+++ b/src/main/java/com/zipcodewilmington/scientificcalculator/BasicCalculator.java
@@ -0,0 +1,60 @@
+package com.zipcodewilmington.scientificcalculator;
+
+public class BasicCalculator {
+
+ private Double result;
+
+ public BasicCalculator(){
+ result = 0.0;
+ }
+
+ public Double add(double num1, double num2){
+ result = num1 + num2;
+ return result;
+ }
+
+ public Double subtract(double num1, double num2){
+ result = num1 - num2;
+ return result;
+ }
+
+ public Double multiply(double num1, double num2){
+ result = num1 * num2;
+ return result;
+ }
+
+ public Double divide(double num1, double num2){
+ result = num1 / num2;
+ return result;
+ }
+
+ public Double squareRoot(Double num1) {
+ result = Math.sqrt(num1);
+ return result;
+ }
+
+ public Double square(Double num1) {
+ result = Math.pow(num1, 2);
+ return result;
+ }
+
+ public Double exponentiation(Double num1, Double num2) {
+ result = Math.pow(num1, num2);
+ return result;
+ }
+
+ public Double inverse(Double num1) {
+ result = 1 / num1;
+ return result;
+ }
+
+ public Double invertNumber(Double num1) {
+ result = -1 * num1;
+ return result;
+ }
+
+ public Double percentage(Double num1) {
+ result = num1 / 100;
+ return result;
+ }
+}
diff --git a/src/main/java/com/zipcodewilmington/scientificcalculator/Console.java b/src/main/java/com/zipcodewilmington/scientificcalculator/Console.java
index 83f0e97f..29f74846 100644
--- a/src/main/java/com/zipcodewilmington/scientificcalculator/Console.java
+++ b/src/main/java/com/zipcodewilmington/scientificcalculator/Console.java
@@ -7,6 +7,12 @@
*/
public class Console {
+ private static int displayMode;
+
+ public static void setDisplayMode(int givenDisplayMode) {
+ displayMode = givenDisplayMode;
+ }
+
public static void print(String output, Object... args) {
System.out.printf(output, args);
}
@@ -15,6 +21,18 @@ public static void println(String output, Object... args) {
print(output + "\n", args);
}
+ public static void displayValue(String currentValue) {
+ Console.println(">>>>>>>> Display Value: %s <<<<<<<<<< \n", currentValue);
+ }
+
+ public static void displayValue(double currentValue) {
+ Console.println(">>>>>>>> Display Value (in %s): %s <<<<<<<<<< \n", getDisplayMode(), applyDisplayMode(currentValue, displayMode));
+ }
+
+ public static void displayValue(double currentValue, String unitMode) {
+ Console.println(">>>>>>>> Display Value (Mode: %s): %s <<<<<<<<<< \n", unitMode, currentValue);
+ }
+
public static String getStringInput(String prompt) {
Scanner scanner = new Scanner(System.in);
println(prompt);
@@ -22,11 +40,106 @@ public static String getStringInput(String prompt) {
return userInput;
}
- public static Integer getIntegerInput(String prompt) {
- return null;
+ public static Integer getIntegerInput(String prompt, int rangeStart, int rangeStop) {
+
+ Scanner scanner = new Scanner(System.in);
+ println(prompt);
+ Integer inputValue = 0;
+
+ while (true) {
+ try {
+ inputValue = Integer.valueOf(scanner.nextLine());
+ if (inputValue >= rangeStart && inputValue <= rangeStop) {
+ break;
+ }
+ else {
+ println("Invalid Choice!");
+ println(prompt);
+ }
+ }
+ catch(Exception e) {
+ println("Invalid Integer Number!");
+ println(prompt);
+ }
+ }
+
+ return inputValue;
}
public static Double getDoubleInput(String prompt) {
- return null;
+
+ Scanner scanner = new Scanner(System.in);
+ println(prompt + " (in %s): ", getDisplayMode());
+ Double inputValue = 0.0;
+
+ while (true) {
+ try {
+ inputValue = Double.valueOf(applyDisplayMode(scanner.nextLine(), displayMode));
+ break;
+ }
+ catch(Exception e) {
+ println("Invalid Input!");
+ println(prompt + "( in %s): ", getDisplayMode());
+ }
+ }
+
+ return inputValue;
+ }
+
+ public static String applyDisplayMode(double currentValue, int displayMode) {
+ String output = null;
+ switch (displayMode) {
+ case 1:
+ output = String.valueOf(currentValue);
+ break;
+ case 2:
+ output = Integer.toBinaryString((int) Math.round(currentValue));
+ break;
+ case 3:
+ output = Integer.toOctalString((int) Math.round(currentValue));
+ break;
+ case 4:
+ output = Integer.toHexString((int) Math.round(currentValue));
+ break;
+ }
+ return output;
+ }
+
+ public static Integer applyDisplayMode(String inputValue, int displayMode) {
+ Integer output = null;
+ switch (displayMode) {
+ case 1:
+ output = Integer.parseInt(inputValue, 10);
+ break;
+ case 2:
+ output = Integer.parseInt(inputValue, 2);
+ break;
+ case 3:
+ output = Integer.parseInt(inputValue, 8);
+ break;
+ case 4:
+ output = Integer.parseInt(inputValue, 16);
+ break;
+ }
+ return output;
+ }
+
+ public static String getDisplayMode() {
+ String displayModeValue = null;
+ switch (displayMode) {
+ case 1:
+ displayModeValue = "Decimal";
+ break;
+ case 2:
+ displayModeValue = "Binary";
+ break;
+ case 3:
+ displayModeValue = "Octal";
+ break;
+ case 4:
+ displayModeValue = "HexaDecimal";
+ break;
+ }
+ return displayModeValue;
}
}
diff --git a/src/main/java/com/zipcodewilmington/scientificcalculator/Fibonacci.java b/src/main/java/com/zipcodewilmington/scientificcalculator/Fibonacci.java
new file mode 100644
index 00000000..5addbc18
--- /dev/null
+++ b/src/main/java/com/zipcodewilmington/scientificcalculator/Fibonacci.java
@@ -0,0 +1,19 @@
+package com.zipcodewilmington.scientificcalculator;
+
+public class Fibonacci {
+
+ public static String fibonacci(Double num1){
+ Double maxNumber = num1;
+ Integer previousNumber = 0;
+ Integer nextNumber = 1;
+ String fiboString = "";
+
+ for (int i = 1; i <= maxNumber; i++){
+ fiboString += " " + previousNumber;
+ int sum = previousNumber + nextNumber;
+ previousNumber = nextNumber;
+ nextNumber = sum;
+ }
+ return fiboString;
+ }
+}
diff --git a/src/main/java/com/zipcodewilmington/scientificcalculator/MainApplication.java b/src/main/java/com/zipcodewilmington/scientificcalculator/MainApplication.java
index 5f421325..fda7bc8e 100644
--- a/src/main/java/com/zipcodewilmington/scientificcalculator/MainApplication.java
+++ b/src/main/java/com/zipcodewilmington/scientificcalculator/MainApplication.java
@@ -4,14 +4,256 @@
* Created by leon on 2/9/18.
*/
public class MainApplication {
+
+ private double currentValue;
+ private int calculatorType;
+
+ // Initialize all required fields
+ private BasicCalculator basicCalc;
+ private ScFunction scientificCalc;
+ private Fibonacci fibo;
+
+ public MainApplication() {
+ basicCalc = new BasicCalculator();
+ scientificCalc = new ScFunction();
+ fibo = new Fibonacci();
+ currentValue = 0.0;
+ Console.setDisplayMode(1);
+ }
+
public static void main(String[] args) {
- Console.println("Welcome to my calculator!");
- String s = Console.getStringInput("Enter a string");
- Integer i = Console.getIntegerInput("Enter an integer");
- Double d = Console.getDoubleInput("Enter a double.");
-
- Console.println("The user input %s as a string", s);
- Console.println("The user input %s as a integer", i);
- Console.println("The user input %s as a d", d);
+
+ MainApplication mainApplication = new MainApplication();
+ mainApplication.runCalculator();
+ }
+
+ private void runCalculator() {
+
+ // Print Welcome Note
+ Console.println("Welcome to Our Calculator!");
+
+ // Get Calculator Type
+
+ calculatorType = Console.getIntegerInput("Please select between 1) Basic Calculator and 2) Scientific Calculator", 1, 2);
+
+ // Get First Number to start
+ currentValue = Console.getDoubleInput("Please enter the number");
+ Console.displayValue(currentValue);
+
+ // Creating infinite loop until user choose to exit
+ while (true) {
+
+ try {
+
+ if (calculatorType == 1) {
+ int choice = runBasicCalculator();
+ if (choice == 14) {
+ break;
+ }
+ } else {
+ int choice = runScientificCalculator();
+ if (choice == 17) {
+ break;
+ }
+ }
+ } catch (Exception e) {
+ Console.displayValue("Err");
+ currentValue = Console.getDoubleInput("Please enter the number");
+ Console.displayValue(currentValue);
+ }
+ }
+ Console.println("Exit! Thank you");
+ }
+
+ private int runBasicCalculator() {
+
+ double operandValue = 0;
+ int choice = Console.getIntegerInput("Please select from the options below\n " +
+ "1) Add \n " +
+ "2) Subtract\n " +
+ "3) Multiply \n " +
+ "4) Division\n " +
+ "5) Exponential\n" +
+ "6) Square\n" +
+ "7) SquareRoot\n" +
+ "8) Inverse\n" +
+ "9) Invert\n" +
+ "10) Percentage\n" +
+ "11) Switch to Scientific Calculator\n" +
+ "12) Switch to Display Mode\n" +
+ "13) Clear\n" +
+ "14) Exit", 1, 14);
+
+ if (choice >= 1 && choice <= 5) {
+ operandValue = Console.getDoubleInput("Please enter the operand number");
+ }
+
+ switch (choice) {
+ case 1:
+ currentValue = basicCalc.add(currentValue, operandValue);
+ Console.displayValue(currentValue);
+ break;
+ case 2:
+ currentValue = basicCalc.subtract(currentValue, operandValue);
+ Console.displayValue(currentValue);
+ break;
+ case 3:
+ currentValue = basicCalc.multiply(currentValue, operandValue);
+ Console.displayValue(currentValue);
+ break;
+ case 4:
+ currentValue = basicCalc.divide(currentValue, operandValue);
+ if (Double.isInfinite(currentValue)) {
+ Console.displayValue("Err");
+ currentValue = Console.getDoubleInput("Please enter the number");
+ }
+ Console.displayValue(currentValue);
+ break;
+ case 5:
+ currentValue = basicCalc.exponentiation(currentValue, operandValue);
+ Console.displayValue(currentValue);
+ break;
+ case 6:
+ currentValue = basicCalc.square(currentValue);
+ Console.displayValue(currentValue);
+ break;
+ case 7:
+ currentValue = basicCalc.squareRoot(currentValue);
+ Console.displayValue(currentValue);
+ break;
+ case 8:
+ currentValue = basicCalc.inverse(currentValue);
+ Console.displayValue(currentValue);
+ break;
+ case 9:
+ currentValue = basicCalc.invertNumber(currentValue);
+ Console.displayValue(currentValue);
+ break;
+ case 10:
+ currentValue = basicCalc.percentage(currentValue);
+ Console.displayValue(currentValue);
+ break;
+ case 11:
+ calculatorType = 2;
+ Console.println("Switching to Scientific Calculator");
+ Console.setDisplayMode(1);
+ Console.displayValue(currentValue);
+ break;
+ case 12:
+ Console.println("Switching to Display Mode");
+ int displayMode = Console.getIntegerInput("Please select display mode\n 1) Decimal\n 2) Binary\n 3) Octal\n 4) HexaDecimal", 1, 4);
+ Console.setDisplayMode(displayMode);
+ Console.displayValue(currentValue);
+ break;
+ case 13:
+ currentValue = 0.0;
+ Console.displayValue(currentValue);
+ currentValue = Console.getDoubleInput("Please enter the number");
+ Console.displayValue(currentValue);
+ break;
+ }
+
+ return choice;
+ }
+
+ private int runScientificCalculator() {
+
+ int choice = Console.getIntegerInput("Please select from the options below\n " +
+ "1) natural log\n" +
+ "2) base log\n" +
+ "3) inverse log\n" +
+ "4) change sign\n" +
+ "5) sine\n" +
+ "6) cos\n" +
+ "7) tan\n" +
+ "8) inverseCosine\n" +
+ "9) inverseTangent\n" +
+ "10) inverseSine\n" +
+ "11) factorial\n" +
+ "12) fibonacci\n" +
+ "13) Switch Unit Mode\n" +
+ "14) Choose Unit Mode\n" +
+ "15) Switch to Basic Calculator\n" +
+ "16) Enter New Number\n" +
+ "17) Exit", 1, 21);
+
+
+ switch (choice) {
+ case 1:
+ currentValue = scientificCalc.inverseNaturalLog(currentValue);
+ Console.displayValue(currentValue);
+ break;
+ case 2:
+ currentValue = scientificCalc.log(currentValue);
+ Console.displayValue(currentValue);
+ break;
+ case 3:
+ currentValue = scientificCalc.inverseLog(currentValue);
+ Console.displayValue(currentValue);
+ break;
+ case 4:
+ currentValue = scientificCalc.changesign(currentValue);
+ Console.displayValue(currentValue);
+ break;
+ case 5:
+ currentValue = scientificCalc.sin(currentValue);
+ Console.displayValue(currentValue, scientificCalc.getUnitMode());
+ break;
+ case 6:
+ currentValue = scientificCalc.cosine(currentValue);
+ Console.displayValue(currentValue, scientificCalc.getUnitMode());
+ break;
+ case 7:
+ currentValue = scientificCalc.tangent(currentValue);
+ Console.displayValue(currentValue, scientificCalc.getUnitMode());
+ break;
+ case 8:
+ currentValue = scientificCalc.inverseCosine(currentValue);
+ Console.displayValue(currentValue, scientificCalc.getUnitMode());
+ break;
+ case 9:
+ currentValue = scientificCalc.inverseTangent(currentValue);
+ Console.displayValue(currentValue, scientificCalc.getUnitMode());
+ break;
+ case 10:
+ currentValue = scientificCalc.inverseSin(currentValue);
+ Console.displayValue(currentValue, scientificCalc.getUnitMode());
+ break;
+ case 11:
+ currentValue = scientificCalc.factorial(currentValue);
+ Console.displayValue(currentValue);
+ break;
+ case 12:
+ String result = fibo.fibonacci(currentValue);
+ Console.displayValue(result);
+ currentValue = Console.getDoubleInput("Please enter the number");
+ Console.displayValue(currentValue);
+ break;
+ case 13:
+ scientificCalc.switchUnitMode();
+ scientificCalc.applyUnitMode(currentValue);
+ Console.displayValue(currentValue, scientificCalc.getUnitMode());
+ currentValue = Console.getDoubleInput("Please enter the number");
+ Console.displayValue(currentValue);
+ break;
+ case 14:
+ int choosenUnitMode = Console.getIntegerInput("Please select unit mode\n 1) Degree\n 2) Radian\n", 1, 2);
+ scientificCalc.setUnitMode(choosenUnitMode);
+ currentValue = Console.getDoubleInput("Please enter the number");
+ Console.displayValue(currentValue);
+ break;
+ case 15:
+ calculatorType = 1;
+ Console.setDisplayMode(1);
+ currentValue = Console.getDoubleInput("Please enter the number");
+ Console.displayValue(currentValue);
+ break;
+ case 16:
+ currentValue = Console.getDoubleInput("Please enter the number");
+ Console.displayValue(currentValue);
+ break;
+ }
+
+ return choice;
}
-}
+}
\ No newline at end of file
diff --git a/src/main/java/com/zipcodewilmington/scientificcalculator/ScFunction.java b/src/main/java/com/zipcodewilmington/scientificcalculator/ScFunction.java
new file mode 100644
index 00000000..dfa028c7
--- /dev/null
+++ b/src/main/java/com/zipcodewilmington/scientificcalculator/ScFunction.java
@@ -0,0 +1,144 @@
+package com.zipcodewilmington.scientificcalculator;
+
+public class ScFunction {
+
+ private Double result;
+
+ // 1 for degree & 2 for radian
+ private int unitsMode;
+
+ public ScFunction() {
+ result = 0.0; // constructor to initialize variable
+ unitsMode = 1;
+ }
+
+ public double sin(double num1) {
+ result = Math.sin(num1);
+ result = applyUnitMode(result);
+ return result;
+ // this works
+ }
+
+ public double cosine(double num1) {
+ result = Math.cos(num1);
+ result = applyUnitMode(result);
+ return result;
+ // this works
+ }
+
+
+ public double tangent(double num1) {
+ result = Math.tan(num1);
+ result = applyUnitMode(result);
+ return result;
+ // this works
+ }
+
+
+ public double inverseSin(double num1) {
+ result = Math.asin(num1);
+ result = applyUnitMode(result);
+ return result;
+ // this works
+ // num1 NEEDS TO BE BETWEEN -1 AND 1 otherwise NaN.
+ }
+
+
+ public double inverseCosine(double num1) {
+ result = Math.acos(num1);
+ result = applyUnitMode(result);
+ return result;
+ // this works
+ // num1 NEEDS TO BE BETWEEN -1 AND 1 otherwise NaN
+ }
+
+
+ public double inverseTangent(double num1) {
+ result = Math.atan(num1);
+ result = applyUnitMode(result);
+ return result;
+ // this works
+ // no input restrictions
+ }
+
+
+ public double log(double num1) {
+ result = Math.log(num1);
+ return result;
+ // need to revisit--not sure
+ }
+
+
+ public double inverseLog(double num1) {
+ result = Math.exp(Math.pow(10, num1));
+ return result;
+ // inputs are traditionally known as x and y
+ // needs two inputs
+ }
+
+ public double inverseNaturalLog(double num1) {
+ result = Math.pow(Math.E, num1);
+ return result;
+
+ }
+
+ public double changesign(double num1) {
+ // Implement change sign
+ return num1;
+ }
+
+ public double rad(double num1){
+ result = Math.toRadians(num1);
+ return result;
+ }
+
+ public double degree(double num1){
+ result = Math.toDegrees(num1);
+ return result;
+ }
+
+ //Fibonacci has own class
+
+
+ //Factorial
+ public Double factorial(Double num1) {
+ if (num1 == 0)
+ return 1.00;
+ else
+ return (num1 * factorial(num1 - 1));
+ }
+
+ public Double applyUnitMode(Double result) {
+
+ if (unitsMode == 2) {
+ result = Math.toRadians(result);
+ }
+ return result;
+ }
+
+ public void switchUnitMode() {
+
+ if (unitsMode == 1) {
+ unitsMode = 2;
+ Console.println("Switched Unit Mode from Degree to Radian");
+ } else {
+ unitsMode = 1;
+ Console.println("Switched Unit Mode from Radian to Degree");
+ }
+ }
+
+ public void setUnitMode(int givenUnitMode) {
+
+ unitsMode = givenUnitMode;
+ }
+
+ public String getUnitMode() {
+ if (unitsMode == 1) {
+ return "Degree";
+ } else {
+ return "Radian";
+ }
+ }
+}
+
+
diff --git a/src/test/java/com/zipcodewilmington/scientific_calculator/TestScCalculator.java b/src/test/java/com/zipcodewilmington/scientific_calculator/TestScCalculator.java
new file mode 100644
index 00000000..615113a4
--- /dev/null
+++ b/src/test/java/com/zipcodewilmington/scientific_calculator/TestScCalculator.java
@@ -0,0 +1,315 @@
+package com.zipcodewilmington.scientific_calculator;
+
+
+import com.zipcodewilmington.scientificcalculator.BasicCalculator;
+import com.zipcodewilmington.scientificcalculator.Console;
+import com.zipcodewilmington.scientificcalculator.Fibonacci;
+import com.zipcodewilmington.scientificcalculator.ScFunction;
+import org.junit.Assert;
+
+import org.junit.Test;
+
+public class TestScCalculator {
+
+
+
+ Fibonacci fibo = new Fibonacci();
+ ScFunction scientificCal = new ScFunction();
+ BasicCalculator basicCalc = new BasicCalculator();
+ @Test
+ public void positiveintegerAdderTest() {
+ Double assumed = 2.;
+
+ Double actual = basicCalc.add(1,1);
+ Assert.assertEquals(assumed, actual);
+ }
+
+ @Test
+ public void NegativeIntegerAdderTest() {
+ Double assumed = -200.;
+ Double actual = basicCalc.add(0., -200.);
+ Assert.assertEquals(assumed, actual);
+ }
+
+ @Test
+ public void SubtractionTestPositiveReturn() {
+ Double assumed = 3.;
+ Double actual = basicCalc.subtract(5., 2.);
+ Assert.assertEquals(assumed, actual);
+
+ }
+
+ @Test
+ public void SubtractionTestZeroReturn() {
+ Double assumed = 0.;
+ Double actual = basicCalc.subtract(3., 3.);
+ Assert.assertEquals(assumed, actual);
+ }
+
+ @Test
+ public void SubtractionTestNegativeReturn() {
+ Double assumed = -1.;
+ Double actual = basicCalc.subtract(5., 6.);
+ Assert.assertEquals(assumed, actual);
+ }
+
+ @Test
+ public void MultiplicationPositiveReturn() {
+ Double assumed = 40.;
+ Double actual = basicCalc.multiply(20., 2.);
+ Assert.assertEquals(assumed, actual);
+ }
+
+ @Test
+ public void MultiplicationZeroReturn() {
+ Double assumed = 0.;
+ Double actual = basicCalc.multiply(0., 5.);
+ Assert.assertEquals(assumed, actual);
+ }
+
+ @Test
+ public void MultiplicationNegativeReturn() {
+ Double assumed = -9.;
+ Double actual = basicCalc.multiply(-3., 3.);
+ Assert.assertEquals(assumed, actual);
+ }
+
+ @Test
+ public void MultiplicationBothNegativeNumbers() {
+ Double assumed = 9.;
+ Double actual = basicCalc.multiply(-3., -3.);
+ Assert.assertEquals(assumed, actual);
+ }
+
+ @Test
+ public void DivisionPositiveReturnWholeNumber() {
+ Double assumed = 10.;
+ Double actual = basicCalc.divide(20., 2.);
+ Assert.assertEquals(assumed, actual);
+ }
+
+ @Test
+ public void DivisionPositiveReturnDecimal() {
+ Double assumed = 2.5;
+ Double actual = basicCalc.divide(5., 2.);
+ Assert.assertEquals(assumed, actual);
+ }
+
+ @Test
+ public void squareRootReturnPositiveWholeNumber() {
+ Double assumed = 4.;
+ Double actual = basicCalc.squareRoot(16.);
+ Assert.assertEquals(assumed, actual);
+ }
+
+ @Test
+ public void squareRootReturnPositiveDecimal() {
+ Double assumed = 4.358898943540674;
+ Double actual = basicCalc.squareRoot(19.);
+ Assert.assertEquals(assumed, actual);
+ }
+
+ @Test
+ public void SquareReturnPositiveWholeNumber() {
+ Double assumed = 100.;
+ Double actual = basicCalc.square(10.);
+ Assert.assertEquals(assumed, actual);
+ }
+
+ @Test
+ public void SquareReturnNegativeWholeNumber() {
+ Double assumed = 25.;
+ Double actual = basicCalc.square(-5.);
+ Assert.assertEquals(assumed, actual);
+ }
+
+ @Test
+ public void SquareReturnPositiveDecimal() {
+ Double assumed = 42.25;
+ Double actual = basicCalc.square(6.5);
+ Assert.assertEquals(assumed, actual);
+ }
+
+ @Test
+ public void SquareReturnNegativeDecimal() {
+ Double assumed = 30.25;
+ Double actual = basicCalc.square(-5.5);
+ Assert.assertEquals(assumed, actual);
+ }
+
+
+
+ @Test
+ public void SinePositiveNumber() {
+ Double assumed = 0.9129452507276277;
+ Double actual = scientificCal.sin(20.);
+ Assert.assertEquals(assumed, actual);
+ }
+
+ @Test
+ public void SineNegativeNumber() {
+ Double assumed = 0.5365729180004349;
+ Double actual = scientificCal.sin(-12.);
+ Assert.assertEquals(assumed, actual);
+ }
+
+ @Test
+ public void SineZeroNumber() {
+ Double assumed = 0.;
+ Double actual = scientificCal.sin(0.);
+ Assert.assertEquals(assumed, actual);
+ }
+
+
+ @Test
+ public void CosineNegativeNumber() {
+ Double assumed = -0.7596879128588213;
+ Double actual = scientificCal.cosine(-15.);
+ Assert.assertEquals(assumed, actual);
+ }
+
+ @Test
+ public void CosinePositiveNumber() {
+ Double assumed = -0.7596879128588213;
+ Double actual = scientificCal.cosine(-15.);
+ Assert.assertEquals(assumed, actual);
+ }
+
+ @Test
+ public void CosineZeroNumber() {
+ Double assumed = 1.;
+ Double actual = scientificCal.cosine(0.);
+ Assert.assertEquals(assumed, actual);
+ }
+
+ @Test
+ public void TangentZeroNumber() {
+ Double assumed = 0.;
+ Double actual = scientificCal.tangent(0.);
+ Assert.assertEquals(assumed, actual);
+ }
+
+ @Test
+ public void TangentPositiveNumber() {
+ Double assumed = -0.8559934009085188;
+ Double actual = scientificCal.tangent(15.);
+ Assert.assertEquals(assumed, actual);
+ }
+
+ @Test
+ public void TangentNegativeNumber() {
+ Double assumed = 0.8559934009085188;
+ Double actual = scientificCal.tangent(-15.);
+ Assert.assertEquals(assumed, actual);
+ }
+
+ @Test
+ public void ExponentPositiveNumbers() {
+ Double assumed = 4.;
+ Double actual = basicCalc.exponentiation(2., 2.);
+ Assert.assertEquals(assumed, actual);
+ }
+
+ @Test
+ public void ExponentNegativeNumbers() {
+ Double assumed = 4.;
+ Double actual = basicCalc.exponentiation(-2., 2.);
+ Assert.assertEquals(assumed, actual);
+ }
+
+ @Test
+ public void ExponentNegativeExponentPositiveNumber() {
+ Double assumed = 0.0625;
+ Double actual = basicCalc.exponentiation(4., -2.);
+ Assert.assertEquals(assumed, actual);
+ }
+
+ @Test
+ public void ExponentNegativeExponentNegativeNumber() {
+ Double assumed = 0.0625;
+ Double actual = basicCalc.exponentiation(-4., -2.);
+ Assert.assertEquals(assumed, actual);
+ }
+
+ @Test
+ public void ExponentZeroPositiveNumber() {
+ Double assumed = 1.;
+ Double actual = basicCalc.exponentiation(2., .0);
+ Assert.assertEquals(assumed, actual);
+ }
+
+ @Test
+ public void ExponentZeroZeroNumber() {
+ Double assumed = 1.;
+ Double actual = basicCalc.exponentiation(0., .0);
+ Assert.assertEquals(assumed, actual);
+ }
+ @Test
+ public void Factorial(){
+ Double assumed = 120.;
+ Double actual = scientificCal.factorial(5.);
+ Assert.assertEquals(assumed, actual);
+ }
+ @Test
+ public void Fibonacci(){
+ String assumed = " 0 1 1 2 3";
+ String actual = fibo.fibonacci(5.);
+ Assert.assertEquals(assumed, actual);
+
+ }
+ @Test
+ public void Fibonacci2(){
+ String assumed = " 0 1 1 2 3 5 8";
+ String actual = fibo.fibonacci(7.);
+ Assert.assertEquals(assumed, actual);
+
+ }
+ @Test
+ public void Fibonacci3BigNumber(){
+ String assumed = " 0 1 1 2 3 5 8 13 21 34 55 89 144 233 377 610 987 1597 2584 4181 6765 10946 17711 28657 46368 75025 121393 196418 317811 514229 832040 1346269";
+ String actual = fibo.fibonacci(32.);
+ Assert.assertEquals(assumed, actual);
+
+ }
+ @Test
+ public void ConvertToBinary() {
+ String assumed = "10100";
+ String actual = Console.applyDisplayMode(20, 2);
+ Assert.assertEquals(assumed, actual);
+ }
+
+ @Test
+ public void ConvertToBinary2(){
+ String assumed = "11111010000";
+ String actual = Console.applyDisplayMode(2000, 2);
+ Assert.assertEquals(assumed, actual);
+ }
+
+ @Test
+ public void ConvertToOctal(){
+ String assumed = "12";
+ String actual = Console.applyDisplayMode(10, 3);
+ Assert.assertEquals(assumed, actual);
+ }
+ @Test
+ public void ConvertToOctal2(){
+ String assumed = "764";
+ String actual = Console.applyDisplayMode(500, 3);
+ Assert.assertEquals(assumed, actual);
+ }
+
+ @Test // Need to Fix this test
+ public void ConvertToHex(){
+ String assumed = "b";
+ String actual = Console.applyDisplayMode(11, 4);
+ Assert.assertEquals(assumed, actual);
+ }
+ @Test
+ public void ConvertToHex2(){
+ String assumed = "9e";
+ String actual = Console.applyDisplayMode(158.0, 4);
+ Assert.assertEquals(assumed, actual);
+ }
+ }
+
+