diff --git a/src/main/java/com/zipcodewilmington/scientificcalculator/Calculator.java b/src/main/java/com/zipcodewilmington/scientificcalculator/Calculator.java new file mode 100644 index 0000000..3e21fc8 --- /dev/null +++ b/src/main/java/com/zipcodewilmington/scientificcalculator/Calculator.java @@ -0,0 +1,100 @@ +package com.zipcodewilmington.scientificcalculator; +import java.lang.Math; +public class Calculator { + + private double display; + + public Calculator() { + this.display = 0; + } + + public double getDisplay() { + return this.display; + } + + public void clearDisplay() { + this.display = 0; + } + + public void setDisplay(double number) { + this.display = number; + } + + public static double addTwoNums(double x, double y) { + double sum = x + y; + Console.print("The sum of " + x + " and " + y + " is " + String.valueOf(sum)); + return sum; + } + + public static double subtractTwoNums(double x, double y) { + double difference = x - y; + Console.print("The difference of " + x + " and " + y + " is " + String.valueOf(difference)); + return difference; + } + + public static double multiplyTwoNums(double x, double y) { + double product = x * y; + Console.print("The product of " + x + " and " + y + " is " + String.valueOf(product)); + return product; + } + + public static double divide(double x, double y) { + double quotient = 0; + if (y != 0) { + quotient = x /y; + } else { + //this.display = Double.NaN; // Set display to NaN for division by zero error + } + Console.print("The quotient of " + x + " / " + y + " is " + String.valueOf(quotient)); + return quotient; + } + + public static double square(double x) { + double squared = (x * x); + Console.print(x + " :Squared is " + String.valueOf(squared)); + return squared; + } + + public static double squareRoot(double x) { + double squareRoot = Math.sqrt(x); + Console.print( "The square root of: " + x + " is " + String.valueOf(squareRoot)); + return squareRoot; + } + + public static double exponentiation(double x, double y) { + double total = Math.pow(x , y); + + Console.print(x + " raised to the power of " + y + " is " + total ); + return total; + } + + public void inverse() { + if (this.display != 0) { + this.display = 1 / this.display; + } else { + //this.display = Double.NaN; // Set display to NaN for division by zero error + + } + } + + public static double invertSign(double x) { + double newNum = 0; + if (x < 0 ){ + //x is less than in this scenario + newNum = (x * -1); + } else { + newNum = -x; + + } + Console.print("This number with it's sign inverted is: " + newNum); + return newNum; + } + + public void clearError() { + if (Double.isNaN(this.display)) { + this.display = 0; + } + } +} + + diff --git a/src/main/java/com/zipcodewilmington/scientificcalculator/Console.java b/src/main/java/com/zipcodewilmington/scientificcalculator/Console.java index 83f0e97..3c13ccc 100644 --- a/src/main/java/com/zipcodewilmington/scientificcalculator/Console.java +++ b/src/main/java/com/zipcodewilmington/scientificcalculator/Console.java @@ -23,10 +23,16 @@ public static String getStringInput(String prompt) { } public static Integer getIntegerInput(String prompt) { - return null; + Scanner scanner = new Scanner(System.in); + print(prompt); + int userInput = scanner.nextInt(); + return userInput; } public static Double getDoubleInput(String prompt) { - return null; + Scanner scanner = new Scanner(System.in); + print(prompt); + double userInput = scanner.nextDouble(); + return userInput; } } diff --git a/src/main/java/com/zipcodewilmington/scientificcalculator/CoreFeatures.java b/src/main/java/com/zipcodewilmington/scientificcalculator/CoreFeatures.java new file mode 100644 index 0000000..25fb561 --- /dev/null +++ b/src/main/java/com/zipcodewilmington/scientificcalculator/CoreFeatures.java @@ -0,0 +1,88 @@ +package com.zipcodewilmington.scientificcalculator; + +import java.util.Scanner; + +public class CoreFeatures { + public static void main(String[] args) { + /* + Console.println("Welcome to Halictidae Calculator!"); + Console.println("I'm here to help!"); + +// String s = Console.getStringInput("Enter a string"); +// Integer i = Console.getIntegerInput("Enter an integer"); +// Double d = Console.getDoubleInput("Enter a double."); +// String methodName = Console.getStringInput("Enter a function"); +// String firstNumber = Console.getStringInput("Enter the first number"); +// +// 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); + + int result = 1; + /* + Console.println("Welcome to Halictidae Calculator!"); + Console.println("I'm here to help!"); + int numberOne = Console.getIntegerInput("Enter the first number: "); + int numberTwo = Console.getIntegerInput("Enter the Second number: "); + String chooseOperation = Console.getStringInput("What operation?\n" + + "( + ) ( - ) ( * ) ( / ) ( ^ ) ( sqr ) ( sqrt )\n");*/ + + //initialized variable result + //Scanner scanObject = new Scanner(System.in); + + + /* + Scanner scan = new Scanner(System.in); + System.out.println("Enter first number:"); + //enter first number + numberOne = (int) scan.nextDouble(); + System.out.println("What operation?"); + System.out.println("( + ) ( - ) ( * ) ( / ) ( ^ ) ( sqr ) ( sqrt )"); + //choose specified operation of choice + String operator = scanObject.next(); + System.out.println("Enter second number"); + //enter second number + numberTwo = scan.nextInt(); */ + + + //System.out.println(result); + //results printed + + /* + switch (chooseOperation) { + case "+": + result = number one + number two; + break; + case "-": + result = numberOne - numberTwo; + break; + case "*": + result = numberOne * numberTwo; + break; + case "/": + result = numberOne / numberTwo; + break; + case "^": + result = (int) Math.pow(numberOne, numberTwo); + break; + case "sqrt": + result = (int) Math.sqrt(numberOne); + break; + + //switch statement - block of code executed when switch value matches operation chosen + } + //System.out.println(numberOne + " " + chooseOperation + " " + numberTwo + " = " + result); + // Example: 10 + 5 = 15 (different operations can be chosen) + } + + */ + } +} + + + + + + + + diff --git a/src/main/java/com/zipcodewilmington/scientificcalculator/MainApplication.java b/src/main/java/com/zipcodewilmington/scientificcalculator/MainApplication.java index 5f42132..e3119d8 100644 --- a/src/main/java/com/zipcodewilmington/scientificcalculator/MainApplication.java +++ b/src/main/java/com/zipcodewilmington/scientificcalculator/MainApplication.java @@ -5,13 +5,106 @@ */ public class MainApplication { 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("Welcome to Halictidae Calculator!"); + Console.println("I'm here to help!"); + String chooseOperation = Console.getStringInput("What operation would you like to perform today?\n" + + "( + ) ( - ) ( * ) ( / ) ( ^ ) ( sqr ) ( sqrt ) (exponentiation) (invert sign)\n" + + "(sine) (cosine) (tangent) (inverseSine) (inverseCosine) (inverseTangent) (log) (inverseLog)" + + " (naturalLog) (inverseNaturalLog) (factorial)\n" + + "(clearError)" + + "\nPlease type it in as you see in the parentheses ---> "); - 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); + double numberOne; + double numberTwo; + + switch (chooseOperation) { + case "+": + numberOne = Console.getDoubleInput("Please enter first number: "); + numberTwo = Console.getDoubleInput("Please enter second number: "); + Calculator.addTwoNums(numberOne, numberTwo); + break; + case "-": + numberOne = Console.getDoubleInput("Please enter first number: "); + numberTwo = Console.getDoubleInput("Please enter second number: "); + Calculator.subtractTwoNums(numberOne, numberTwo); + break; + case "*": + numberOne = Console.getDoubleInput("Please enter first number: "); + numberTwo = Console.getDoubleInput("Please enter second number: "); + Calculator.multiplyTwoNums(numberOne, numberTwo); + break; + case "/": + numberOne = Console.getDoubleInput("Please enter first number: "); + numberTwo = Console.getDoubleInput("Please enter second number: "); + Calculator.divide(numberOne, numberTwo); + break; + case "exponentiation": + numberOne = Console.getDoubleInput("Please enter first number: "); + numberTwo = Console.getDoubleInput("Please enter second number: "); + Calculator.exponentiation(numberOne, numberTwo); + break; + case "sqr": + numberOne = Console.getDoubleInput("Please enter the number you want squared: "); + Calculator.square(numberOne); + break; + case "sqrt": + numberOne = Console.getDoubleInput("Please enter the number you want the square root of: "); + Calculator.squareRoot(numberOne); + break; + case "invert sign": + numberOne = Console.getDoubleInput("Please enter the number which sign you want to inverse: "); + Calculator.invertSign(numberOne); + break; + case "sine": + numberOne = Console.getDoubleInput("Please enter the number you want to Sine of: "); + Science.Sin(numberOne); + break; + case "cosine": + numberOne = Console.getDoubleInput("Please enter the number you want to Cosine of: "); + Science.Cos(numberOne); + break; + case "tangent": + numberOne = Console.getDoubleInput("Please enter the number you want to Tangent of: "); + Science.Tan(numberOne); + break; + case "inverseSine": + numberOne = Console.getDoubleInput("Please enter the number you want to Inverse Sine of: "); + Science.aSin(numberOne); + break; + case "inverseCosine": + numberOne = Console.getDoubleInput("Please enter the number you want to Inverse Cosine of: "); + Science.aCos(numberOne); + break; + case "inverseTangent": + numberOne = Console.getDoubleInput("Please enter the number you want to Inverse Tangent of: "); + Science.aTan(numberOne); + break; + case "log": + numberOne = Console.getDoubleInput("Please enter the number you want the log of: "); + Science.log(numberOne); + break; + case "inverseLog": + numberOne = Console.getDoubleInput("Please enter the number you want the inverse log of: "); + Science.invLog(numberOne); + break; + case "naturalLog": + numberOne = Console.getDoubleInput("Please enter the number you want the natural log of: "); + Science.natLog(numberOne); + break; + case "inverseNaturalLog": + numberOne = Console.getDoubleInput("Please enter the number you want the inverse natural log of: "); + Science.invNatLog(numberOne); + break; + case "factorial": + numberOne = Console.getDoubleInput("Please enter the number you want the factorial of: "); + Science.factorial(numberOne); + break; + default: + Console.print("That command does not exist please enter another command: "); + break; + } } } + + + diff --git a/src/main/java/com/zipcodewilmington/scientificcalculator/Science.java b/src/main/java/com/zipcodewilmington/scientificcalculator/Science.java new file mode 100644 index 0000000..955a981 --- /dev/null +++ b/src/main/java/com/zipcodewilmington/scientificcalculator/Science.java @@ -0,0 +1,107 @@ +package com.zipcodewilmington.scientificcalculator; + +import java.util.Scanner; + +public class Science { + public static void Binary () { + Scanner binaryInput = new Scanner (System.in); + + } + + public static double Sin(double input) { + double sinValue = Math.sin(input); + Console.println("sin(" + input + ") = " + sinValue); + return sinValue; + } + + public static double Cos(double input) { + double cosValue = Math.cos(input); + Console.println("sin(" + input + ") = " + cosValue); + return cosValue; + } + + public static double Tan(double input) { + double tanValue = Math.tan(input); + Console.println("sin(" + input + ") = " + tanValue); + return tanValue; + } + + public static double aSin(double input) { + double asinvalue = Math.asin(input); + Console.println("sin(" + input + ") = " + asinvalue); + return asinvalue; + } + public static double aCos(double input) { + double acosvalue = Math.acos(input); + Console.println("sin(" + input + ") = " + acosvalue); + return acosvalue; + } + + public static double aTan(double input) { + double atanvalue = Math.atan(input); + Console.println("sin(" + input + ") = " + atanvalue); + return atanvalue; + } + + public static double log (double log) { + double logValue = Math.log(log); + Console.println("log(" + log + ") = " + logValue); + return logValue; + } + + public static double invLog (double invLog) { + double invLogValue = Math.log10(invLog); + Console.println("sin(" + invLog + ") = " + invLogValue); + return invLogValue; + } + + public static double natLog (double natLog) { + double natLogValue = Math.log1p(natLog); + Console.println("sin(" + natLog + ") = " + natLogValue); + return natLogValue; + } + + public static double invNatLog (double invNatLog) { + double invNatLogValue = Math.log10(Math.log1p(invNatLog)); + Console.println("sin(" + invNatLog + ") = " + invNatLogValue); + return invNatLogValue; + } + + public static double factorial(double fact) { + double total = 1; + for (int i = 0; 0 < fact; i++){ + + // add N to the total sum of the number + total *= fact;//3 + fact -= 1; + //have total increment with i till its less than n + } + Console.println("The factorial is: " + total); + return total; + } + public static int fact (int fact) { + for (int i = 1;i <= fact; i++) { + fact = fact * i; + } + int factValue = fact; + return factValue; + } + + public static void switchUnitsMode () { + String s = Console.getStringInput("Please enter Degrees or Radians: "); + if (s.equals("Degrees")) { + swithUnitsMode(s); + } + else { + + } + + } + + public static String swithUnitsMode(String mode) { + return null; + } + + + +} diff --git a/src/test/java/com/zipcodewilmington/scientific_calculator/CoreTest.java b/src/test/java/com/zipcodewilmington/scientific_calculator/CoreTest.java new file mode 100644 index 0000000..b6979b9 --- /dev/null +++ b/src/test/java/com/zipcodewilmington/scientific_calculator/CoreTest.java @@ -0,0 +1,459 @@ +package com.zipcodewilmington.scientific_calculator; + +import com.zipcodewilmington.scientificcalculator.Calculator; +import com.zipcodewilmington.scientificcalculator.MainApplication; +import org.apache.commons.io.output.ByteArrayOutputStream; +import org.junit.After; +import org.junit.Assert; +import org.junit.Before; +import org.junit.Test; + +import java.io.PrintStream; + + +public class CoreTest { + private final ByteArrayOutputStream outContent = new ByteArrayOutputStream(); + private final PrintStream originalOut = System.out; + + @Before + public void setUpStreams() { + // changes "System.out.print" commands to print to this stream, rather than the console + System.setOut(new PrintStream(outContent)); + } + + @After + public void restoreStreams() { + // we do this to avoid having any null pointer exceptions + System.setOut(originalOut); + } + + + @Test + public void addTest1() { + //Given, this is the expected behavior + //change variables to names of group's methods + double x = 2; + double y = 4; + double expectedSum = x + y; + + //When + //calling groups class and method to store the value of the actual method + // + double actual = Calculator.addTwoNums(x,y); + + //Then + Assert.assertEquals(expectedSum, actual, 0.001); + } + + @Test + public void addTest2() { + //Given, this is the expected behavior + //change variables to names of group's methods + double x = 60; + double y = 40; + double expectedSum = x + y; + + //When + //calling group's class and method to store the value of the actual method + // + double actual = Calculator.addTwoNums(x, y); + + //Then + Assert.assertEquals(expectedSum, actual, 0.001); + } + + @Test + public void addTest3() { + //Given, this is the expected behavior + //change variables to names of group's methods + double x = 50; + double y = -40; + double expectedSum = x + y; + + //When + //calling group's class and method to store the value of the actual method + // + double actual = Calculator.addTwoNums(x, y); + + //Then + Assert.assertEquals(expectedSum, actual, 0.001); + } + + + + @Test + public void subtractTest1() { + + //Given, this is the expected behavior + //change variables to names of group's methods + double x = 6; + double y = 4; + + double expectedDifference = x - y; + + //When + //calling groups class and method to store the value of the actual method + // + double actual = Calculator.subtractTwoNums(x,y); + + //Then + Assert.assertEquals(expectedDifference, actual, .001); + } + @Test + public void subtractTest2() { + //Given, this is the expected behavior + //change variables to names of group's methods + double x = -50; + double y = -90; + double expectedDifference = x - y; + + //When + //calling group's class and method to store the value of the actual method + // + double actual = Calculator.subtractTwoNums(x, y); + + //Then + Assert.assertEquals(expectedDifference, actual, 0.001); + } + @Test + public void subtractTest3() { + //Given, this is the expected behavior + //change variables to names of group's methods + double x = -502; + double y = 600; + double expected = x - y; + + //When + //calling group's class and method to store the value of the actual method + // + double actual = Calculator.subtractTwoNums(x, y); + + //Then + Assert.assertEquals(expected, actual, 0.001); + } + + + + @Test + public void multiplyTest1() { + + //Given, this is the expected behavior + //change variables to names of group's methods + double x = 2; + double y = 4; + + double expected = x * y; + + //When + //calling groups class and method to store the value of the actual method + // + double actual = Calculator.multiplyTwoNums(x,y); + + //Then + Assert.assertEquals(expected, actual, .001); + } + @Test + public void multiplyTest2() { + //Given, this is the expected behavior + //change variables to names of group's methods + double x = 50; + double y = -40; + double expected = x * y; + + //When + //calling group's class and method to store the value of the actual method + // + double actual = Calculator.multiplyTwoNums(x, y); + + //Then + Assert.assertEquals(expected, actual, 0.001); + } + @Test + public void multiplyTest3() { + //Given, this is the expected behavior + //change variables to names of group's methods + double x = -5; + double y = -10; + double expected = x * y; + + //When + //calling group's class and method to store the value of the actual method + // + double actual = Calculator.multiplyTwoNums(x, y); + + //Then + Assert.assertEquals(expected, actual, 0.001); + } + + + + @Test + public void divideTest1() { + + //Given, this is the expected behavior + //change variables to names of group's methods + double x = 40; + double y = 10; + double expected; + + if (x != 0 && y != 0) { + expected = x /y; + } else { + expected = 0; + } + + //When + //calling groups class and method to store the value of the actual method + // + double actual = Calculator.divide(x,y); + + //Then + Assert.assertEquals(expected, actual, .001); + } + @Test + public void divideTest2() { + + //Given, this is the expected behavior + //change variables to names of group's methods + double x = 0; + double y = 50; + double expected; + + if (x != 0 && y != 0) { + expected = x /y; + } else { + expected = 0; + } + //When + //calling groups class and method to store the value of the actual method + // + double actual = Calculator.divide(x,y); + + //Then + Assert.assertEquals(expected, actual, .001); + } + @Test + public void divideTest3() { + //Given, this is the expected behavior + //change variables to names of group's methods + double x = 40; + double y = 0; + double expected; + + if (x != 0 && y != 0) { + expected = x /y; + } else { + expected = 0; + } + + //When + //calling groups class and method to store the value of the actual method + // + double actual = Calculator.divide(x,y); + + //Then + Assert.assertEquals(expected, actual, .001); + } + + + + @Test + public void exponentiationTest1() { + + //Given, this is the expected behavior + //change variables to names of group's methods + double x = 2; + double y = 4; + double expected = Math.pow(x,y); + + //When + //calling groups class and method to store the value of the actual method + // + double actual = Calculator.exponentiation(x, y); + + //Then + Assert.assertEquals(expected, actual, .001); + } + @Test + public void exponentiationTest2() { + + //Given, this is the expected behavior + //change variables to names of group's methods + double x = 4; + double y = 4; + double expected = Math.pow(x,y); + + //When + //calling groups class and method to store the value of the actual method + // + double actual = Calculator.exponentiation(x, y); + + //Then + Assert.assertEquals(expected, actual, .001); + } + @Test + public void exponentiationTest3() { + + //Given, this is the expected behavior + //change variables to names of group's methods + double x = 10; + double y = -10; + double expected = Math.pow(x,y); + + //When + //calling groups class and method to store the value of the actual method + // + double actual = Calculator.exponentiation(x, y); + + //Then + Assert.assertEquals(expected, actual, .001); + } + + + + @Test + public void sqrTest1() { + + //Given, this is the expected behavior + //change variables to names of group's methods + double x = 2; + double expected = (x * x); + + //When + //calling groups class and method to store the value of the actual method + // + double actual = Calculator.square(x); + + //Then + Assert.assertEquals(expected, actual, .001); + } + @Test + public void sqrTest2() { + + //Given, this is the expected behavior + //change variables to names of group's methods + double x = 5; + double expected = (x * x); + + //When + //calling groups class and method to store the value of the actual method + // + double actual = Calculator.square(x); + + //Then + Assert.assertEquals(expected, actual, .001); + } + @Test + public void sqrTest3() { + + //Given, this is the expected behavior + //change variables to names of group's methods + double x = 12; + double expected = (x * x); + + //When + //calling groups class and method to store the value of the actual method + // + double actual = Calculator.square(x); + + //Then + Assert.assertEquals(expected, actual, .001); + } + + + + @Test + public void sqrtTest1() { + //Given, this is the expected behavior + //change variables to names of group's methods + double x = 16; + double expected = Math.sqrt(x); + + //When + //calling group's class and method to store the value of the actual method + // + double actual = Calculator.squareRoot(x); + + //Then + Assert.assertEquals(expected, actual, 0.001); + } + @Test + public void sqrtTest2() { + //Given, this is the expected behavior + //change variables to names of group's methods + double x = 25; + double expected = Math.sqrt(x); + + //When + //calling group's class and method to store the value of the actual method + // + double actual = Calculator.squareRoot(x); + + //Then + Assert.assertEquals(expected, actual, 0.001); + } + @Test + public void sqrtTest3() { + //Given, this is the expected behavior + //change variables to names of group's methods + double x = 100; + double expected = Math.sqrt(x); + + //When + //calling group's class and method to store the value of the actual method + // + double actual = Calculator.squareRoot(x); + + //Then + Assert.assertEquals(expected, actual, 0.001); + } + + + + @Test + public void invertSignTest1() { + + //Given, this is the expected behavior + //change variables to names of group's methods + double x = 2; + double expectedSum = x * -1; + + //When + //calling groups class and method to store the value of the actual method + // + double actual = Calculator.invertSign(x); + + //Then + Assert.assertEquals(expectedSum, actual, .001); + } + @Test + public void invertSignTest2() { + //Given, this is the expected behavior + //change variables to names of group's methods + double x = -16; + double expectedSum = x * -1; + + //When + //calling groups class and method to store the value of the actual method + // + double actual = Calculator.invertSign(x); + + //Then + Assert.assertEquals(expectedSum, actual, .001); + } + @Test + public void invertSignTest3() { + //Given, this is the expected behavior + //change variables to names of group's methods + double x = 0; + double expectedSum = x * -1; + + //When + //calling groups class and method to store the value of the actual method + // + double actual = Calculator.invertSign(x); + + //Then + Assert.assertEquals(expectedSum, actual, .001); + } +} \ No newline at end of file diff --git a/src/test/java/com/zipcodewilmington/scientific_calculator/ScientificTest.java b/src/test/java/com/zipcodewilmington/scientific_calculator/ScientificTest.java new file mode 100644 index 0000000..fa51d9c --- /dev/null +++ b/src/test/java/com/zipcodewilmington/scientific_calculator/ScientificTest.java @@ -0,0 +1,213 @@ +package com.zipcodewilmington.scientific_calculator; + +import com.zipcodewilmington.scientificcalculator.MainApplication; +import com.zipcodewilmington.scientificcalculator.Calculator; +import com.zipcodewilmington.scientificcalculator.Science; +import org.apache.commons.io.output.ByteArrayOutputStream; +import org.junit.After; +import org.junit.Assert; +import org.junit.Before; +import org.junit.Test; + +import java.io.PrintStream; + +public class ScientificTest { + private final ByteArrayOutputStream outContent = new ByteArrayOutputStream(); + private final PrintStream originalOut = System.out; + + @Before + public void setUpStreams() { + // changes "System.out.print" commands to print to this stream, rather than the console + System.setOut(new PrintStream(outContent)); + } + + @After + public void restoreStreams() { + // we do this to avoid having any null pointer exceptions + System.setOut(originalOut); + } + + @Test + public void sinTest1() { + //Given, this is the expected behavior + //change variables to names of group's methods + double x = 60; + double expected = Math.sin(x); + + //When + //calling groups class and method to store the value of the actual method + // + double actual = Science.Sin(x); + + //Then + Assert.assertEquals(expected, actual, 0.001); + } + + @Test + public void cosTest1() { + //Given, this is the expected behavior + //change variables to names of group's methods + double x = 60; + double expected = Math.cos(x); + + //When + //calling groups class and method to store the value of the actual method + // + double actual = Science.Cos(x); + + //Then + Assert.assertEquals(expected, actual, 0.001); + } + + @Test + public void tanTest1() { + //Given, this is the expected behavior + //change variables to names of group's methods + double x = 60; + double expected = Math.tan(x); + + //When + //calling groups class and method to store the value of the actual method + // + double actual = Science.Tan(x); + + //Then + Assert.assertEquals(expected, actual, 0.001); + } + + @Test + public void asinTest1() { + //Given, this is the expected behavior + //change variables to names of group's methods + double x = 60; + double expected = Math.asin(x); + + //When + //calling groups class and method to store the value of the actual method + // + double actual = Science.aSin(x); + + //Then + Assert.assertEquals(expected, actual, 0.001); + } + + @Test + public void acosTest1() { + //Given, this is the expected behavior + //change variables to names of group's methods + double x = 60; + double expected = Math.acos(x); + + //When + //calling groups class and method to store the value of the actual method + // + double actual = Science.aCos(x); + + //Then + Assert.assertEquals(expected, actual, 0.001); + } + + @Test + public void atanTest1() { + //Given, this is the expected behavior + //change variables to names of group's methods + double x = 60; + double expected = Math.atan(x); + + //When + //calling groups class and method to store the value of the actual method + // + double actual = Science.aTan(x); + + //Then + Assert.assertEquals(expected, actual, 0.001); + } + + @Test + public void logTest1() { + //Given, this is the expected behavior + //change variables to names of group's methods + double x = 60; + double expected = Math.log(x); + + //When + //calling groups class and method to store the value of the actual method + // + double actual = Science.log(x); + + //Then + Assert.assertEquals(expected, actual, 0.001); + } + + @Test + public void inverseLogTest1() { + //Given, this is the expected behavior + //change variables to names of group's methods + double x = 60; + double expected = Math.log10(x); + + //When + //calling groups class and method to store the value of the actual method + // + double actual = Science.invLog(x); + + //Then + Assert.assertEquals(expected, actual, 0.001); + } + + @Test + public void naturalLogTest1() { + //Given, this is the expected behavior + //change variables to names of group's methods + double x = 60; + double expected = Math.log(x); + + //When + //calling groups class and method to store the value of the actual method + // + double actual = Science.natLog(x); + + //Then + Assert.assertEquals(expected, actual, 0.001); + } + + @Test + public void inverseNaturalLogTest1() { + //Given, this is the expected behavior + //change variables to names of group's methods + double x = 60; + double expected = Math.exp(Math.log(x)); + + //When + //calling groups class and method to store the value of the actual method + // + double actual = Science.invNatLog(x); + + //Then + Assert.assertEquals(expected, actual, 0.001); + } + + @Test + public void factorialTest1() { + //Given, this is the expected behavior + //change variables to names of group's methods + double storedNum = 5; + double x = storedNum; + double expected = 120; + double total = 1; + for (int i = 0; 0 < x; i++){ + + // add N to the total sum of the number + total *= x;//3 + x -= 1; + //have total increment with i till its less than n + } + //When + //calling groups class and method to store the value of the actual method + // + double actual = Science.factorial(storedNum); + + //Then + Assert.assertEquals(expected, actual, 0.001); + } +} diff --git a/src/test/java/com/zipcodewilmington/scientific_calculator/TestMainApplication.java b/src/test/java/com/zipcodewilmington/scientific_calculator/TestMainApplication.java index 94e8d98..f6988c6 100644 --- a/src/test/java/com/zipcodewilmington/scientific_calculator/TestMainApplication.java +++ b/src/test/java/com/zipcodewilmington/scientific_calculator/TestMainApplication.java @@ -1,7 +1,25 @@ package com.zipcodewilmington.scientific_calculator; -/** - * Created by leon on 2/9/18. - */ +import java.util.logging.Level; +import java.util.logging.Logger; + +import static org.junit.Assert.*; +import static org.junit.jupiter.api.Assertions.*; + +import com.zipcodewilmington.scientificcalculator.MainApplication; +import org.junit.Assert; +import org.junit.Test; + +import org.junit.runner.RunWith; +import org.junit.runners.Suite; + +@RunWith(Suite.class) + +@Suite.SuiteClasses({ + CoreTest.class, + ScientificTest.class, +}) public class TestMainApplication { + + }