diff --git a/.DS_Store b/.DS_Store new file mode 100644 index 0000000..88e32b9 Binary files /dev/null and b/.DS_Store differ diff --git a/ScientificCalculatorUML.png b/ScientificCalculatorUML.png new file mode 100644 index 0000000..395a1c1 Binary files /dev/null and b/ScientificCalculatorUML.png differ diff --git a/pom.xml b/pom.xml index b92b052..2d576ce 100644 --- a/pom.xml +++ b/pom.xml @@ -11,44 +11,34 @@ 11 11 + UTF-8 + 5.10.2 + + + + org.junit.jupiter + junit-jupiter + ${junit.jupiter.version} + test + + + org.apache.maven.plugins maven-compiler-plugin - 3.8.0 + 3.11.0 11 + + org.apache.maven.plugins + maven-surefire-plugin + 3.2.5 + - - - org.apache.maven.plugins - maven-compiler-plugin - 3.8.1 - - - junit - junit - 4.12 - test - - - junit - junit - 4.12 - test - - - junit - junit - 4.12 - test - - - - diff --git a/src/main/java/com/zipcodewilmington/scientificcalculator/Console.java b/src/main/java/com/zipcodewilmington/scientificcalculator/Console.java index 83f0e97..b21ab47 100644 --- a/src/main/java/com/zipcodewilmington/scientificcalculator/Console.java +++ b/src/main/java/com/zipcodewilmington/scientificcalculator/Console.java @@ -3,10 +3,12 @@ import java.util.Scanner; /** - * Created by leon on 2/9/18. + * Created by Michael Sie. I'm building a mansion with just a single hammer. */ public class Console { + private static final Scanner scanner = new Scanner(System.in); + public static void print(String output, Object... args) { System.out.printf(output, args); } @@ -16,17 +18,28 @@ public static void println(String output, Object... args) { } public static String getStringInput(String prompt) { - Scanner scanner = new Scanner(System.in); println(prompt); - String userInput = scanner.nextLine(); - return userInput; + return scanner.nextLine(); } public static Integer getIntegerInput(String prompt) { - return null; + while (true) { + try { + return Integer.parseInt(getStringInput(prompt)); + } catch (NumberFormatException e) { + println("Invalid input. Please enter an integer."); + } } +} public static Double getDoubleInput(String prompt) { - return null; + while (true) { + try { + return Double.parseDouble(getStringInput(prompt)); + } catch (NumberFormatException e) { + println("Invalid input. Please enter a double."); + } } } +} + diff --git a/src/main/java/com/zipcodewilmington/scientificcalculator/MainApplication.java b/src/main/java/com/zipcodewilmington/scientificcalculator/MainApplication.java index 5f42132..1289cce 100644 --- a/src/main/java/com/zipcodewilmington/scientificcalculator/MainApplication.java +++ b/src/main/java/com/zipcodewilmington/scientificcalculator/MainApplication.java @@ -1,17 +1,226 @@ package com.zipcodewilmington.scientificcalculator; -/** - * Created by leon on 2/9/18. - */ public class MainApplication { + + private static String trigMode = "Degrees"; + private static String displayMode = "Decimal"; + 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); + ScientificCalculator calc = new ScientificCalculator(); + boolean running = true; + + System.out.println("\n========================================"); + System.out.println("Welcome to Michael and Prachi's Calculator"); + System.out.println("If you find any bugs, you're probably higher than the Empire State."); + System.out.println("========================================"); + + double startingValue = Console.getDoubleInput("\n \n Please enter a starting value:"); + calc.setCurrentValue(startingValue); + + while (running) { + System.out.println("\n \n========================================"); + if (calc.isError()) { + Console.println(" Current Value: Error"); + } else { + Console.println(" Current Value: " + calc.getCurrentValue()); + } + printMenu(); + int choice = Console.getIntegerInput("Select option: "); + + if (choice == 0) { + System.out.println("Adieux!"); + break; + } + + // MEMORY & SETTINGS (NO INPUT) + if (isNoInputOption(choice)) { + handleNoInputChoice(choice, calc); + printDisplay(calc); + } + + // NORMAL OPERATIONS + else { + if (needsSecondNumber(choice)) { + double second = Console.getDoubleInput("Enter another number: "); + handleBinaryChoice(choice, second, calc); + } else { + handleUnaryChoice(choice, calc); + } + printDisplay(calc); + } + + // CONTINUE? + + System.out.print("\nDo you want to continue? (yes/no): "); + String answer = Console.getStringInput("").trim().toLowerCase(); + + if (!answer.equals("yes") && !answer.equals("y")) { + if (answer.equals("no") || answer.equals("n")) { + System.out.println("Goodbye!"); + running = false; + } else { + System.out.println("Invalid input."); + } + } + } + } + + // CHECKS + + private static boolean needsSecondNumber(int choice) { + return choice == 1 || choice == 2 || choice == 3 + || choice == 4 || choice == 7 || choice == 11; + } + + private static boolean isNoInputOption(int choice) { + return choice == 10 || choice == 12 || choice == 13 || choice == 14 || choice == 15 + || choice == 22; + } + + // MEMORY & SETTINGS + + private static void handleNoInputChoice(int choice, ScientificCalculator calc) { + + switch (choice) { + case 10:calc.clear(); break; + case 12: + calc.switchDisplayMode(); + displayMode = nextDisplayMode(displayMode); + System.out.println("Display mode changed to: " + displayMode); + break; + case 13: // M+ + double before = calc.getCurrentValue(); + calc.memoryAdd(); + System.out.println(" Memory Add Successful!"); + System.out.println("Added value: " + before); + System.out.println("New memory value: " + calc.getCurrentValue()); + break; + + case 14: // MC + calc.memoryClear(); + System.out.println(" Memory Cleared Successfully! Memory is now 0."); + break; + + case 15: // MRC + calc.memoryRecall(); + System.out.println("Memory Recalled Successfully!"); + System.out.println("Value loaded from memory: " + calc.getCurrentValue()); + break; + + case 22: + calc.switchUnitsMode(); + trigMode = trigMode.equals("Degrees") ? "Radians" : "Degrees"; + System.out.println("Trig mode changed to: " + trigMode); + break; + + + } + } + + // TWO NUMBER OPERATIONS + + private static void handleBinaryChoice(int choice, double second, ScientificCalculator calc) { + + switch (choice) { + case 1: calc.add(second); break; + case 2: calc.subtract(second); break; + case 3: calc.multiply(second); break; + case 4: calc.divide(second); break; + case 7: calc.power(second); break; + case 11: calc.setCurrentValue(second); break; + } + } + + // ONE NUMBER OPERATIONS + + private static void handleUnaryChoice(int choice, ScientificCalculator calc) { + + switch (choice) { + case 5: calc.square(); break; + case 6: calc.squareRoot(); break; + case 8: calc.inverse(); break; + case 9: + calc.switchSign(); + if (calc.getCurrentValue() == -0.0) { + calc.setCurrentValue(0.0); + } + break; + case 16: calc.sine(); break; + case 17: calc.cosine(); break; + case 18: calc.tangent(); break; + case 19: calc.inverseSine(); break; + case 20: calc.inverseCosine(); break; + case 21: calc.inverseTangent(); break; + case 23: calc.logarithm(); break; + case 24: calc.inverseLogarithm(); break; + case 25: calc.naturalLogarithm(); break; + case 26: calc.inverseNaturalLogarithm(); break; + case 27: calc.factorial(); break; + case 28: calc.cube(); break; + case 29: calc.percent(); break; + default: + System.out.println("Invalid option."); + + } + } + + // DISPLAY + + private static void printDisplay(ScientificCalculator calc) { + + if (calc.isError()) { + System.out.println("Err. Please clear the calculator to continue."); + return; + } + + double val = calc.getCurrentValue(); + + System.out.print("\n>>> Value: [" + displayMode + "]: "); + + switch (displayMode) { + case "Binary": + System.out.println(Long.toBinaryString((long) val)); + break; + + case "Octal": + System.out.println(Long.toOctalString((long) val)); + break; + + case "Hexadecimal": + System.out.println(Long.toHexString((long) val).toUpperCase()); + break; + + default: + System.out.println(val); + } + } + + // MENU + + private static void printMenu() { + System.out.println("========================================"); + System.out.println("Scientific Calculator | Trig: " + trigMode + " | Display: " + displayMode); + System.out.println("========================================"); + + System.out.println("1. Add 2. Subtract 3. Multiply 4. Divide"); + System.out.println("5. Square 6. SquareRoot 7. Power 8. Inverse"); + System.out.println("9. +/- 10. Clear"); + System.out.println("11. Set current value 12. Switch Display Mode"); + System.out.println("13. M+ 14. MC 15. MRC"); + System.out.println("16. Sin 17. Cos 18. Tan"); + System.out.println("19. asin 20. acos 21. atan"); + System.out.println("22. Toggle Deg/Rad"); + System.out.println("23. log(x) 24. 10^x 25. ln(x) 26. e^x"); + System.out.println("27. Factorial 28. x^3 29. % 0. Exit"); + } + + private static String nextDisplayMode(String current) { + switch (current) { + case "Decimal": return "Hexadecimal"; + case "Hexadecimal": return "Binary"; + case "Binary": return "Octal"; + default: return "Decimal"; + } } -} +} \ No newline at end of file diff --git a/src/main/java/com/zipcodewilmington/scientificcalculator/ScientificCalculator.Java b/src/main/java/com/zipcodewilmington/scientificcalculator/ScientificCalculator.Java new file mode 100644 index 0000000..43cc218 --- /dev/null +++ b/src/main/java/com/zipcodewilmington/scientificcalculator/ScientificCalculator.Java @@ -0,0 +1,286 @@ +package com.zipcodewilmington.scientificcalculator; + +/** + * Created by Michael Sie on 4/11/26. + * I barely understands how to use a calculator, let alone a scientific one. + * But I have a dream of working in a big tech company. + * I have no idea how to create a scientific calculator, but I wannt to learn. + * This is going to be a long journey for me. + */ + + +public class ScientificCalculator { + private double currentValue = 0; + private double currentMemory = 0; + private String currentTrigMode = "Degrees"; + private String currentDisplayMode = "Decimal"; + private boolean isError = false; + + public double getCurrentValue() { + return currentValue; + } + + public void setCurrentValue(double currentValue) { + if (isError) { + return ; + } + this.currentValue = currentValue; + } + + public void clear() { + currentValue = 0; + isError = false; + } + + public void add(double value) { + if (isError) { + return ; + } + currentValue += value; + } + + public void subtract(double value) { + if (isError) { + return ; + } + currentValue -= value; + } + + public void multiply(double value) { + if (isError) { + return ; + } + currentValue *= value; + } + + public void divide(double value) { + if (isError) { + return ; + } + if (value == 0) { + isError = true; + } else { + currentValue /= value; + } + } + + public void square() { + if (isError) { + return ; + } + currentValue *= currentValue; + } + + public void squareRoot() { + if (isError) { + return ; + } + if (currentValue < 0) { + isError = true; + } else { + currentValue = Math.sqrt(currentValue); + } + } + + public void inverse() { + if (isError) { + return ; + } + if (currentValue == 0) { + isError = true; + } else { + currentValue = 1 / currentValue; + } + } + + public void switchSign() { + if (isError) { + return ; + } + currentValue = -currentValue; + } + + public void power(double exponent) { + if (isError) { + return ; + } + currentValue = Math.pow(currentValue, exponent); + } + + public void memoryAdd() { + if (isError) { + return ; + } + currentMemory += currentValue; + currentValue = currentMemory; + } + + public void memoryClear() { + currentMemory = 0; + } + + public void memoryRecall() { + if (isError) { + return ; + } + currentValue = currentMemory; + } + + public void switchUnitsMode(String mode) { + if (mode.equals("Degrees") || mode.equals("Radians")) { + currentTrigMode = mode; + } + } + + public void switchUnitsMode() { + if (currentTrigMode.equals("Degrees")) { + currentTrigMode = "Radians"; + } else { + currentTrigMode = "Degrees"; + } + } + + public void switchDisplayMode(String mode) { + if (mode.equals("Decimal") || mode.equals("Octal") || mode.equals("Binary") || mode.equals("Hexadecimal")) { + currentDisplayMode = mode; + } + } + + public void switchDisplayMode() { + if (currentDisplayMode.equals("Decimal")) { + currentDisplayMode = "Hexadecimal"; + } else if (currentDisplayMode.equals("Hexadecimal")) { + currentDisplayMode = "Binary"; + } else if (currentDisplayMode.equals("Binary")) { + currentDisplayMode = "Octal"; + } else { + currentDisplayMode = "Decimal"; + } + } + + public void sine() { + if (isError) { + return ; + } + double radians = currentTrigMode.equals("Degrees") ? Math.toRadians(currentValue) : currentValue; + currentValue = Math.sin(radians); + } + + public void cosine() { + if (isError) { + return ; + } + double radians = currentTrigMode.equals("Degrees") ? Math.toRadians(currentValue) : currentValue; + currentValue = Math.cos(radians); + } + + public void tangent() { + if (isError) { + return ; + } + double radians = currentTrigMode.equals("Degrees") ? Math.toRadians(currentValue) : currentValue; + currentValue = Math.tan(radians); + } + + public void inverseSine() { + if (isError) { + return ; + } if (currentValue < -1 || currentValue > 1) { + isError = true; + return ; + } else { + double radians = Math.asin(currentValue); + currentValue = currentTrigMode.equals("Degrees") ? Math.toDegrees(radians) : radians; + } + } + + public void inverseCosine() { + if (isError) { + return ; + } + if (currentValue < -1 || currentValue > 1) { + isError = true; + return ; + } else { + double radians = Math.acos(currentValue); + currentValue = currentTrigMode.equals("Degrees") ? Math.toDegrees(radians) : radians; + } + } + + public void inverseTangent() { + if (isError) { + return ; + } + double radians = Math.atan(currentValue); + currentValue = currentTrigMode.equals("Degrees") ? Math.toDegrees(radians) : radians; + } + + public void logarithm() { + if (isError) { + return ; + } + if (currentValue <= 0) { + isError = true; + } else { + currentValue = Math.log10(currentValue); + } + } + + public void inverseLogarithm() { + if (isError) { + return ; + } + currentValue = Math.pow(10, currentValue); + } + + public void naturalLogarithm() { + if (isError) { + return ; + } + if (currentValue <= 0) { + isError = true; + } else { + currentValue = Math.log(currentValue); + } + } + + public void inverseNaturalLogarithm() { + if (isError) { + return ; + } + currentValue = Math.exp(currentValue); + } + + public void factorial() { + if (isError) { + return ; + } + if (currentValue < 0 || currentValue != Math.floor(currentValue)) { + isError = true; + } else { + double result = 1; + for (int i = 1; i <= (int)currentValue; i++) { + result *= i; + } + currentValue = result; + } + } + + public void cube() { + if (isError) { + return ; + } + currentValue *= currentValue * currentValue; + } + + public void percent() { + if (isError) { + return ; + } + currentValue /= 100; + } + + public boolean isError() { + return isError; + } +} diff --git a/src/test/java/com/zipcodewilmington/scientific_calculator/ScientificCalculatorTest.java b/src/test/java/com/zipcodewilmington/scientific_calculator/ScientificCalculatorTest.java new file mode 100644 index 0000000..9ba4c38 --- /dev/null +++ b/src/test/java/com/zipcodewilmington/scientific_calculator/ScientificCalculatorTest.java @@ -0,0 +1,318 @@ +package com.zipcodewilmington.scientific_calculator; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertTrue; +import org.junit.jupiter.api.Test; + +import com.zipcodewilmington.scientificcalculator.ScientificCalculator; + +public class ScientificCalculatorTest { + + @Test // 1 + public void testAddition() { + ScientificCalculator calculator = new ScientificCalculator(); + calculator.setCurrentValue(7349); + calculator.add(2364); + assertEquals(9713, calculator.getCurrentValue(), 0.001); + } + + @Test // 2 + public void testSubtraction() { + ScientificCalculator calculator = new ScientificCalculator(); + calculator.setCurrentValue(23674); + calculator.subtract(24837); + assertEquals(-1163, calculator.getCurrentValue(), 0.001); + } + + @Test // 3 + public void testMultiplication() { + ScientificCalculator calculator = new ScientificCalculator(); + calculator.setCurrentValue(7349); + calculator.multiply(2364); + assertEquals(17373036, calculator.getCurrentValue(), 0.001); + } + + @Test // 4 + public void testDivision() { + ScientificCalculator calculator = new ScientificCalculator(); + calculator.setCurrentValue(84327); + calculator.divide(8347); + assertEquals(10.102072601, calculator.getCurrentValue(), 0.001); + } + + @Test // 4.1 + public void testDivisionByZero() { + ScientificCalculator calculator = new ScientificCalculator(); + calculator.setCurrentValue(7436); + calculator.divide(0); + assertTrue(calculator.isError()); + } + + @Test // 5 + public void testSquare() { + ScientificCalculator calculator = new ScientificCalculator(); + calculator.setCurrentValue(1436); + calculator.square(); + assertEquals(2062096, calculator.getCurrentValue(), 0.001); + } + + @Test // 6 + public void testSquareRoot() { + ScientificCalculator calculator = new ScientificCalculator(); + calculator.setCurrentValue(2062096); + calculator.squareRoot(); + assertEquals(1436, calculator.getCurrentValue(), 0.001); + } + + @Test // 6.1 + public void testSquareRootOfNegative() { + ScientificCalculator calculator = new ScientificCalculator(); + calculator.setCurrentValue(-234); + calculator.squareRoot(); + assertTrue(calculator.isError()); + } + + @Test // 7 + public void testDoubleExponent() { + ScientificCalculator calculator = new ScientificCalculator(); + calculator.setCurrentValue(734); + calculator.power(2); + assertEquals(538756, calculator.getCurrentValue(), 0.001); + } + + @Test // 8 + public void testInverse() { + ScientificCalculator calculator = new ScientificCalculator(); + calculator.setCurrentValue(2342); + calculator.inverse(); + assertEquals(0.000426985, calculator.getCurrentValue(), 0.001); + } + + @Test // 8.1 + public void testInverseOfZero() { + ScientificCalculator calculator = new ScientificCalculator(); + calculator.setCurrentValue(0); + calculator.inverse(); + assertTrue(calculator.isError()); + } + + @Test // 9 + public void testSwitchSign() { + ScientificCalculator calculator = new ScientificCalculator(); + calculator.setCurrentValue(2543); + calculator.switchSign(); + assertEquals(-2543, calculator.getCurrentValue(), 0.001); + } + + @Test // 10 + public void testClear() { + ScientificCalculator calculator = new ScientificCalculator(); + calculator.setCurrentValue(2873); + calculator.clear(); + assertEquals(0, calculator.getCurrentValue(), 0.001); + } + + @Test // 11 + public void testsetCurrentValue() { + ScientificCalculator calculator = new ScientificCalculator(); + calculator.setCurrentValue(7349); + assertEquals(7349, calculator.getCurrentValue(), 0.001); + } + + @Test // 12 ??? + public void testSwitchDisplayMode() { + ScientificCalculator calculator = new ScientificCalculator(); + calculator.setCurrentValue(8172); + calculator.switchDisplayMode(); + assertEquals(8172, calculator.getCurrentValue(), 0.001); + } + + @Test // 13 & 15 + public void testmemoryFunctions() { + ScientificCalculator calculator = new ScientificCalculator(); + calculator.setCurrentValue(7349); + calculator.memoryAdd(); + calculator.memoryRecall(); + assertEquals(7349, calculator.getCurrentValue(), 0.001); + } + + @Test // 13.1 + public void testMemoryFunctions() { + ScientificCalculator calculator = new ScientificCalculator(); + calculator.setCurrentValue(7349); + calculator.memoryAdd(); + calculator.memoryClear(); + calculator.memoryRecall(); + assertEquals(0, calculator.getCurrentValue(), 0.001); + } + + @Test // 14 + public void testMemoryClear() { + ScientificCalculator calculator = new ScientificCalculator(); + calculator.setCurrentValue(3453); + calculator.memoryAdd(); + calculator.memoryClear(); + calculator.memoryRecall(); + assertEquals(0, calculator.getCurrentValue(), 0.001); + } + + @Test // 16 + public void testSine() { + ScientificCalculator calculator = new ScientificCalculator(); + calculator.setCurrentValue(30); + calculator.sine(); + assertEquals(0.5, calculator.getCurrentValue(), 0.001); + } + + @Test // 17 + public void testCosine() { + ScientificCalculator calculator = new ScientificCalculator(); + calculator.setCurrentValue(60); + calculator.cosine(); + assertEquals(0.5, calculator.getCurrentValue(), 0.001); + } + + @Test // 18 + public void testTangent() { + ScientificCalculator calculator = new ScientificCalculator(); + calculator.setCurrentValue(45); + calculator.tangent(); + assertEquals(1, calculator.getCurrentValue(), 0.001); + } + + @Test // 19 + public void testInverseSine() { + ScientificCalculator calculator = new ScientificCalculator(); + calculator.setCurrentValue(0.5); + calculator.inverseSine(); + assertEquals(30, calculator.getCurrentValue(), 0.001); + } + + @Test // 19.1 + public void testInverseSineOutOfRange() { + ScientificCalculator calculator = new ScientificCalculator(); + calculator.setCurrentValue(53); + calculator.inverseSine(); + assertTrue(calculator.isError()); + } + + @Test // 20 + public void testInverseCosine() { + ScientificCalculator calculator = new ScientificCalculator(); + calculator.setCurrentValue(0.5); + calculator.inverseCosine(); + assertEquals(60, calculator.getCurrentValue(), 0.001); + } + + @Test // 20.1 + public void testInverseCosineOutOfRange() { + ScientificCalculator calculator = new ScientificCalculator(); + calculator.setCurrentValue(-65); + calculator.inverseCosine(); + assertTrue(calculator.isError()); + } + + @Test // 21 + public void testInverseTangent() { + ScientificCalculator calculator = new ScientificCalculator(); + calculator.setCurrentValue(1); + calculator.inverseTangent(); + assertEquals(45, calculator.getCurrentValue(), 0.001); + } + + @Test // 22 + public void testSwitchTrigMode() { + ScientificCalculator calculator = new ScientificCalculator(); + calculator.switchUnitsMode("Radians"); + calculator.setCurrentValue(Math.PI / 6); + calculator.sine(); + assertEquals(0.5, calculator.getCurrentValue(), 0.001); + } + + @Test // 23 + public void testLogarithm() { + ScientificCalculator calculator = new ScientificCalculator(); + calculator.setCurrentValue(10000); + calculator.logarithm(); + assertEquals(4, calculator.getCurrentValue(), 0.001); + } + + @Test // 23.1 + public void testLogarithmOfNegative() { + ScientificCalculator calculator = new ScientificCalculator(); + calculator.setCurrentValue(-10000); + calculator.logarithm(); + assertTrue(calculator.isError()); + } + + @Test // 24 + public void testInverseLogarithm() { + ScientificCalculator calculator = new ScientificCalculator(); + calculator.setCurrentValue(4); + calculator.inverseLogarithm(); + assertEquals(10000, calculator.getCurrentValue(), 0.001); + } + + @Test // 25 + public void testNaturalLogarithm() { + ScientificCalculator calculator = new ScientificCalculator(); + calculator.setCurrentValue(Math.E); + calculator.naturalLogarithm(); + assertEquals(1, calculator.getCurrentValue(), 0.001); + } + + @Test // 25.1 + public void testNaturalLogarithmOfNegative() { + ScientificCalculator calculator = new ScientificCalculator(); + calculator.setCurrentValue(-Math.E); + calculator.naturalLogarithm(); + assertTrue(calculator.isError()); + } + + @Test // 26 + public void testInverseNaturalLogarithm() { + ScientificCalculator calculator = new ScientificCalculator(); + calculator.setCurrentValue(1); + calculator.inverseNaturalLogarithm(); + assertEquals(Math.E, calculator.getCurrentValue(), 0.001); + } + + @Test // 27 + public void testFactorial() { + ScientificCalculator calculator = new ScientificCalculator(); + calculator.setCurrentValue(5); + calculator.factorial(); + assertEquals(120, calculator.getCurrentValue(), 0.001); + } + + @Test // 27.1 + public void testFactorialOfNegative() { + ScientificCalculator calculator = new ScientificCalculator(); + calculator.setCurrentValue(-5); + calculator.factorial(); + assertTrue(calculator.isError()); + } + + @Test // 27.2 + public void testFactorialOfNonInteger() { + ScientificCalculator calculator = new ScientificCalculator(); + calculator.setCurrentValue(5.5); + calculator.factorial(); + assertTrue(calculator.isError()); + } + + @Test // 28 + public void testCube() { + ScientificCalculator calculator = new ScientificCalculator(); + calculator.setCurrentValue(3); + calculator.cube(); + assertEquals(27, calculator.getCurrentValue(), 0.001); + } + + @Test // 29 + public void testPercentage() { + ScientificCalculator calculator = new ScientificCalculator(); + calculator.setCurrentValue(50); + calculator.percent(); + assertEquals(0.5, calculator.getCurrentValue(), 0.001); + } +} \ No newline at end of file diff --git a/src/test/java/com/zipcodewilmington/scientific_calculator/TestMainApplication.java b/src/test/java/com/zipcodewilmington/scientific_calculator/TestMainApplication.java index 94e8d98..9669304 100644 --- a/src/test/java/com/zipcodewilmington/scientific_calculator/TestMainApplication.java +++ b/src/test/java/com/zipcodewilmington/scientific_calculator/TestMainApplication.java @@ -1,4 +1,7 @@ package com.zipcodewilmington.scientific_calculator; +import com.zipcodewilmington.scientificcalculator.ScientificCalculator; +import org.junit.jupiter.api.Test; +import static org.junit.jupiter.api.Assertions.*; /** * Created by leon on 2/9/18.