diff --git a/.DS_Store b/.DS_Store new file mode 100644 index 00000000..05feab9d Binary files /dev/null and b/.DS_Store differ diff --git a/UML.png b/UML.png new file mode 100644 index 00000000..018e2886 Binary files /dev/null and b/UML.png differ diff --git a/pom.xml b/pom.xml index e7cb4f6b..ad11bc41 100644 --- a/pom.xml +++ b/pom.xml @@ -9,4 +9,20 @@ 1.0-SNAPSHOT + + + + 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..fff4ccc5 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..0ec6259e 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..1d412679 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..6179e2dd 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..2ac16c3d 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..970ba2b3 100644 --- a/src/main/java/com/zipcodewilmington/scientificcalculator/Console.java +++ b/src/main/java/com/zipcodewilmington/scientificcalculator/Console.java @@ -15,18 +15,125 @@ public static void println(String output, Object... args) { print(output + "\n", args); } + public static Scanner scanner; + public static String getStringInput(String prompt) { - Scanner scanner = new Scanner(System.in); + + scanner = new Scanner(System.in); println(prompt); String userInput = scanner.nextLine(); - return userInput; + return "Hello there " + userInput + "!"; } - public static Integer getIntegerInput(String prompt) { - return null; + public static int getIntegerInput(String prompt) { + + int userInput; + + scanner = new Scanner(System.in); + println(prompt); + String nextNum = scanner.nextLine(); + + try{ + userInput = Integer.parseInt(nextNum); + return userInput; + }catch (Exception e) { + return Console.getIntegerInput(prompt); + } } public static Double getDoubleInput(String prompt) { - return null; + + double userInput; + Display dis = new Display(); + + scanner = new Scanner(System.in); + println(prompt); + String nextNum = scanner.nextLine(); + + try{ + userInput = Double.parseDouble(nextNum); + dis.update(userInput); + return userInput; + }catch (Exception e) { + return Console.getDoubleInput(prompt); + } + + } + + public static int getOperand(String prompt){ + + scanner = new Scanner(System.in); + println(prompt); + String nextOperand = scanner.nextLine(); + + if(nextOperand.equals("+")){ + return 1; + }else if(nextOperand.equals("-")){ + return 2; + }else if(nextOperand.equals("*")){ + return 3; + }else if(nextOperand.equals("/")){ + return 4; + }else if(nextOperand.equalsIgnoreCase("x^2")){ + return 5; + }else if(nextOperand.equalsIgnoreCase("sqrt")){ + return 6; + }else if(nextOperand.equalsIgnoreCase("x^n")){ + return 7; + }else if(nextOperand.equalsIgnoreCase("1/x")){ + return 8; + }else if(nextOperand.equalsIgnoreCase("+/-")){ + return 9; + }else if(nextOperand.equalsIgnoreCase("sin")){ + return 10; + }else if(nextOperand.equalsIgnoreCase("cos")){ + return 11; + }else if(nextOperand.equalsIgnoreCase("tan")){ + return 12; + }else if(nextOperand.equalsIgnoreCase("invSin")){ + return 13; + }else if(nextOperand.equalsIgnoreCase("invCos")){ + return 14; + }else if(nextOperand.equalsIgnoreCase("invTan")){ + return 15; + }else if(nextOperand.equalsIgnoreCase("log")){ + return 16; + }else if(nextOperand.equalsIgnoreCase("invLog")){ + return 17; + }else if(nextOperand.equalsIgnoreCase("Ln")){ + return 18; + }else if(nextOperand.equalsIgnoreCase("invLn")){ + return 19; + }else if(nextOperand.equalsIgnoreCase("!")){ + return 20; + }else if(nextOperand.equalsIgnoreCase("m+")){ + return 21; + }else if(nextOperand.equalsIgnoreCase("mc")){ + return 22; + }else if(nextOperand.equalsIgnoreCase("mrc")){ + return 23; + }else if(nextOperand.equalsIgnoreCase("mode")){ + return 24; + }else if(nextOperand.equalsIgnoreCase("mode x")){ + return 25; + }else if(nextOperand.equalsIgnoreCase("rd")){ + return 26; + }else if(nextOperand.equalsIgnoreCase("rd x")){ + return 27; + }else if(nextOperand.equalsIgnoreCase("prime")){ + return 28; + }else if(nextOperand.equalsIgnoreCase("year%")){ + return 29; + }else if(nextOperand.equalsIgnoreCase("c")){ + return 0; + }else if(nextOperand.equalsIgnoreCase("off")){ + return 100; + }else{ + if(Display.error) System.out.println("Please clear before continuing!"); + return getOperand(prompt); + } } } + + + diff --git a/src/main/java/com/zipcodewilmington/scientificcalculator/Display.java b/src/main/java/com/zipcodewilmington/scientificcalculator/Display.java new file mode 100644 index 00000000..73a28812 --- /dev/null +++ b/src/main/java/com/zipcodewilmington/scientificcalculator/Display.java @@ -0,0 +1,136 @@ +package com.zipcodewilmington.scientificcalculator; + +import sun.applet.Main; + +public class Display { + public boolean checkState = true; + public static boolean error = false; + public int displayMode = 0; + public int unitMode = 0; + + public void clearDisplay() { + checkState = true; + update(0); + error = false; + + } + public void changeNumberDisplay() { + + int intTotal = (int) Math.round(MainApplication.total); + switch (displayMode){ + case 0: + update(intTotal); + displayMode++; + break; + case 1: + update(ScientificCalc.Hexadecimal(intTotal)); + displayMode++; + break; + case 2: + update(ScientificCalc.Octal(intTotal)); + displayMode++; + break; + case 3: + update(ScientificCalc.Binary(intTotal)); + displayMode = 0; + break; + } + } + + public void changeNumberDisplay(String mode) { + + int intTotal = (int) Math.round(MainApplication.total); + if(mode.equalsIgnoreCase("hexa")){ + update(ScientificCalc.Hexadecimal(intTotal)); + }else if(mode.equalsIgnoreCase("binary")) { + update(ScientificCalc.Binary(intTotal)); + }else if(mode.equalsIgnoreCase("octal")){ + update(ScientificCalc.Octal(intTotal)); + }else if(mode.equalsIgnoreCase("deci")){ + update(intTotal); + }else{ + displayErr(); + } + } + + public void changeUnitDisplay(){ + + switch (unitMode){ + case 0: + update(ScientificCalc.radian(MainApplication.total)); + unitMode++; + break; + case 1: + update(ScientificCalc.degree(MainApplication.total)); + unitMode = 0; + break; + } + } + + public void changeUnitDisplay(String unit){ + + if(unit.equalsIgnoreCase("rad")){ + update(ScientificCalc.radian(MainApplication.total)); + }else if(unit.equalsIgnoreCase("deg")){ + update(ScientificCalc.degree(MainApplication.total)); + }else { + displayErr(); + } + } + + public void displayErr() { + //if math calculations don't work, display 'Err') + error = true; + update("Err. Clear screen."); + } + + public void update(double update){ + String[][] calc = { {"C", " RD", "RD X ", " SIN", "invSin", "Off"}, + {"+", "X^2", " Sqrt", " COS", "invCos", " "}, + {"-", "X^N", " 1/x ", " TAN", "invTan", " "}, + {"*", " M+", "Prime", " Log", "invLog", " "}, + {"/", " MC", "Year%", " Ln ", " invLn", " "}, + {"!", "MRC", " +/- ", "Mode", "Mode X", " "}}; + + String dis = String.format("|%27s| ", update); + + System.out.print("\033[H\033[2J"); + System.out.flush(); + System.out.println("-----------------------------"); + System.out.println(dis); + System.out.println("-----------------------------"); + for(int i = 0; i < calc.length; i++){ + for (int j = 0; j < calc.length; j++){ + System.out.print("|" + calc[i][j]); + } + System.out.print("|"); + System.out.println(); + System.out.println(" - --- ----- ---- ------ ---"); + } + } + + public void update(String update){ + String[][] calc = { {"C", " RD", "RD X ", " SIN", "invSin", "Off"}, + {"+", "X^2", " Sqrt", " COS", "invCos", " "}, + {"-", "X^N", " 1/x ", " TAN", "invTan", " "}, + {"*", " M+", "Prime", " Log", "invLog", " "}, + {"/", " MC", "Year%", " Ln ", " invLn", " "}, + {"!", "MRC", " +/- ", "Mode", "Mode X", " "}}; + + String dis = String.format("|%27s| ", update); + + System.out.print("\033[H\033[2J"); + System.out.flush(); + System.out.println("-----------------------------"); + System.out.println(dis); + System.out.println("-----------------------------"); + for(int i = 0; i < calc.length; i++){ + for (int j = 0; j < calc.length; j++){ + System.out.print("|" + calc[i][j]); + } + System.out.print("|"); + System.out.println(); + System.out.println(" - --- ----- ---- ------ ---"); + } + } +} diff --git a/src/main/java/com/zipcodewilmington/scientificcalculator/MainApplication.java b/src/main/java/com/zipcodewilmington/scientificcalculator/MainApplication.java index 5f421325..bd8a4910 100644 --- a/src/main/java/com/zipcodewilmington/scientificcalculator/MainApplication.java +++ b/src/main/java/com/zipcodewilmington/scientificcalculator/MainApplication.java @@ -1,17 +1,302 @@ package com.zipcodewilmington.scientificcalculator; +import static java.lang.Integer.*; /** * Created by leon on 2/9/18. */ public class MainApplication { + + public static double total = 0; + public static double currentTotal = 0; 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."); + + double input; + int operand; + Display display = new Display(); + Operations opp = new Operations(); + ScientificCalc sci = new ScientificCalc(); + boolean on = true; + + Console.println("Welcome to MAV!"); + while (on){ - 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); + if(display.checkState){ + display.update(0); + input = Console.getDoubleInput("Please enter a number:"); + total = input; + currentTotal = input; + display.checkState = false; + }else { + operand = Console.getOperand("Enter an operator:"); + switch (operand){ + case 100: + on = false; + break; + case 0: + display.clearDisplay(); + break; + case 1: + if(!Display.error) { + currentTotal = opp.add(total, Console.getDoubleInput("Please enter a number:")); + display.update(currentTotal); + total = currentTotal; + }else{ + display.displayErr(); + } + break; + case 2: + if(!Display.error) { + currentTotal = opp.subtract(total, Console.getDoubleInput("Please enter a number:")); + display.update(currentTotal); + total = currentTotal; + }else{ + display.displayErr(); + } + break; + case 3: + if(!Display.error) { + currentTotal = opp.multiply(total, Console.getDoubleInput("Please enter a number:")); + display.update(currentTotal); + total = currentTotal; + }else{ + display.displayErr(); + } + break; + case 4: + if(!Display.error) { + double secondInput = Console.getDoubleInput("Please enter a number:"); + if(secondInput == 0){ + display.displayErr(); + break; + }else { + currentTotal = opp.divide(total, secondInput); + display.update(currentTotal); + total = currentTotal; + } + }else{ + display.displayErr(); + } + break; + case 5: + if(!Display.error) { + currentTotal = opp.square(total); + display.update(currentTotal); + total = currentTotal; + }else{ + display.displayErr(); + } + break; + case 6: + if(!Display.error) { + currentTotal = opp.squareRoot(total); + display.update(currentTotal); + total = currentTotal; + }else{ + display.displayErr(); + } + break; + case 7: + if(!Display.error) { + currentTotal = opp.exponent(total, Console.getDoubleInput("Please enter a number:")); + display.update(currentTotal); + total = currentTotal; + }else{ + display.displayErr(); + } + break; + case 8: + if(!Display.error) { + currentTotal = opp.inverse(total); + display.update(currentTotal); + total = currentTotal; + }else{ + display.displayErr(); + } + break; + case 9: + if(!Display.error) { + currentTotal = opp.switchSign(total); + display.update(currentTotal); + total = currentTotal; + }else{ + display.displayErr(); + } + break; + case 10: + if(!Display.error) { + currentTotal = sci.sine(total); + display.update(currentTotal); + total = currentTotal; + }else{ + display.displayErr(); + } + break; + case 11: + if(!Display.error) { + currentTotal = sci.cose(total); + display.update(currentTotal); + total = currentTotal; + }else{ + display.displayErr(); + } + break; + case 12: + if(!Display.error) { + currentTotal = sci.tangent(total); + display.update(currentTotal); + total = currentTotal; + }else{ + display.displayErr(); + } + break; + case 13: + if(!Display.error) { + currentTotal = sci.inverseSin(total); + display.update(currentTotal); + total = currentTotal; + }else{ + display.displayErr(); + } + break; + case 14: + if(!Display.error) { + currentTotal = sci.inverseCos(total); + display.update(currentTotal); + total = currentTotal; + }else{ + display.displayErr(); + } + break; + case 15: + if(!Display.error) { + currentTotal = sci.inverseTan(total); + display.update(currentTotal); + total = currentTotal; + }else{ + display.displayErr(); + } + break; + case 16: + if(!Display.error) { + currentTotal = sci.logarithm(total); + display.update(currentTotal); + total = currentTotal; + }else{ + display.displayErr(); + } + break; + case 17: + if(!Display.error) { + currentTotal = sci.inverseLog(total); + display.update( currentTotal); + total = currentTotal; + }else{ + display.displayErr(); + } + break; + case 18: + if(!Display.error) { + currentTotal = sci.naturalLog(total); + display.update(currentTotal); + total = currentTotal; + }else{ + display.displayErr(); + } + break; + case 19: + if(!Display.error) { + currentTotal = sci.inverseNaturalLog(total); + display.update(currentTotal); + total = currentTotal; + }else{ + display.displayErr(); + } + break; + case 20: + if(!Display.error) { + currentTotal = sci.factorial(total); + display.update(currentTotal); + total = currentTotal; + }else{ + display.displayErr(); + } + break; + case 21: + if(!Display.error) { + ScientificCalc.memoryAddDouble(); + }else{ + display.displayErr(); + } + break; + case 22: + if(!Display.error) { + ScientificCalc.memoryReset(); + }else{ + display.displayErr(); + } + break; + case 23: + if(!Display.error) { + display.update(ScientificCalc.getMemoryDouble()); + }else{ + display.displayErr(); + } + break; + case 24: + if(!Display.error) { + display.changeNumberDisplay(); + }else{ + display.displayErr(); + } + break; + case 25: + if(!Display.error) { + String mode = Console.getStringInput("Enter mode: (Deci, Hexa, Binary, Octal"); + display.changeNumberDisplay(mode); + }else{ + display.displayErr(); + } + break; + case 26: + if(!Display.error) { + display.changeUnitDisplay(); + }else{ + display.displayErr(); + } + break; + case 27: + if(!Display.error) { + String unit = Console.getStringInput("Enter mod: rad, deg"); + display.changeUnitDisplay(unit); + }else{ + display.displayErr(); + } + break; + case 28: + if(!Display.error) { + if(sci.isPrime(total)){ + display.update("It's a prime!"); + }else { + display.update("It's not a prime!"); + } + }else{ + display.displayErr(); + } + break; + case 29: + if(!Display.error) { + double principal = Console.getDoubleInput("Enter principal:"); + double interest = Console.getDoubleInput("Enter interest:"); + double yearInterest = sci.yearlyInterest(principal, interest); + display.update(yearInterest); + }else{ + display.displayErr(); + } + break; + } + + } + } } } + diff --git a/src/main/java/com/zipcodewilmington/scientificcalculator/Operations.java b/src/main/java/com/zipcodewilmington/scientificcalculator/Operations.java new file mode 100644 index 00000000..59810d40 --- /dev/null +++ b/src/main/java/com/zipcodewilmington/scientificcalculator/Operations.java @@ -0,0 +1,58 @@ +package com.zipcodewilmington.scientificcalculator; + +import static java.lang.Math.*; + +public class Operations { + + // CORE FEATURES + //==================================================== + + // Addition + public double add (double num1, double num2){ + return num1 + num2; + } + + //Subtraction + public double subtract(double num1, double num2) { + return num1 - num2; + } + + // Multiplication + public double multiply (double num1, double num2) { + return num1 * num2; + } + + // Division + public double divide (double num1, double num2) { + return num1 / num2; + } + + // Number Squared + public double square (double num1) { + return num1 * num1; + } + + // Square Root of Number + public double squareRoot (double num1) { return sqrt(num1); } + + + // Exponent + public double exponent (double num1, double num2) { + return pow (num1, num2); + } + + // Inverse + public double inverse (double num1) { + return (1 / num1); + } + + // Switch from Positive to Negative + public double switchSign (double num1) { + return (-1 * num1); + } + + // Display Error if Divide by 0 + + // Clear Error Before New Operation + +} diff --git a/src/main/java/com/zipcodewilmington/scientificcalculator/ScientificCalc.java b/src/main/java/com/zipcodewilmington/scientificcalculator/ScientificCalc.java new file mode 100644 index 00000000..bcca9233 --- /dev/null +++ b/src/main/java/com/zipcodewilmington/scientificcalculator/ScientificCalc.java @@ -0,0 +1,130 @@ +package com.zipcodewilmington.scientificcalculator; + +import static java.lang.Math.*; + +public class ScientificCalc { + + public static double memDouble; + // Trig Functions + // Sine + public double sine (double num1) { + return sin( num1 ); + } + + // Cosine + public double cose (double num1) { + return cos( num1 ); + } + + // Tangent + public double tangent (double num1) { + return tan( num1 ); + } + + // Inverse Sine + public double inverseSin (double num1) { + return asin( num1 ); + } + + // Inverse Cosine + public double inverseCos(double num1) { + return acos( num1 ); + } + + // Inverse Tangent + public double inverseTan (double num1) { + return atan( num1 ); + } + + // Logarithmic Functions + + // Log + public double logarithm (double num1) { + return log10(num1); + } + + // Inverse Logarithm + public double inverseLog (double num1) { + return pow(10,num1); + } + + // Natural Log + public double naturalLog (double num1) { + return log(num1); + } + + // Inverse Natural Log + public double inverseNaturalLog (double num1) { + return exp(num1); + } + + // Factorial + public double factorial (double num1) { + + int intNum1 = (int) Math.round(num1); + double sum = 1.0; + for (int i = 2; i <= intNum1 ; i++) { + sum *= i; + } + return sum; + } + + // Monthly Interest Calc + public double yearlyInterest (double principal, double interestRate) { + double amount = principal * (1 + (interestRate/100)) - principal; + return amount; + } + + // First input is take in a principal amount and then the rate is a percentage + // IsPrime + public boolean isPrime(double num) { + if (num <= 1) { + return false; + } + for (double i = 2; i <= sqrt(num); i++) { + if (num % i == 0) { + return false; + } + } + return true; + } + + // Degrees to Radians + + public static double radian(double num1){ + return toRadians(num1); + } + + // Radians to Degrees + public static double degree(double num1){ + return toDegrees(num1); + } + + // Ghetto Switch Display Mode + public static String Hexadecimal(Integer input) { + return Integer.toHexString(input); + } + public static String Octal(Integer input) { + return Integer.toOctalString(input); + } + public static String Binary(Integer input) { + return Integer.toBinaryString(input); + } + + public static void memoryAddDouble(){ + + memDouble = MainApplication.currentTotal; + + } + + public static void memoryReset(){ + + memDouble = 0; + + } + + public static double getMemoryDouble(){ + + return memDouble; + } +} diff --git a/src/test/.DS_Store b/src/test/.DS_Store new file mode 100644 index 00000000..5e719426 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..7f97956e 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..0c39755f Binary files /dev/null and b/src/test/java/com/.DS_Store differ diff --git a/src/test/java/com/zipcodewilmington/scientific_calculator/ConsoleTest.java b/src/test/java/com/zipcodewilmington/scientific_calculator/ConsoleTest.java new file mode 100644 index 00000000..26956e70 --- /dev/null +++ b/src/test/java/com/zipcodewilmington/scientific_calculator/ConsoleTest.java @@ -0,0 +1,32 @@ +package com.zipcodewilmington.scientific_calculator; + +import org.junit.Test; + +import static org.junit.Assert.*; + +public class ConsoleTest { + + @Test + public void print() { + } + + @Test + public void println() { + } + + @Test + public void getStringInput() { + } + + @Test + public void getIntegerInput() { + } + + @Test + public void getDoubleInput() { + } + + @Test + public void getOperand() { + } +} \ No newline at end of file diff --git a/src/test/java/com/zipcodewilmington/scientific_calculator/DisplayTest.java b/src/test/java/com/zipcodewilmington/scientific_calculator/DisplayTest.java new file mode 100644 index 00000000..1c75791b --- /dev/null +++ b/src/test/java/com/zipcodewilmington/scientific_calculator/DisplayTest.java @@ -0,0 +1,44 @@ +package com.zipcodewilmington.scientific_calculator; + +import org.junit.Test; + +import static org.junit.Assert.*; + +public class DisplayTest { + + @Test + public void displayValue() { + } + + @Test + public void displayCurrentValue() { + } + + @Test + public void clearDisplay() { + } + + @Test + public void changeNumberDisplay() { + } + + @Test + public void testChangeNumberDisplay() { + } + + @Test + public void changeUnitDisplay() { + } + + @Test + public void testChangeUnitDisplay() { + } + + @Test + public void displayErr() { + } + + @Test + public void update() { + } +} \ No newline at end of file diff --git a/src/test/java/com/zipcodewilmington/scientific_calculator/OperationsTest.java b/src/test/java/com/zipcodewilmington/scientific_calculator/OperationsTest.java new file mode 100644 index 00000000..afdab984 --- /dev/null +++ b/src/test/java/com/zipcodewilmington/scientific_calculator/OperationsTest.java @@ -0,0 +1,179 @@ +package com.zipcodewilmington.scientific_calculator; + +import com.zipcodewilmington.scientificcalculator.Operations; +import org.junit.Test; + +import static org.junit.Assert.assertEquals; + +public class OperationsTest { + + Operations operations = new Operations(); + + // Addition Tests + @Test + public void addPosNums() { + double expected = 50; + double actual = operations.add(23, 27); + assertEquals(expected, actual, 0.01); + } + @Test + public void addPosNums1() { + double expected = 80; + double actual = operations.add(75, 5); + assertEquals(expected,actual, 0.01); + } + + @Test + public void addNegNums(){ + double expected = -70; + double actual = operations.add(-50, -20); + assertEquals(expected, actual, 0.01); + } + + @Test + public void addNegNums1() { + double expected = -3; + double actual = operations.add(-10, 7); + assertEquals(expected, actual, 0.01); + + } + + // Subtraction Tests + @Test + public void subtractPosNums() { + double expected = 23; + double actual = operations.subtract(50, 27); + assertEquals(expected, actual, 0.01); + } + + @Test + public void subtractNegNums() { + double expected = -30; + double actual = operations.subtract(-50, -20); + assertEquals(expected, actual, 0.01); + } + + // Multiplication Tests + @Test + public void multiplyPosNums() { + double expected = 27; + double actual = operations.multiply(9, 3); + assertEquals(expected, actual, 0.01); + } + + @Test + public void multiplyNegNums() { + double expected = 27; + double actual = operations.multiply(-9, -3); + assertEquals(expected, actual, 0.01); + } + + // Division Tests + @Test + public void dividePosNums() { + double expected = 3; + double actual = operations.divide(9, 3); + assertEquals(expected, actual, 0.01); + } + + @Test + public void divideNegNums() { + double expected = -3; + double actual = operations.divide(9, -3); + assertEquals(expected, actual, 0.01); + } + + // Number Squared Test + @Test + public void squarePosNums() { + double expected = 9; + double actual = operations.square(3); + assertEquals(expected, actual, 0.01); + } + + @Test + public void squarePosNums1() { + double expected = 64; + double actual = operations.square(8); + assertEquals(expected, actual, 0.01); + } + + @Test + public void squareNegNums() { + double expected = 9; + double actual = operations.square(-3); + assertEquals(expected, actual, 0.01); + } + + @Test + public void squareNegNums1() { + double expected = 16; + double actual = operations.square(-4); + assertEquals(expected, actual, 0.01); + } + + // Square Root of Numbers + @Test + public void squareRootPosNums() { + double expected = 9; + double actual = operations.squareRoot(81); + assertEquals(expected, actual, 0.01); + } + + @Test + public void squareRootPosNums1() { + double expected = 10; + double actual = operations.squareRoot(100); + assertEquals(expected, actual, 0.01); + } + + // Square Root Negative Numbers Test Case ??? + + // Exponent Tests + @Test + public void exponentNums() { + double expected = 8; + double actual = operations.exponent(2, 3); + assertEquals(expected, actual, 0.01); + } + + @Test + public void exponentNums1() { + double expected = 9; + double actual = operations.exponent(3, 2); + assertEquals(expected, actual, 0.01); + } + + // Need To Parse All User Inputs as Doubles + @Test + public void exponentNegNums() { + double expected = 1/8.0; + double actual = operations.exponent(2, -3); + assertEquals(expected, actual, 0.01); + } + + // Inverse + @Test + public void inverseNums() { + double expected = 1/8.0; + double actual = operations.inverse(8); + assertEquals(expected, actual, 0.01); + } + + // Switch Signs + @Test + public void switchSigns() { + double expected = 8; + double actual = operations.switchSign(-8); + assertEquals(expected, actual, 0.01); + } + + @Test + public void switchSignsPosToNeg() { + double expected = -8; + double actual = operations.switchSign(8); + assertEquals(expected, actual, 0.01); + } + + +} diff --git a/src/test/java/com/zipcodewilmington/scientific_calculator/ScientificTests.java b/src/test/java/com/zipcodewilmington/scientific_calculator/ScientificTests.java new file mode 100644 index 00000000..a74a6885 --- /dev/null +++ b/src/test/java/com/zipcodewilmington/scientific_calculator/ScientificTests.java @@ -0,0 +1,164 @@ +package com.zipcodewilmington.scientific_calculator; + +import com.zipcodewilmington.scientificcalculator.ScientificCalc; +import org.junit.Test; + +import static org.junit.Assert.assertEquals; + +public class ScientificTests { + + ScientificCalc scientific = new ScientificCalc(); + + // Sine Tests in Radians and Degrees + @Test + public void sinRadians() { + double expected = 0; + double actual = scientific.sine(0); + assertEquals(expected, actual, 0.01); + } + + /* + @Test + public void sinDegrees() { + double expected = 0; + double actual = scientific.sin(0); + assertEquals(expected, actual, 0.01); + } + */ + + // Cosine Tests in Radians and Degrees + @Test + public void cosRadians() { + double expected = 1; + double actual = scientific.cose(0); + assertEquals(expected, actual, 0.01); + } + + /* + @Test + public void cosDegrees() { + double expected = 0; + double actual = scientific.cos(0); + assertEquals(expected, actual, 0.01); + } + */ + + // Tangent Tests in Radians and Degrees + @Test + public void tanRadians() { + double expected = 0; + double actual = scientific.tangent(0); + assertEquals(expected, actual, 0.01); + } + + /* + @Test + public void tanDegrees() { + double expected = 0; + double actual = scientific.tan(0); + assertEquals(expected, actual, 0.01); + } + */ + + // Inverse Sine Tests in Radians and Degrees + @Test + public void inverseSinRadians() { + double expected = 0; + double actual = scientific.inverseSin(0); + assertEquals(expected, actual, 0.01); + } + + /* + @Test + public void inverseSinDegrees() { + double expected = 0; + double actual = scientific.inverseSin(0); + assertEquals(expected, actual, 0.01); + } + */ + + // Inverse Cosine Tests in Radians and Degrees + @Test + public void inverseCosRadians() { + double expected = 0; + double actual = scientific.inverseCos(1); + assertEquals(expected, actual, 0.01); + } + + /* + @Test + public void inverseCosDegrees() { + double expected = 0; + double actual = scientific.inverseCos(0); + assertEquals(expected, actual, 0.01); + } + */ + + // Inverse Tangent Tests in Radians and Degrees + @Test + public void inverseTanRadians() { + double expected = 0; + double actual = scientific.inverseTan(0); + assertEquals(expected, actual, 0.01); + } + + /* + @Test + public void inverseTanDegrees() { + double expected = 0; + double actual = scientific.inverseTan(0); + assertEquals(expected, actual, 0.01); + } + */ + + // Logarithmic Functions + + // Log + @Test + public void log () { + double expected = 0; + double actual = scientific.logarithm(1); + assertEquals(expected, actual, 0.01); + } + + // Inverse Log + @Test + public void inverseLog () { + double expected = 100; + double actual = scientific.inverseLog(2); + assertEquals(expected, actual, 0.01); + } + + // Natural Log + @Test + public void naturalLog () { + double expected = 0; + double actual = scientific.naturalLog(1); + assertEquals(expected, actual, 0.01); + } + + // Inverse Natural Log + @Test + public void inverseNaturalLog() { + double expected = 1; + double actual = scientific.inverseNaturalLog(0); + assertEquals(expected, actual, 0.01); + } + + // Factorial + @Test + public void factorial () { + double expected = 120; + double actual = scientific.factorial(5); + assertEquals(expected, actual, 0.01); + } + + // Simple Yearly Interest Calc + @Test + public void yearlyInterest () { + double expected = 50; + double actual = scientific.yearlyInterest(1000, 5); + assertEquals(expected, actual, 0.01); + } + +} diff --git a/src/test/java/com/zipcodewilmington/scientific_calculator/TestMainApplication.java b/src/test/java/com/zipcodewilmington/scientific_calculator/TestMainApplication.java deleted file mode 100644 index 94e8d987..00000000 --- a/src/test/java/com/zipcodewilmington/scientific_calculator/TestMainApplication.java +++ /dev/null @@ -1,7 +0,0 @@ -package com.zipcodewilmington.scientific_calculator; - -/** - * Created by leon on 2/9/18. - */ -public class TestMainApplication { -}