diff --git a/.DS_Store b/.DS_Store
new file mode 100644
index 00000000..7e005e57
Binary files /dev/null and b/.DS_Store differ
diff --git a/MainApplication.uml b/MainApplication.uml
new file mode 100644
index 00000000..9200f767
--- /dev/null
+++ b/MainApplication.uml
@@ -0,0 +1,22 @@
+
+
+ JAVA
+ com.zipcodewilmington.scientificcalculator.MainApplication
+
+ com.zipcodewilmington.scientificcalculator.MainApplication
+
+
+
+
+
+ com.zipcodewilmington.scientificcalculator.MainApplication
+
+
+ Fields
+ Constructors
+ Methods
+
+ All
+ private
+
+
diff --git a/TestMainApplication.uml b/TestMainApplication.uml
new file mode 100644
index 00000000..8e495989
--- /dev/null
+++ b/TestMainApplication.uml
@@ -0,0 +1,22 @@
+
+
+ JAVA
+ com.zipcodewilmington.scientific_calculator.TestMainApplication
+
+ com.zipcodewilmington.scientific_calculator.TestMainApplication
+
+
+
+
+
+ com.zipcodewilmington.scientific_calculator.TestMainApplication
+
+
+ Fields
+ Constructors
+ Methods
+
+ All
+ private
+
+
diff --git a/pom.xml b/pom.xml
index e7cb4f6b..d1c9be3d 100644
--- a/pom.xml
+++ b/pom.xml
@@ -7,6 +7,38 @@
com.zipcodewilmington
scientific_calculator
1.0-SNAPSHOT
+
+
+
+ org.apache.maven.plugins
+ maven-compiler-plugin
+
+ 8
+ 8
+
+
+
+
+
+
+ junit
+ junit
+ 4.12
+ test
+
+
+ junit
+ junit
+ 4.12
+ test
+
+
+ junit
+ junit
+ 4.12
+ test
+
+
\ No newline at end of file
diff --git a/src/.DS_Store b/src/.DS_Store
new file mode 100644
index 00000000..0787fb7b
Binary files /dev/null and b/src/.DS_Store differ
diff --git a/src/main/.DS_Store b/src/main/.DS_Store
new file mode 100644
index 00000000..63b728b4
Binary files /dev/null and b/src/main/.DS_Store differ
diff --git a/src/main/java/.DS_Store b/src/main/java/.DS_Store
new file mode 100644
index 00000000..0a8bc21e
Binary files /dev/null and b/src/main/java/.DS_Store differ
diff --git a/src/main/java/com/.DS_Store b/src/main/java/com/.DS_Store
new file mode 100644
index 00000000..79f01664
Binary files /dev/null and b/src/main/java/com/.DS_Store differ
diff --git a/src/main/java/com/zipcodewilmington/.DS_Store b/src/main/java/com/zipcodewilmington/.DS_Store
new file mode 100644
index 00000000..5eb53395
Binary files /dev/null and b/src/main/java/com/zipcodewilmington/.DS_Store differ
diff --git a/src/main/java/com/zipcodewilmington/scientificcalculator/Console.java b/src/main/java/com/zipcodewilmington/scientificcalculator/Console.java
index 83f0e97f..724f24c1 100644
--- a/src/main/java/com/zipcodewilmington/scientificcalculator/Console.java
+++ b/src/main/java/com/zipcodewilmington/scientificcalculator/Console.java
@@ -22,11 +22,20 @@ public static String getStringInput(String prompt) {
return userInput;
}
+
public static Integer getIntegerInput(String prompt) {
- return null;
+ Scanner scanner = new Scanner(System.in);
+ println(prompt);
+ int userInput = scanner.nextInt();
+ return userInput;
}
public static Double getDoubleInput(String prompt) {
- return null;
+ Scanner scanner = new Scanner(System.in);
+ println(prompt);
+ double userInput = scanner.nextDouble();
+ return userInput;
}
-}
+
+
+}
\ No newline at end of file
diff --git a/src/main/java/com/zipcodewilmington/scientificcalculator/MainApplication.java b/src/main/java/com/zipcodewilmington/scientificcalculator/MainApplication.java
index 5f421325..db881f0f 100644
--- a/src/main/java/com/zipcodewilmington/scientificcalculator/MainApplication.java
+++ b/src/main/java/com/zipcodewilmington/scientificcalculator/MainApplication.java
@@ -1,17 +1,650 @@
package com.zipcodewilmington.scientificcalculator;
+import com.sun.codemodel.internal.JWhileLoop;
+import java.time.LocalDateTime;
+import java.time.format.DateTimeFormatter;
+
/**
* Created by leon on 2/9/18.
*/
public class MainApplication {
+ public static boolean startLoop = true;
+ private static String currentMode = "binary";
+ private static String currentUnit = "degrees";
+ private static double currentValue = 0.0; // Current Value
+ private static double memoryValue = 0.0; // Value Stored in Memory
+ private static String displayValue = ""; //String.valueOf(currentValue)
+
+
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);
}
+
+ public static void runCalculator() {
+ Console.println("HI! I'M CODEB0T0VER9000!");
+ Console.println("I SEE YOU NEED HELP WITH YOUR MATH FRIEND, HOW MAY I BE OF SERVICE?");
+
+ while (startLoop) {
+ while (displayValue.equals("Err")) {
+ userInputDouble = Console.getDoubleInput("Please press 0 to continue");
+ if (userInputDouble == 0) {
+ clearDisplay();
+ }
+
+ }
+ Console.println("0-Clear Display");
+ Console.println("1-Add 2-Subtract 3-Multiple 4-Divide");
+ Console.println("5-Square 6-Square Root 7-Exponentiation 8-Inverse 9-Change Sign 10-Factorial");
+ Console.println("11-Sine 12-Cosine 13-Tangent");
+ Console.println("14-Inverse Sine 15-Inverse Cosine 16-Inverse Tangent");
+ Console.println("17-Switch Trig Units 18-Select Trig Units");
+ Console.println("19-Log 20-Inverse Log 21-Natural Log 22-Inverse Natural Log");
+ Console.println("23-Clear memory 24-Add value to memory 25-Recall memory");
+ Console.println("26-Switch Display Mode 27-Choose Display Mode");
+ Console.println("28-Show Current Time");
+ Console.println("99-EXIT CALCULATOR");
+ Console.println("");
+ Console.println("CURRENT DISPLAY: " + displayValue);
+ Console.println("");
+
+
+ Integer choice = Console.getIntegerInput("Enter the number of the operation you want to perform.");
+
+ switch (choice) {
+ case 0:
+ clearDisplay();
+ System.out.println(displayValue);
+ break;
+ case 1:
+ userInputDouble = Console.getDoubleInput("Enter first number");
+ userInputDouble2 = Console.getDoubleInput("Enter second number");
+ findSum(userInputDouble, userInputDouble2);
+ System.out.println(displayValue);
+ break;
+ case 2:
+ userInputDouble = Console.getDoubleInput("Enter first number");
+ userInputDouble2 = Console.getDoubleInput("Enter second number");
+ findDifference(userInputDouble, userInputDouble2);
+ System.out.println(displayValue);
+ break;
+ case 3:
+ userInputDouble = Console.getDoubleInput("Enter first number");
+ userInputDouble2 = Console.getDoubleInput("Enter second number");
+ findProduct(userInputDouble, userInputDouble2);
+ System.out.println(displayValue);
+ break;
+ case 4:
+ userInputDouble = Console.getDoubleInput("Enter first number");
+ userInputDouble2 = Console.getDoubleInput("Enter second number");
+ findQuotient(userInputDouble, userInputDouble2);
+ System.out.println(displayValue);
+ break;
+ case 5:
+ userInputDouble = Console.getDoubleInput("Enter a number");
+ getSquare(userInputDouble);
+ System.out.println(displayValue);
+ break;
+ case 6:
+ userInputDouble = Console.getDoubleInput("Enter a number");
+ getSquareRoot(userInputDouble);
+ System.out.println(displayValue);
+ break;
+ case 7:
+ userInputDouble = Console.getDoubleInput("Enter first number");
+ userInputDouble2 = Console.getDoubleInput("Enter second number");
+ getExponentiation(userInputDouble, userInputDouble2);
+ System.out.println(displayValue);
+ break;
+ case 8:
+ userInputDouble = Console.getDoubleInput("Enter a number");
+ getInverse(userInputDouble);
+ System.out.println(displayValue);
+ break;
+ case 9:
+ userInputDouble = Console.getDoubleInput("Enter a number");
+ getSignInversion(userInputDouble);
+ System.out.println(displayValue);
+ break;
+ case 10:
+ userInputDouble = Console.getDoubleInput("Enter a number");
+ findFactorial(userInputDouble);
+ break;
+ case 11:
+ userInputDouble = Console.getDoubleInput("Enter a number");
+ getSin(userInputDouble);
+ System.out.println(displayValue);
+ break;
+ case 12:
+ userInputDouble = Console.getDoubleInput("Enter a number");
+ getCos(userInputDouble);
+ System.out.println(displayValue);
+ break;
+ case 13:
+ userInputDouble = Console.getDoubleInput("Enter a number");
+ getTan(userInputDouble);
+ System.out.println(displayValue);
+ break;
+ case 14:
+ userInputDouble = Console.getDoubleInput("Enter a number");
+ getAsin(userInputDouble);
+ System.out.println(displayValue);
+ break;
+ case 15:
+ userInputDouble = Console.getDoubleInput("Enter a number");
+ getAcos(userInputDouble);
+ System.out.println(displayValue);
+ break;
+ case 16:
+ userInputDouble = Console.getDoubleInput("Enter a number");
+ getAtan(userInputDouble);
+ System.out.println(displayValue);
+ break;
+ case 17:
+ switchUnitsMode();
+ break;
+ case 18:
+ String trigMode = Console.getStringInput("Enter the desired trig units mode");
+ switchUnitsMode(trigMode);
+ break;
+ case 19:
+ userInputDouble = Console.getDoubleInput("Enter a number");
+ logarithm(userInputDouble);
+ System.out.println(displayValue);
+ break;
+ case 20:
+ userInputDouble = Console.getDoubleInput("Enter a number");
+ invLog(userInputDouble);
+ System.out.println(displayValue);
+ break;
+ case 21:
+ userInputDouble = Console.getDoubleInput("Enter a number");
+ natLog(userInputDouble);
+ System.out.println(displayValue);
+ break;
+ case 22:
+ userInputDouble = Console.getDoubleInput("Enter a number");
+ invNatLog(userInputDouble);
+ System.out.println(displayValue);
+ break;
+ case 23:
+ clearMemory();
+ break;
+ case 24:
+ addCurrentValueToMemory();
+ break;
+ case 25:
+ recallMemoryValue();
+ break;
+ case 26:
+ switchDisplayMode();
+ break;
+ case 27:
+ String mode = Console.getStringInput("Enter the desired mode");
+ switchDisplayMode(mode);
+ break;
+ case 28:
+ getTime();
+ System.out.println(displayValue);
+ break;
+ case 99:
+ startLoop = false;
+ System.out.println("Goodbye");
+ break;
+ case 100:
+ playGame();
+ break;
+ default:
+ System.out.println("Invalid choice! Please enter a valid number.");
+ break;
+ }
+ }
+ }
+
+
+ public static double userInputDouble = 0.0;
+ public static double userInputDouble2 = 0;
+
+ public static void clearDisplay(){
+ currentValue = 0;
+ displayValue = String.valueOf(currentValue);
+ }
+
+ //IM A BASIC B
+ public static double findSum(double a, double b) {
+ currentValue = a + b;
+ displayValue = String.valueOf(currentValue);
+ return currentValue;
+ }
+
+ public static double findDifference(double a, double b) {
+ currentValue = a - b;
+ displayValue = String.valueOf(currentValue);
+ return currentValue;
+ }
+
+ public static double findProduct(double a, double b) {
+ currentValue = a * b;
+ displayValue = String.valueOf(currentValue);
+ return currentValue;
+ }
+
+ public static double findQuotient(double a, double b) {
+ if (b != 0){
+ currentValue = a / b;
+ displayValue = String.valueOf(currentValue);
+ } else displayValue = "Err";
+
+ return currentValue;
+ }
+
+ public static double findRemainder(double a, double b) {
+ currentValue = a % b;
+ displayValue = String.valueOf(currentValue);
+ return currentValue;
+ }
+
+ // MEMORY
+ // public static Double acceptUserInput()
+
+ public static double getMemoryValue() {
+ displayValue = String.valueOf(memoryValue);
+ return memoryValue;
+ }
+
+ // Set the current value
+ public static double setCurrentValue(double input) {
+ currentValue = input;
+ displayValue = String.valueOf(currentValue);
+ return currentValue;
+ }
+
+ // Return the current value
+ public static double returnCurrentValue() {
+ displayValue = String.valueOf(currentValue);
+ return currentValue;
+ }
+
+ // M+ KEY: Recall current value from memory to the display
+ public static double recallMemoryValue() {
+ displayValue = String.valueOf(memoryValue);
+ return memoryValue;
+ }
+
+ // MC KEY: Reset the memory & Clear Display
+ public static double clearMemory() {
+ memoryValue = 0.0;
+ displayValue = String.valueOf(memoryValue);
+ return memoryValue;
+ }
+
+
+ // MC+ KEY: Add currently displayed value to the value in memory & clear display
+ public static double addCurrentValueToMemory() {
+ memoryValue = currentValue;
+ currentValue = 0.0;
+ displayValue = String.valueOf(currentValue);
+ return currentValue;
+ }
+
+ // BASIC CALCULATOR OPERATIONS
+
+
+ // SCIENTIFIC CALCULATOR OPERATIONS
+
+ // Find the factorial of a number
+ public static double findFactorial(double userInput) {
+ double factorial = userInput;
+ for (int i = 1; i < factorial; i++) {
+ userInput *= i;
+ }
+
+ setCurrentValue(userInput);
+ displayValue = String.valueOf(currentValue);
+ return currentValue;
+ }
+
+
+ //Following methods take a value (num1) for the log equations.
+ //Logarithms
+
+ //Takes a value for num2 for the log equation. num1 is not used in this case
+
+ public static double logarithm(double num1) {
+ currentValue = Math.log10(num1);
+ displayValue = String.valueOf(currentValue);
+ return currentValue;
+ }
+
+ //Inverted Logs
+
+
+ public static double invLog(double num1) {
+ currentValue = Math.pow(10,num1);
+ displayValue = String.valueOf(currentValue);
+ return currentValue;
+
+ }
+ //Natural Logs
+ public static double natLog(double num1) {
+ currentValue = Math.log(num1);
+ displayValue = String.valueOf(currentValue);
+ return currentValue;
+ }
+ //Inverted Natural Logs
+
+
+ public static double invNatLog(double num1) {
+ currentValue = Math.pow(Math.E,num1);
+ displayValue = String.valueOf(currentValue);
+ return currentValue;
+ }
+
+
+
+ //DISPLAY CHANGES
+
+ public static void getMode() {
+ displayValue = String.valueOf(currentMode);
+ }
+ //public void setMode(String newMode){currentMode = newMode;}
+
+ public static String switchDisplayMode() {
+
+ if (currentMode.equals("binary")) {
+ currentMode = "octal";
+ displayValue = currentMode;
+ } else if (currentMode.equals("octal")) {
+ currentMode = "decimal";
+ displayValue = currentMode;
+ } else if (currentMode.equals("decimal")) {
+ currentMode = "hexadecimal";
+ displayValue = currentMode;
+ } else if (currentMode.equals("hexadecimal")) {
+ currentMode = "binary";
+ displayValue = currentMode;
+ } else
+ displayValue = "Err";
+ return currentMode;
+ }
+
+
+ public static String switchDisplayMode(String mode) {
+
+ if (mode.equals("binary")) {
+ currentMode = "binary";
+ displayValue = currentMode;
+ } else if (mode.equals("octal")) {
+ currentMode = "octal";
+ displayValue = currentMode;
+ } else if (mode.equals("decimal")) {
+ currentMode = "decimal";
+ displayValue = currentMode;
+ } else if (mode.equals("hexadecimal")) {
+ currentMode = "hexadecimal";
+ displayValue = currentMode;
+ } else mode = "Err";
+ displayValue = mode;
+ System.out.println("Err");
+ return mode;
+ }
+
+ //UNIT CHANGES
+
+ public static void getUnit() {
+ displayValue = currentUnit;
+ System.out.println(currentUnit);
+ }
+
+ public static String switchUnitsMode() {
+ if (currentUnit.equals("degrees")) {
+ currentUnit = "radians";
+ displayValue = currentUnit;
+ } else if (currentUnit.equals("radians")) {
+ currentUnit = "degrees";
+ displayValue = currentUnit;
+ } else
+ displayValue = "Err";
+ return currentUnit;
+ }
+
+ public static String switchUnitsMode(String mode) {
+ if (mode.equals("degrees")) {
+ currentUnit = "degrees";
+ displayValue = currentUnit;
+ } else if (mode.equals("radians")) {
+ currentUnit = "radians";
+ displayValue = currentUnit;
+ } else mode = "Err";
+ displayValue = mode;
+ System.out.println("Err");
+ return mode;
+ }
+ // TRIG FUNCTIONS
+
+ public static double getSin (double a) {
+ double b=Math.toRadians(a);
+ currentValue = (Math.sin(b));
+ displayValue = String.valueOf(currentValue);
+ return currentValue;
+ }
+
+
+ public static double getSinPi (double a) {
+ //double b=Math.toRadians(a);
+ System.out.println(Math.sin(a));
+ return (Math.sin(a));
+ }
+
+
+ public static double getCos(double a) {
+ double b=Math.toRadians(a);
+ currentValue = (Math.cos(b));
+ displayValue = String.valueOf(currentValue);
+ return currentValue;
+ }
+
+
+ public static double getCosPi (double a) {
+ //double b=Math.toRadians(a);
+ System.out.println(Math.cos(a));
+ return (Math.cos(a));
+ }
+
+
+ public static double getTan(double a) {
+ double b=Math.toRadians(a);
+ currentValue = (Math.tan(b));
+ displayValue = String.valueOf(currentValue);
+ return currentValue;
+ }
+
+ public static double getAsinPi(double a) {
+ currentValue = (Math.asin(a));
+ displayValue = String.valueOf(currentValue);
+ return currentValue;
+ }
+
+ public static double getAcosPi(double a) {
+ currentValue = (Math.acos(a));
+ displayValue = String.valueOf(currentValue);
+ return currentValue;
+ }
+
+ public static double getAsin(double a) {
+ double b=Math.toRadians(a);
+ currentValue = (Math.asin(b));
+ displayValue = String.valueOf(currentValue);
+ return currentValue;
+ }
+
+ public static double getAcos (double a){
+ double b=Math.toRadians(a);
+ currentValue = (Math.acos(b));
+ displayValue = String.valueOf(currentValue);
+ return currentValue;
+ }
+
+ public static double getAtan (double a){
+ currentValue = (Math.atan(a));
+ displayValue = String.valueOf(currentValue);
+ return currentValue;
+ }
+
+
+ // ADVANCED FUNCTIONS
+
+ // Invert sign
+ public static double getSignInversion(double num1) {
+ if (num1 != 0) {
+ currentValue = num1 * -1;
+ displayValue = String.valueOf(currentValue);
+ } else currentValue = 0;
+ displayValue = String.valueOf(currentValue);
+ return currentValue;
+ }
+
+
+ // Compute square
+ public static double getSquare(double num1) {
+ currentValue = num1 * num1;
+ displayValue = String.valueOf(currentValue);
+ return currentValue;
+ }
+
+ // Square Root
+ public static double getSquareRoot(double num1) {
+ if (num1 >= 0) {
+ currentValue = Math.sqrt(num1);
+ displayValue = String.valueOf(currentValue);
+ } else displayValue = "Err";
+ return currentValue;
+ }
+
+ // Exponentiation
+ public static double getExponentiation(double num1, double num2) {
+ currentValue = Math.pow(num1, num2);
+ displayValue = String.valueOf(currentValue);
+ return currentValue;
+ }
+
+ // Inverse (1/x)
+ public static double getInverse(double num1) {
+ if (num1 != 0) {
+ currentValue = 1 / num1;
+ displayValue = String.valueOf(currentValue);
+ } else displayValue = "Err";
+ return currentValue;
+
+ }
+
+ //'Rock,Paper,Scissors' game.
+ //No unit test but tested and debugged live in production.
+ public static void playGame() {
+ boolean gameOn = true;
+ double userChoice;
+ double continueGame;
+ double score = 0;
+ double gamesPlayed = 0;
+ String computerMove;
+ String userMove;
+
+
+
+ while(gameOn) {
+ System.out.println("Let's play a game!");
+ System.out.println("0 = Rock, 1 = Paper, 2 = Scissors");
+ userChoice = Console.getDoubleInput("Enter your selection.");
+
+ double computerDub = (Math.random() * 3);
+
+ if ((computerDub >= 0) && (computerDub < 1)) {
+ computerMove = "Rock";
+ } else if ((computerDub >= 1) && (computerDub < 2)) {
+ computerMove = "Paper";
+ } else if ((computerDub >= 2) && (computerDub < 3)) {
+ computerMove = "Scissors";
+ } else {
+ computerMove = "Invalid, choose 0,1,2";
+ }
+
+ if (userChoice == 0) {
+ userMove = "Rock";
+ } else if (userChoice == 1) {
+ userMove = "Paper";
+ } else if (userChoice == 2) {
+ userMove = "Scissors";
+ } else {
+ System.out.println("Invalid, choose 0,1,2"); continue;
+ }
+
+ System.out.println("You play: " + userMove);
+ System.out.println("I play: " + computerMove);
+ int computerInt = (int) computerDub;
+ int userInt = (int) userChoice;
+
+ switch (userInt) {
+ case 0:
+ if (userInt == computerInt) {
+ System.out.println("We tied!");
+ } else if (computerInt == 1) {
+ System.out.println("Sorry, you lose!");
+ } else { score++;
+ System.out.println("Congratulations, you win!");
+ }
+ break;
+ case 1:
+ if (userInt == computerInt) {
+ System.out.println("We tied!");
+ } else if (computerInt == 0) {
+ score++;
+ System.out.println("Congratulations, you win!");
+ } else {
+ System.out.println("Sorry! You lose!");
+ }
+ break;
+ case 2:
+ if (userInt == computerInt) {
+ System.out.println("We tied");
+ } else if (computerInt == 0) {
+ System.out.println("Sorry, you lose!");
+ } else {
+ score++;
+ System.out.println("Congratulations, you win!");
+ }
+ break;
+
+ }
+ gamesPlayed++;
+
+ System.out.println("You won " + score + " / " + gamesPlayed + "!");
+ System.out.println("Play again? 1 - Yes or 2 - No");
+ continueGame = Console.getDoubleInput("Enter your selection.");
+
+ boolean validInput = true;
+ while (validInput) {
+ if (continueGame == 1) {
+ gameOn = true;
+ break;
+ } else if (continueGame == 2) {
+ System.out.println("Goodbye!");
+ gameOn = false;
+ break;
+ } else System.out.println("Invalid selection: Please choose 1 - Yes or 2 - No");
+ continueGame = Console.getDoubleInput("");
+ }
+
+ }
+
+ }
+
+ //Time display
+ public static void getTime(){
+ DateTimeFormatter timeFormat = DateTimeFormatter.ofPattern("yyyy/MM/dd HH:mm:ss");
+ LocalDateTime now = LocalDateTime.now();
+ displayValue = (timeFormat.format(now));
+ }
+
+
}
+
+
diff --git a/src/test/.DS_Store b/src/test/.DS_Store
new file mode 100644
index 00000000..4da071c0
Binary files /dev/null and b/src/test/.DS_Store differ
diff --git a/src/test/java/.DS_Store b/src/test/java/.DS_Store
new file mode 100644
index 00000000..e8ff6d8f
Binary files /dev/null and b/src/test/java/.DS_Store differ
diff --git a/src/test/java/com/.DS_Store b/src/test/java/com/.DS_Store
new file mode 100644
index 00000000..8497804a
Binary files /dev/null and b/src/test/java/com/.DS_Store differ
diff --git a/src/test/java/com/zipcodewilmington/.DS_Store b/src/test/java/com/zipcodewilmington/.DS_Store
new file mode 100644
index 00000000..9ed55185
Binary files /dev/null and b/src/test/java/com/zipcodewilmington/.DS_Store differ
diff --git a/src/test/java/com/zipcodewilmington/scientific_calculator/TestMainApplication.java b/src/test/java/com/zipcodewilmington/scientific_calculator/TestMainApplication.java
index 94e8d987..288419b6 100644
--- a/src/test/java/com/zipcodewilmington/scientific_calculator/TestMainApplication.java
+++ b/src/test/java/com/zipcodewilmington/scientific_calculator/TestMainApplication.java
@@ -1,7 +1,334 @@
package com.zipcodewilmington.scientific_calculator;
+import static org.junit.Assert.assertEquals;
+import com.zipcodewilmington.scientificcalculator.MainApplication;
+import org.junit.AfterClass;
+import org.junit.BeforeClass;
+import org.junit.Test;
+import org.junit.experimental.theories.suppliers.TestedOn;
+import javax.naming.NameNotFoundException;
+import static org.junit.Assert.assertNotEquals;
+import static org.junit.Assert.*;
/**
* Created by leon on 2/9/18.
*/
+
public class TestMainApplication {
+
+ //Basic functions tests
+ @Test
+ public void getSum() {
+ MainApplication testSum = new MainApplication();
+ assertEquals(10, testSum.findSum(8, 2), 0.0000001);
+ assertEquals(163.987, testSum.findSum(100, 63.987), 0.0000001);
+ assertEquals(420, testSum.findSum(69, 351), 0.0000001);
+ }
+
+ @Test
+ public void getDifference() {
+ MainApplication testDiff = new MainApplication();
+ assertEquals(8, testDiff.findDifference(15, 7), 0.0000001);
+ assertEquals(99.9, testDiff.findDifference(100.9, 1), 0.0000001);
+ assertEquals(69, testDiff.findDifference(420, 351), 0.0000001);
+ }
+
+ @Test
+ public void getProduct() {
+ MainApplication testProduct = new MainApplication();
+ assertEquals(100, testProduct.findProduct(10, 10), 0.0000001);
+ assertEquals(12.5, testProduct.findProduct(2.5, 5), 0.0000001);
+ assertEquals(28980, testProduct.findProduct(69, 420), 0.0000001);
+ }
+
+ @Test
+ public void getQuotient() {
+ MainApplication testQuotient = new MainApplication();
+ assertEquals(10, testQuotient.findQuotient(100, 10), 0.0000001);
+ assertEquals(33.3, testQuotient.findQuotient(99.9, 3), 0.0000001);
+ assertEquals(6.0869565, testQuotient.findQuotient(420, 69), 0.0000001);
+ }
+
+ @Test
+ public void getRemainder() {
+ MainApplication testRemainder = new MainApplication();
+ assertEquals(1, testRemainder.findRemainder(17, 2), 0.0000001);
+ assertEquals(3, testRemainder.findRemainder(23, 5), 0.0000001);
+ assertEquals(0, testRemainder.findRemainder(420, 2), 0.0000001);
+ }
+
+ //Log base 10 method tests
+ @Test
+ public void getLog0() {
+ MainApplication newLog = new MainApplication();
+ assertEquals(3.0, newLog.logarithm(1000.0), 0.0000001);
+ assertEquals(1.0, newLog.logarithm(10.0), 0.0000001);
+ assertEquals(-0.3010299957, newLog.logarithm(0.5), 0.0000001);
+ assertEquals(-1.0, newLog.logarithm(0.1), 0.0000001);
+ assertEquals(Double. NEGATIVE_INFINITY, newLog.logarithm(0.0), 0.0000001);
+ assertEquals(Double.NaN, newLog.logarithm(-1.0), 0.0000001);
+ }
+
+
+ @Test //Inverted log base 10 test
+ public void getInvLog0() {
+ MainApplication newLog = new MainApplication();
+ assertEquals(100000.0, newLog.invLog(5.0), 0.0000001);
+ assertEquals(10.0, newLog.invLog(1.0), 0.0000001);
+ assertEquals(3.16227766, newLog.invLog(0.5), 0.0000001);
+ assertEquals(1.258925412, newLog.invLog(0.1), 0.0000001);
+ assertEquals(0.1, newLog.invLog(-1.0), 0.0000001);
+ }
+
+
+ @Test //Natural Log tests
+ public void getNatLog0() {
+ MainApplication newLog = new MainApplication();
+ assertEquals(1.609437912, newLog.natLog(5.0), 0.0000001);
+ assertEquals(0.0, newLog.natLog(1.0), 0.0000001);
+ assertEquals(Double.NEGATIVE_INFINITY, newLog.natLog(0.0), 0.0000001);
+ assertEquals(Double.NaN, newLog.natLog(-1), 0.0000001);
+ assertEquals(-2.302585093, newLog.natLog(0.1), 0.0000001);
+ }
+
+ @Test //Inverted Natural Log tests
+ public void getInvNatLog0() {
+ MainApplication newLog = new MainApplication();
+ assertEquals(148.4131591, newLog.invNatLog(5.0), 0.0000001);
+ assertEquals(1.0, newLog.invNatLog(0.0), 0.0000001);
+ assertEquals(0.3678794412, newLog.invNatLog(-1.0), 0.0000001);
+ assertEquals(1.105170918, newLog.invNatLog(0.1), 0.0000001);
+ assertEquals(0.904837418, newLog.invNatLog(-0.1), 0.0000001);
+ }
+
+
+
+ @Test //Log base 10 method test
+ public void getLog10() {
+ MainApplication newLog = new MainApplication();
+ assertEquals(1.0, newLog.logarithm(10.0), 0.0000001);
+ }
+ @Test //Log base 10 method Err test
+ public void getLog101() {
+ MainApplication newLog = new MainApplication();
+ assertEquals(Double. NEGATIVE_INFINITY, newLog.logarithm(0.0), 0.0000001);
+ }
+
+
+ @Test //Inverted log test
+ public void getInvLog10() {
+ MainApplication newLog = new MainApplication();
+ assertEquals(100000.0, newLog.invLog(5.0), 0.0000001);
+ }
+ @Test //Natural Log test
+ public void getNetLog() {
+ MainApplication newLog = new MainApplication();
+ assertEquals(1.609437912, newLog.natLog(5.0), 0.0000001);
+ }
+ @Test //Inverted Natural Log test
+ public void getInvNetLog() {
+ MainApplication newLog = new MainApplication();
+ assertEquals(148.4131591, newLog.invNatLog(5.0), 0.0000001);
+ }
+
+
+
+ @Test
+ public void displayTest() {
+ MainApplication displaytester = new MainApplication();
+ assertEquals("binary", displaytester.switchDisplayMode());
+ assertEquals("octal", displaytester.switchDisplayMode());
+ assertEquals("decimal", displaytester.switchDisplayMode());
+ assertEquals("hexadecimal", displaytester.switchDisplayMode());
+ }
+
+ @Test
+ public void modeChange() {
+ MainApplication modeChanger = new MainApplication();
+
+ assertEquals("binary", modeChanger.switchDisplayMode("binary"));
+ assertEquals("hexadecimal", modeChanger.switchDisplayMode("hexadecimal"));
+ assertEquals("Err", modeChanger.switchDisplayMode("hello!"));
+ }
+
+ @Test
+ public void unitChangeButton() {
+ MainApplication unitChanger = new MainApplication();
+
+ assertEquals("radians", unitChanger.switchUnitsMode());
+ assertEquals("degrees", unitChanger.switchUnitsMode());
+ assertEquals("radians", unitChanger.switchUnitsMode());
+ }
+
+ @Test
+ public void unitChange() {
+ MainApplication unitChanger1 = new MainApplication();
+
+ assertEquals("radians", unitChanger1.switchUnitsMode("radians"));
+ assertEquals("Err", unitChanger1.switchUnitsMode("Break me"));
+ assertEquals("degrees", unitChanger1.switchUnitsMode("degrees"));
+ }
+
+ @Test
+ public void sinTest() {
+ MainApplication sinTest1 = new MainApplication();
+ assertEquals(-1, sinTest1.getSin(270.0),0.000000001);
+ assertEquals(0.5, sinTest1.getSin(30.0),0.000000001);
+ assertEquals(1.0, sinTest1.getSin(90.0),0.000000001);
+ //assertEquals(Float.NaN, sinTest1.getSin(30.0),0.000000001);
+ }
+ @Test
+ public void sinpiTest(){
+ MainApplication sinpiTest1 = new MainApplication();
+ assertEquals(Float.NaN,sinpiTest1.getSinPi(Double.NaN),0.000001);
+ assertEquals(Float.NaN,sinpiTest1.getSinPi(Double.NEGATIVE_INFINITY),0.000001);
+ assertEquals(Float.NaN,sinpiTest1.getSinPi(Double.POSITIVE_INFINITY),0.000001);}
+ @Test
+ public void cosTest() {
+ MainApplication cosTest1 = new MainApplication();
+ assertEquals(0.866025,cosTest1.getCos(30.0),0.000001);
+ assertEquals(0.5,cosTest1.getCos(60.0),0.1);
+ assertEquals(1.0,cosTest1.getCos(0.0),0.1);
+ }
+
+ @Test
+ public void cospiTest(){
+ MainApplication cospiTest1 = new MainApplication();
+ assertEquals(Float.NaN,cospiTest1.getCosPi(Double.NaN),0.000001);
+ assertEquals(Float.NaN,cospiTest1.getCosPi(Double.NEGATIVE_INFINITY),0.000001);
+ assertEquals(Float.NaN,cospiTest1.getCosPi(Double.POSITIVE_INFINITY),0.000001);}
+ @Test
+ public void tanTest() {
+ MainApplication tanTest1 = new MainApplication();
+ assertEquals(0,tanTest1.getTan(0.0),0.001);
+ assertEquals(1,tanTest1.getTan(45.0),0.001);
+ assertEquals(1.732,tanTest1.getTan(60.0),0.001);
+
+ }
+ @Test
+ public void asinpiTest(){
+ MainApplication asinTest1 = new MainApplication();
+ assertEquals(Float.NaN,asinTest1.getAsinPi(Math.PI),0.000001);
+ assertEquals(Float.NaN,asinTest1.getAsinPi(Double.NEGATIVE_INFINITY),0.000001);
+ assertEquals(Float.NaN,asinTest1.getAsinPi(Double.POSITIVE_INFINITY),0.000001);
+ }
+ @Test
+ public void asinTest(){
+ MainApplication asinTest1 = new MainApplication();
+ assertEquals(0.0,asinTest1.getAsin(0.0),0.000001);
+ assertEquals(0.903,asinTest1.getAsin(45),0.001);
+ assertEquals(-0.903,asinTest1.getAsin(-45),0.001);
+ }
+ @Test
+ public void acosTest(){
+ MainApplication acosTest1 = new MainApplication();
+ assertEquals(0.2840,acosTest1.getAcos(55),0.0001);
+ assertEquals(1.0197,acosTest1.getAcos(30.0),0.001);
+ assertEquals(1.3953,acosTest1.getAcos(10.0),0.001);
+
+ }
+ @Test
+ public void acospiTest(){
+ MainApplication acospiTest1 = new MainApplication();
+ assertEquals(Float.NaN,acospiTest1.getAcosPi(Math.PI),0.000001);
+ assertEquals(Float.NaN,acospiTest1.getAsinPi(Double.NEGATIVE_INFINITY),0.000001);
+ assertEquals(Float.NaN,acospiTest1.getAsinPi(Double.POSITIVE_INFINITY),0.000001);
+ }
+
+ @Test
+ public void atanTest(){
+ MainApplication atanTest1 = new MainApplication();
+ assertEquals(0.0,atanTest1.getAtan(0.0), 0.01);
+ assertEquals(1.537,atanTest1.getAtan(30.0), 0.01);
+ assertEquals(1.5541,atanTest1.getAtan(60.0), 0.01);
+ }
+
+
+ @Test
+ public void findFactorial() {
+ MainApplication findFactorialTest = new MainApplication();
+
+ assertEquals(120.0, findFactorialTest.findFactorial(5.0), 1e-15);
+ assertEquals(362880, findFactorialTest.findFactorial(9), 1e-15);
+ assertEquals(6.0, findFactorialTest.findFactorial(3.0), 1e-15);
+ }
+
+ @Test
+ public void setCurrentValue() {
+ MainApplication setCurrentValueTest = new MainApplication();
+
+ assertEquals(10, setCurrentValueTest.setCurrentValue(10), 1e-15);
+ assertEquals(21.1, setCurrentValueTest.setCurrentValue(21.1), 1e-15);
+ assertNotEquals(5.0, setCurrentValueTest.setCurrentValue(5.1), 1e-15);
+ }
+
+ @Test
+ public void clearMemory() {
+ MainApplication clearMemoryTest = new MainApplication();
+ clearMemoryTest.setCurrentValue(420);
+
+ assertEquals(0, clearMemoryTest.addCurrentValueToMemory(), 1e-15);
+ assertEquals(420, clearMemoryTest.getMemoryValue(), 1e-15);
+ assertEquals(0, clearMemoryTest.clearMemory(), 1e-15);
+ assertEquals(0, clearMemoryTest.clearMemory(), 1e-15);
+ assertNotEquals(5.0, clearMemoryTest.clearMemory(), 1e-15);
+ }
+
+ @Test
+ public void testStoredMemory() {
+ MainApplication addMemTest = new MainApplication();
+ addMemTest.setCurrentValue(6.0);
+
+ assertEquals(6.0, addMemTest.returnCurrentValue(), 1e-15);
+ assertEquals(0.0, addMemTest.addCurrentValueToMemory(), 1e-15);
+ assertEquals(6.0, addMemTest.recallMemoryValue(), 1e-15);
+ }
+
+ @Test
+ public void testGetSignInversion() {
+ MainApplication getSignInversion1 = new MainApplication();
+ assertEquals(-2.0, getSignInversion1.getSignInversion(2.0), 0.1);
+ assertEquals(25.0, getSignInversion1.getSignInversion(-25.0), 0.1);
+ assertEquals(0, getSignInversion1.getSignInversion(0), 0.1);
+ }
+
+
+ @Test
+ public void testGetSquare() {
+ MainApplication getSquare1 = new MainApplication();
+ assertEquals(4.0, getSquare1.getSquare(2.0), 0.1);
+ assertEquals(9.0, getSquare1.getSquare(-3.0), 0.1);
+ assertEquals(0.0625, getSquare1.getSquare(-0.25), 0.1);
+ assertEquals(0.0, getSquare1.getSquare(0.0), 0.1);
+ }
+
+ @Test
+ public void testGetSquareRoot() {
+ MainApplication getSquareRoot1 = new MainApplication();
+ assertEquals(4.0, getSquareRoot1.getSquareRoot(16.0), 0.1);
+ assertEquals(0.0, getSquareRoot1.getSquareRoot(0.0), 0.1);
+ }
+
+ @Test
+ public void testGetExponentiation() {
+ MainApplication getExponentiation1 = new MainApplication();
+ assertEquals(8.0, getExponentiation1.getExponentiation(2.0, 3.0), 0.1);
+ assertEquals(-8.0, getExponentiation1.getExponentiation(-2.0, 3.0), 0.1);
+ assertEquals(0.125, getExponentiation1.getExponentiation(2.0, -3.0), 0.1);
+ assertEquals(0.0, getExponentiation1.getExponentiation(0.0, 2.0), 0.1);
+ assertEquals(2.0, getExponentiation1.getExponentiation(4.0, 0.5), 0.1);
+ assertEquals(0.5, getExponentiation1.getExponentiation(4.0, -0.5), 0.1);
+ assertEquals(1.0, getExponentiation1.getExponentiation(1.0, 0.0), 0.1);
+ assertEquals(0.0, getExponentiation1.getExponentiation(0.0, 1.0), 0.1);
+ }
+
+ @Test
+ public void testGetInverse() {
+ MainApplication getInverse1 = new MainApplication();
+ assertEquals(0.25, getInverse1.getInverse(4.0), 0.1);
+ assertEquals(-0.25, getInverse1.getInverse(-4.0), 0.1);
+ assertEquals(.01, getInverse1.getInverse(100), 0.1);
+
+ }
+
}
+