diff --git a/.gitignore b/.gitignore index de469bb3..1d24f508 100644 --- a/.gitignore +++ b/.gitignore @@ -14,6 +14,7 @@ .idea/**/sqlDataSources.xml .idea/**/dynamic.xml .idea/**/uiDesigner.xml +.DS_Store # Gradle: .idea/**/gradle.xml @@ -149,7 +150,7 @@ fabric.properties .project .classpath .settings - +.DS_Store #maven build target -target/ \ No newline at end of file +target/ diff --git a/pom.xml b/pom.xml index e7cb4f6b..73de514a 100644 --- a/pom.xml +++ b/pom.xml @@ -8,5 +8,13 @@ scientific_calculator 1.0-SNAPSHOT + + + junit + junit + 4.13 + test + + \ No newline at end of file diff --git a/src/.idea/.gitignore b/src/.idea/.gitignore new file mode 100644 index 00000000..e7e9d11d --- /dev/null +++ b/src/.idea/.gitignore @@ -0,0 +1,2 @@ +# Default ignored files +/workspace.xml diff --git a/src/.idea/misc.xml b/src/.idea/misc.xml new file mode 100644 index 00000000..28a804d8 --- /dev/null +++ b/src/.idea/misc.xml @@ -0,0 +1,6 @@ + + + + + \ No newline at end of file diff --git a/src/.idea/modules.xml b/src/.idea/modules.xml new file mode 100644 index 00000000..f669a0e5 --- /dev/null +++ b/src/.idea/modules.xml @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/src/.idea/vcs.xml b/src/.idea/vcs.xml new file mode 100644 index 00000000..6c0b8635 --- /dev/null +++ b/src/.idea/vcs.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/src/main/.DS_Store b/src/main/.DS_Store new file mode 100644 index 00000000..697099d5 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..ae0f618c Binary files /dev/null and b/src/main/java/.DS_Store differ diff --git a/src/main/java/com/zipcodewilmington/scientificcalculator/Basic.java b/src/main/java/com/zipcodewilmington/scientificcalculator/Basic.java new file mode 100644 index 00000000..1e816a9c --- /dev/null +++ b/src/main/java/com/zipcodewilmington/scientificcalculator/Basic.java @@ -0,0 +1,52 @@ +package com.zipcodewilmington.scientificcalculator; + +public class Basic{ + public static double add(double a, double b){ + double sum = a+b; + return sum; + } + public static double subtract(double a, double b){ + double difference = a-b; + return difference; + + } + public static double multiply(double a, double b){ + double product = a*b; + return product; + } + + public static double divide(double a, double b){ + double quotient = a/b; + return quotient; + } + + public static double square(double a){ + double squareResult = (double) Math.pow(a,2); + return squareResult; + + } + public static double squareRoot(double a){ + double squareRootResult = (double) Math.sqrt(a); + return squareRootResult; + } + public static double exponent(double a, double b){ + double exponentResult = (double) Math.pow(a,b); + return exponentResult; + } + public static double inverse(double a){ + double inverseResult = 1/a; + return inverseResult; + } + public static double signChange(double a){ + double opposite = 0; + if (a > 0){ + opposite = a - (2 * Math.abs(a)); + } else if(a < 0){ + opposite = a + (2 * Math.abs(a)); + } else { + opposite = 0; + } + + return opposite; + } +} \ No newline at end of file diff --git a/src/main/java/com/zipcodewilmington/scientificcalculator/Console.java b/src/main/java/com/zipcodewilmington/scientificcalculator/Console.java index 83f0e97f..660896b4 100644 --- a/src/main/java/com/zipcodewilmington/scientificcalculator/Console.java +++ b/src/main/java/com/zipcodewilmington/scientificcalculator/Console.java @@ -2,6 +2,10 @@ import java.util.Scanner; +import static com.zipcodewilmington.scientificcalculator.Basic.*; +import static com.zipcodewilmington.scientificcalculator.Sci.*; +import static com.zipcodewilmington.scientificcalculator.Sci.factorial; + /** * Created by leon on 2/9/18. */ @@ -22,11 +26,615 @@ public static String getStringInput(String prompt) { return userInput; } - public static Integer getIntegerInput(String prompt) { - return null; + + + + + public static void BasicMenu() { + System.out.printf("%-10s %-10s %-10s", "1 - Add |", "2 - Subtract |", "3 - Multiply \n"); + System.out.printf("%-10s %-10s %-10s", "4 - Divide |", "5 - Square |", "6 - Square Root \n"); + System.out.printf("%-10s %-10s %-10s", "7 - Exponent |", "8 - Inverse |", "9 - Pos <--> Neg \n"); + ForAllMenus(); + String s = Console.getStringInput("Please select an option"); + if (s.equals("1")) { + //+ + double curInt = 0; + double pastInt = 0; + + while (!s.equals("x")) { + s = Console.getStringInput("Please enter a number\nEnter x when done"); + if (s.equals("x")) { + break; + } + curInt = Double.parseDouble(s); + if (pastInt == 0) { + System.out.println(curInt); + } else { + System.out.println(add(pastInt, curInt)); + } + + pastInt = curInt; + + } + BasicMenu(); + } + + else if (s.equals("2")) { + //- + double curInt = 0; + double pastInt = 0; + + while (!s.equals("x")) { + s = Console.getStringInput("Please enter a number\nEnter x when done"); + if (s.equals("x")) { + break; + } + curInt = Double.parseDouble(s); + if (pastInt == 0) { + System.out.println(curInt); + } else { + System.out.println(subtract(pastInt, curInt)); + } + + pastInt = curInt; + + } + BasicMenu(); + } + else if (s.equals("3")) { + //* + double curInt = 0; + double pastInt = 0; + + while (!s.equals("x")) { + s = Console.getStringInput("Please enter a number\nEnter x when done"); + if (s.equals("x")) { + break; + } + curInt = Double.parseDouble(s); + if (pastInt == 0) { + System.out.println(curInt); + } else { + System.out.println(multiply(pastInt, curInt)); + } + + pastInt = curInt; + + } + BasicMenu(); + } + else if (s.equals("4")) { + //divide + double curInt = 0; + double pastInt = 0; + + while (!s.equals("x")) { + s = Console.getStringInput("Please enter a number\nEnter x when done"); + if (s.equals("x")) { + break; + } + curInt = Double.parseDouble(s); + if (pastInt == 0) { + System.out.println(curInt); + } else { + System.out.println(divide(pastInt, curInt)); + } + + pastInt = curInt; + + } + BasicMenu(); + } + else if (s.equals("5")) { + //square + double curInt = 0; + s = Console.getStringInput("Please enter a number"); + curInt = Double.parseDouble(s); + System.out.println(square(curInt)); + BasicMenu(); + } + else if (s.equals("6")) { + //square root + double curInt = 0; + s = Console.getStringInput("Please enter a number"); + curInt = Double.parseDouble(s); + System.out.println(squareRoot(curInt)); + BasicMenu(); + } + else if (s.equals("7")) { + //exponent + double curInt = 0; + double pastInt = 0; + + while (!s.equals("x")) { + s = Console.getStringInput("Please enter a number\nEnter x when done"); + if (s.equals("x")) { + break; + } + curInt = Double.parseDouble(s); + if(pastInt == 0) { + System.out.println(curInt); + } + else { + System.out.println(exponent(pastInt, curInt)); + } + + + pastInt = curInt; + + } + BasicMenu(); + } + else if (s.equals("8")) { + //inverse + double curInt = 0; + s = Console.getStringInput("Please enter a number"); + curInt = Double.parseDouble(s); + System.out.println(inverse(curInt)); + + } else if (s.equals("9")) { + //sign change + double curInt = 0; + s = Console.getStringInput("Please enter a number"); + curInt = Double.parseDouble(s); + System.out.println(signChange(curInt)); + BasicMenu(); + } else if (s.equals("a")) { + //Clear Error + s = ""; + BasicMenu(); + } else if (s.equals("b")) { + //Clear Display + s = ""; + BasicMenu(); + } else if ((s.equals("c")) || ((s.equals("d")))) { + //Back + Greeting(); + + } else if (s.equals("e")) { + //Exit + ExitCalc(); + } else { + System.out.println("Please enter a valid response"); + BasicMenu(); + + } + + + } + + public static void SciMenuHome(){ + System.out.println("Rotate Display - 1"); + System.out.println("Memory - 2"); + System.out.println("Trig Functions - 3"); + System.out.println("Mode Change - 4"); + System.out.println("Log Functions - 5"); + System.out.println("Factorial Functions - 6"); + ForAllMenus(); + + String s = Console.getStringInput("Please select an option"); + //Start Rotate Display + if (s.equals("1")) { + RotateDisplay(); + } + else if (s.equals("2")) { + Memory(); + } + else if (s.equals("3")) { + TrigFunctions(); + } + else if (s.equals("4")) { + ModeChange(); + } + else if (s.equals("5")) { + LogFunctions(); + } + else if (s.equals("6")) { + //Factorial Functions + int curInt = 0; + s = Console.getStringInput("Please enter a number"); + curInt = Integer.parseInt(s); + System.out.println(factorial(curInt)); + SciMenuHome(); + } +//End Factorial Function + else if (s.equals("a")) { + //Clear Error + s = ""; + SciMenuHome(); + } + else if (s.equals("b")) { + //Clear Display + s = ""; + SciMenuHome(); + } + else if (s.equals("c")) { + //Back + Greeting(); + + } + else if (s.equals("d")) { + //Main Menu + Greeting(); + + } + else if (s.equals("e")) { + //Exit + ExitCalc(); + } + else { + System.out.println("Please enter a valid response"); + SciMenuHome(); + + } + } - public static Double getDoubleInput(String prompt) { - return null; + public static void RotateDisplay(){ + System.out.println("Binary - 1"); + System.out.println("Octal - 2"); + System.out.println("Decimal - 3"); + System.out.println("Hexadecimal - 4"); + ForAllMenus(); + + String s = Console.getStringInput("Please select an option"); + if (s.equals("1")) { + //bin + int curInt = 0; + s = Console.getStringInput("Please enter a number"); + curInt = Integer.parseInt(s); + System.out.println(switchDisplayModeToBinary(curInt)); + RotateDisplay(); + } + else if (s.equals("2")) { + //oct + int curInt = 0; + s = Console.getStringInput("Please enter a number"); + curInt = Integer.parseInt(s); + System.out.println(switchDisplayModeToOctal(curInt)); + RotateDisplay(); + } + else if (s.equals("3")) { + //dec + int curInt = 0; + s = Console.getStringInput("Please enter a number"); + curInt = Integer.parseInt(s); + System.out.println(switchDisplayModeToDecimal(curInt)); + RotateDisplay(); + } + else if (s.equals("4")) { + //hex + int curInt = 0; + s = Console.getStringInput("Please enter a number"); + curInt = Integer.parseInt(s); + System.out.println(switchDisplayModeToHexadecimal(curInt)); + RotateDisplay(); + } + else if (s.equals("a")) { + //Clear Error + s = ""; + } + else if (s.equals("b")) { + //Clear Display + s = ""; + } + else if (s.equals("c")) { + //Back + SciMenuHome(); + + } + else if (s.equals("d")) { + //Main Menu + Greeting(); + + } + else if (s.equals("e")) { + //Exit + ExitCalc(); + } + else { + System.out.println("Please enter a valid response"); + RotateDisplay(); + + } + RotateDisplay(); + } -} + public static void Memory() { + System.out.println("M+ - 1"); + System.out.println("MC - 2"); + System.out.println("MRC - 3"); + ForAllMenus(); + + String s = Console.getStringInput("Please select an option"); + if (s.equals("1")) { + //M+ + float curInt = 0; + s = Console.getStringInput("Please enter a number"); + curInt = Float.parseFloat(s); + System.out.println(memPlus(curInt)); + Memory(); + memoryStatus = "stored"; + + } else if (s.equals("2")) { + //MC + + memClear(); + Memory(); + memoryStatus = "not stored"; + + } + + else if (s.equals("3")) { + //MRC + + if (memoryStatus.equals("stored")) { + System.out.println(memNum); + Memory(); + } else { + System.out.println("No memory stored!"); + Memory(); + } + + } + else if (s.equals("a")) { + //Clear Error + s = ""; + Memory(); + } + else if (s.equals("b")) { + //Clear Display + s = ""; + Memory(); + } + else if (s.equals("c")) { + //Back + SciMenuHome(); + + } + else if (s.equals("d")) { + //Main Menu + Greeting(); + + } + else if (s.equals("e")) { + //Exit + ExitCalc(); + } + else { + System.out.println("Please enter a valid response"); + Memory(); + + } + + } + public static void TrigFunctions(){ + System.out.println("Sin - 1"); + System.out.println("Cos - 2"); + System.out.println("Tan - 3"); + System.out.println("Arcsin - 4"); + System.out.println("Arccos - 5"); + System.out.println("Arctan - 6"); + ForAllMenus(); + + String s = Console.getStringInput("Please select an option"); + if (s.equals("1")) { + //sin + float curInt = 0; + s = Console.getStringInput("Please enter a number"); + curInt = Float.parseFloat(s); + System.out.println(sine(curInt)); + TrigFunctions(); + + } + else if (s.equals("2")) { + //cos + float curInt = 0; + s = Console.getStringInput("Please enter a number"); + curInt = Float.parseFloat(s); + System.out.println(cosine(curInt)); + TrigFunctions(); + } + else if (s.equals("3")) { + //tan + float curInt = 0; + s = Console.getStringInput("Please enter a number"); + curInt = Float.parseFloat(s); + System.out.println(tangent(curInt)); + TrigFunctions(); + } + else if (s.equals("4")) { + //arcsin + float curInt = 0; + s = Console.getStringInput("Please enter a number"); + curInt = Float.parseFloat(s); + System.out.println(inverseSine(curInt)); + TrigFunctions(); + } + else if (s.equals("5")) { + //arccos + float curInt = 0; + s = Console.getStringInput("Please enter a number"); + curInt = Float.parseFloat(s); + System.out.println(inverseCosine(curInt)); + TrigFunctions(); + } + else if (s.equals("6")) { + //arctan + float curInt = 0; + s = Console.getStringInput("Please enter a number"); + curInt = Float.parseFloat(s); + System.out.println(inverseTangent(curInt)); + TrigFunctions(); + } + else if (s.equals("a")) { + //Clear Error + s = ""; + TrigFunctions(); + } else if (s.equals("b")) { + //Clear Display + s = ""; + TrigFunctions(); + } else if (s.equals("c")) { + //Back + SciMenuHome(); + + } else if (s.equals("d")) { + //Main Menu + Greeting(); + + } else if (s.equals("e")) { + //Exit + ExitCalc(); + } else { + System.out.println("Please enter a valid response"); + + + } + TrigFunctions(); + } + public static void ModeChange(){ + System.out.println("Rotate Degrees - 1"); + System.out.println("Rotate Radius - 2"); + ForAllMenus(); + + String s = Console.getStringInput("Please select an option"); + if (s.equals("1")) { + //deg + float curInt = 0; + s = Console.getStringInput("Please enter a number"); + curInt = Float.parseFloat(s); + ModeChange(); + } + else if (s.equals("2")) { + //rad + float curInt = 0; + s = Console.getStringInput("Please enter a number"); + curInt = Float.parseFloat(s); + ModeChange(); + } + else if (s.equals("a")) { + //Clear Error + s = ""; + } + else if (s.equals("b")) { + //Clear Display + s = ""; + } + else if (s.equals("c")) { + //Back + SciMenuHome(); + + } + else if (s.equals("d")) { + //Main Menu + Greeting(); + + } + else if (s.equals("e")) { + //Exit + ExitCalc(); + } + else { + System.out.println("Please enter a valid response"); + ModeChange(); + + } + ModeChange(); + + } + public static void LogFunctions(){ + System.out.println("Log - 1"); + System.out.println("Inverse Log - 2"); + System.out.println("Ln - 3"); + System.out.println("e^x - 4"); + ForAllMenus(); + + String s = Console.getStringInput("Please select an option"); + if (s.equals("1")) { + //log + float curInt = 0; + + s = Console.getStringInput("Please enter a number"); + curInt = Float.parseFloat(s); + System.out.println(logarithm(curInt)); + + } + else if (s.equals("2")) { + //inverse log + float curInt = 0; + float pastInt = 0; + s = Console.getStringInput("Please enter a number"); + curInt = Float.parseFloat(s); + + if (pastInt == 0) { + System.out.println(curInt); + } else { + System.out.println(inverseLogarithm(pastInt, curInt)); + } + + pastInt = curInt; + + + } + else if (s.equals("3")) { + //ln + float curInt = 0; + s = Console.getStringInput("Please enter a number"); + curInt = Float.parseFloat(s); + System.out.println(naturalLogarithm(curInt)); + + } + else if (s.equals("4")) { + //e^x + } + else if (s.equals("a")) { + //Clear Error + s = ""; + } + else if (s.equals("b")) { + //Clear Display + s = ""; + } + else if (s.equals("c")) { + //Back + SciMenuHome(); + + } + else if (s.equals("d")) { + //Main Menu + Greeting(); + + } + else if (s.equals("e")) { + //Exit + ExitCalc(); + } + else { + System.out.println("Please enter a valid response"); + LogFunctions(); + + } + LogFunctions(); + } + public static void ForAllMenus() { + System.out.println("Clear Error - a"); + System.out.println("Clear Display - b"); + System.out.println("Back - c"); + System.out.println("Main Menu - d"); + System.out.println("Exit - e"); + } + + public static void ExitCalc(){ + System.exit(0); + } + + public static String Greeting() { + Console.println("Welcome to my calculator!"); + String s = Console.getStringInput("1 - Basic | 2 - Scientific | 3 - Exit"); + return s; + } + + + } + diff --git a/src/main/java/com/zipcodewilmington/scientificcalculator/EmmaTestMethods.java b/src/main/java/com/zipcodewilmington/scientificcalculator/EmmaTestMethods.java new file mode 100644 index 00000000..87fcdfe9 --- /dev/null +++ b/src/main/java/com/zipcodewilmington/scientificcalculator/EmmaTestMethods.java @@ -0,0 +1,29 @@ +package com.zipcodewilmington.scientificcalculator; + + +import java.util.stream.IntStream; + +public class EmmaTestMethods { + public int a; + public int b; + public String result; + + public static Integer Addition(int x, int y) { + return x + y; + } + + + + public static int[] stringArrayToIntArray(String intString) { + String[] intStringSplit = intString.split(" "); //Split by spaces + int[] result = new int[intStringSplit.length]; //Used to store our ints + + for (int i = 0; i < intStringSplit.length; i++) { + //parse and store each value into int[] to be returned + result[i] = Integer.parseInt(intStringSplit[i]); + } + return result; + } + } + + diff --git a/src/main/java/com/zipcodewilmington/scientificcalculator/MainApplication.java b/src/main/java/com/zipcodewilmington/scientificcalculator/MainApplication.java index 5f421325..b8d8f64e 100644 --- a/src/main/java/com/zipcodewilmington/scientificcalculator/MainApplication.java +++ b/src/main/java/com/zipcodewilmington/scientificcalculator/MainApplication.java @@ -1,17 +1,41 @@ package com.zipcodewilmington.scientificcalculator; + +import static com.zipcodewilmington.scientificcalculator.Console.*; +import static com.zipcodewilmington.scientificcalculator.Basic.*; +import static com.zipcodewilmington.scientificcalculator.Sci.*; /** * Created by leon on 2/9/18. */ 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("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); - } -} + + + + String s = Greeting(); + if (s.equals("1")) { + BasicMenu(); + } + + else if (s.equals("2")) { + SciMenuHome(); + } + + else if (s.equals("xxx")) { + System.exit(0); + } + else { + System.out.println("Please enter a valid response"); + Greeting(); + } + + + } //void main +} //main app + + + + + + + diff --git a/src/main/java/com/zipcodewilmington/scientificcalculator/Sci.java b/src/main/java/com/zipcodewilmington/scientificcalculator/Sci.java new file mode 100644 index 00000000..290707a5 --- /dev/null +++ b/src/main/java/com/zipcodewilmington/scientificcalculator/Sci.java @@ -0,0 +1,156 @@ +package com.zipcodewilmington.scientificcalculator; + +//converts currently-displayed number to binary +public class Sci { + public static String switchDisplayModeToBinary(Integer a){ + String displayMode = ""; + String converted = Integer.toString(a,2); + + return converted; + + } + public static String switchDisplayModeToHexadecimal(Integer a){ + String displayMode = ""; + String converted = Integer.toString(a,16); + + + return converted; + + } + public static String switchDisplayModeToOctal(Integer a){ + String displayMode = ""; + String converted = Integer.toString(a,8); + + return converted; + + } + public static String switchDisplayModeToDecimal(Integer a){ + String displayMode = ""; + String converted = Integer.toString(a,10); + + return converted; + + } + + static double memNum; + static String memoryStatus = "not stored"; + public static void checkMemStatus(){ + if (memNum == 0 || memNum > 0 || memNum < 0){ + memoryStatus = "stored"; + } else { + memoryStatus = "not stored"; + } + } + public static double memPlus(double a) { + checkMemStatus(); + if (memoryStatus.equals("stored")){ + memNum += a; + } else { + memNum = a; + } + + return memNum; + } + + public static void memClear(){ + memoryStatus = "not stored"; + memNum = 0; + + + } + + public static String noMem() { + return "no memory stored"; + } + + public static double yesMem(){ + return memNum; + } + + public static void recall() { + checkMemStatus(); + if (memoryStatus.equals("not stored")) { + noMem(); + } else { + yesMem(); + } + } + public static double sine(double a){ + double sin = (double) Math.sin(a); + return sin; + } + public static double cosine(double a){ + double cos = (double) Math.cos(a); + return cos; + } + public static double tangent(double a){ + double tan = (double) Math.tan(a); + return tan; + } + public static double inverseSine(double a){ + double invSin = (double) Math.asin(a); + return invSin; + } + public static double inverseCosine(double a){ + double invCos = (double) Math.acos(a); + return invCos; + } + public static double inverseTangent(double a){ + double invTan = (double) Math.atan(a); + return invTan; + } + + public static double switchUnitsModeRotate(double a){ + String unitsMode = "Radians"; + double converted = 0; + if (unitsMode.equals("Radians")) { + unitsMode = "Degrees"; + converted = (double) Math.toDegrees(a); + } else { + unitsMode = "Radians"; + converted = (double) Math.toRadians(a); + } + return converted; + //degrees,radians + } + + public double switchUnitsModeString(String unitsModeInput, double a){ + double converted = 0; + if (unitsModeInput.equals("Degrees")){ + converted = (double) Math.toDegrees(a); + return converted; + } else if (unitsModeInput.equals("Radians")){ + converted = (double) Math.toRadians(a); + return converted; + } else { + System.out.println("Invalid unit type, try again."); + return converted; + } + + } + public static double logarithm(double a){ + double log = (double) Math.log10(a); + return log; + } + public static double inverseLogarithm(double a, double b){ + double invLog = (double) (Math.pow(a, b)); + return invLog; + //Request for first input to be 10 + } + public static double naturalLogarithm(double a){ + double natLog = (double) Math.log(a); + return natLog; + } + public double inverseNaturalLogarithm(double a, double b){ + double invNatLog = (double) (Math.pow(a, b)); + return invNatLog; + //Request for the first input to be the number e + } + public static Integer factorial(Integer a){ + Integer fact = a; + for (int i = 0; i< a;a++){ + fact *= a-1; + } + return fact; + } +} diff --git a/src/test/java/com/zipcodewilmington/scientific_calculator/TestBasic.java b/src/test/java/com/zipcodewilmington/scientific_calculator/TestBasic.java new file mode 100644 index 00000000..539c033e --- /dev/null +++ b/src/test/java/com/zipcodewilmington/scientific_calculator/TestBasic.java @@ -0,0 +1,21 @@ +package com.zipcodewilmington.scientific_calculator; + +import com.zipcodewilmington.scientificcalculator.Basic; +import org.junit.Assert; +import org.junit.Before; +import org.junit.Test; + +public class TestBasic { + + @Test + public void testAdd1(){ + Basic calculator = new Basic(); + Assert.assertEquals(5, calculator.add(2, 3), 0); + } + + @Test + public void testAdd2(){ + Basic calculator = new Basic(); + Assert.assertEquals(15, calculator.add(7, 8), 0); + } +} diff --git a/src/test/java/com/zipcodewilmington/scientific_calculator/TestMainApplication.java b/src/test/java/com/zipcodewilmington/scientific_calculator/TestMainApplication.java index 94e8d987..f27f5567 100644 --- a/src/test/java/com/zipcodewilmington/scientific_calculator/TestMainApplication.java +++ b/src/test/java/com/zipcodewilmington/scientific_calculator/TestMainApplication.java @@ -1,7 +1,267 @@ package com.zipcodewilmington.scientific_calculator; +import com.sun.corba.se.impl.interceptors.PICurrent; +import com.zipcodewilmington.scientificcalculator.Basic; +import com.zipcodewilmington.scientificcalculator.Sci; +import com.zipcodewilmington.scientificcalculator.Console; +import com.zipcodewilmington.scientificcalculator.MainApplication; +import org.junit.Assert; +import org.junit.Before; +import org.junit.Test; + +import javax.xml.bind.annotation.adapters.XmlJavaTypeAdapters; + +import static org.junit.Assert.assertEquals; + /** * Created by leon on 2/9/18. */ public class TestMainApplication { + + @Test + public void testAdd1(){ + Basic calculator = new Basic(); + assertEquals(5, calculator.add(2, 3), 0); + } + + @Test + public void testAdd2(){ + Basic calculator = new Basic(); + assertEquals(15, calculator.add(7, 8), 0); + } + + @Test + public void testMinus1(){ + Basic calculator = new Basic(); + assertEquals(15, calculator.subtract(19, 4), 0); + } + + @Test + public void testMinus2(){ + Basic calculator = new Basic(); + assertEquals(99, calculator.subtract(123, 24), 0); + } + + @Test + public void testMultiply1(){ + Basic calculator = new Basic(); + assertEquals(20, calculator.multiply(5, 4), 0); + } + + @Test + public void testMultiply2(){ + Basic calculator = new Basic(); + assertEquals(15, calculator.multiply(5, 3), 0); + } + + @Test + public void testMultiplyByZero(){ + Basic calculator = new Basic(); + assertEquals(0, calculator.multiply(5, 0), 0); + } + + @Test + public void testDivide1(){ + Basic calculator = new Basic(); + assertEquals(5, calculator.divide(10, 2), 0); + } + + @Test + public void testDivide2(){ + Basic calculator = new Basic(); + assertEquals(3.33, calculator.divide(10, 3), 0.01); + } + + @Test + public void testDivideByZero(){ + Basic calculator = new Basic(); + assertEquals(15, calculator.divide(5, 0), 0); + } + + @Test + public void testSquare1(){ + Basic calculator = new Basic(); + assertEquals(100, calculator.square(10), 0); + } + + @Test + public void testSquare2(){ + Basic calculator = new Basic(); + assertEquals(25, calculator.square(5), 0); + } + + @Test + public void testSquareRoot1(){ + Basic calculator = new Basic(); + assertEquals(5, calculator.squareRoot(25), 0); + } + + @Test + public void testSquareRoot2(){ + Basic calculator = new Basic(); + assertEquals(1.4142135, calculator.squareRoot(2), 0.1); + } + + @Test + public void testInverse1(){ + Basic calculator = new Basic(); + assertEquals(1/25, calculator.inverse(25), 0.1); + } + + @Test + public void testInverse2(){ + Basic calculator = new Basic(); + assertEquals(0.5, calculator.inverse(2), 0.1); + } + + @Test + public void testPosToNeg1(){ + Basic calculator = new Basic(); + assertEquals(-2, calculator.signChange(2), 0.1); + } + + @Test + public void testPosToNeg2(){ + Basic calculator = new Basic(); + assertEquals(12345, calculator.signChange(-12345), 0.1); + } + + @Test + public void testExponent1(){ + Basic calculator = new Basic(); + assertEquals(343, calculator.exponent(7, 3), 0.1); + } + @Test + public void testExponent2() { + Basic calculator = new Basic(); + assertEquals(343, calculator.exponent(0, 0), 0.1); + } + + @Test + public void testSine1(){ + Sci calculator = new Sci(); + assertEquals(1, calculator.sine(Math.PI/2), 0); + } + + @Test + public void testTestSine2(){ + Sci calculator = new Sci(); + assertEquals(-1, calculator.sine(Math.PI*3/2), 0); + } + + @Test + public void testCosine1(){ + Sci calculator = new Sci(); + assertEquals(0, calculator.cosine(Math.PI/2), 0); + } + + @Test + public void testCosine2(){ + Sci calculator = new Sci(); + assertEquals(-1, calculator.cosine(Math.PI), 0); + } + + @Test + public void testTangent1(){ + Sci calculator = new Sci(); + assertEquals(0, calculator.tangent(Math.PI), 0); + } + + @Test + public void testTangent2(){ + Sci calculator = new Sci(); + assertEquals(0, calculator.tangent(Math.PI*2), 0); + } + + @Test + public void testArcsine1(){ + Sci calculator = new Sci(); + assertEquals(Math.PI/2, calculator.inverseSine(1), 0); + } + + @Test + public void testArcsine2(){ + Sci calculator = new Sci(); + assertEquals(Math.PI/2, calculator.inverseSine(1), 0); + } + + @Test + public void testArccosine1(){ + Sci calculator = new Sci(); + assertEquals(0, calculator.inverseCosine(1), 0); + } + + @Test + public void testArccosine2(){ + Sci calculator = new Sci(); + assertEquals(0, calculator.inverseCosine(1), 0); + } + + @Test + public void testArctangent1(){ + Sci calculator = new Sci(); + assertEquals(Math.PI/4, calculator.inverseTangent(1), 0); + } + + @Test + public void testArctangent2(){ + Sci calculator = new Sci(); + assertEquals(Math.PI/4, calculator.inverseTangent(1), 0); + } + + @Test + public void testLog1(){ + Sci calculator = new Sci(); + assertEquals(0.77815, calculator.logarithm(6), 0.01); + } + + @Test + public void testLog2(){ + Sci calculator = new Sci(); + assertEquals(2, calculator.logarithm(100), 0.01); + } + + @Test + public void testInverseLog1(){ + Sci calculator = new Sci(); + assertEquals(1000, calculator.inverseLogarithm(10, 3), 0.01); + } + + @Test + public void testInverseLog2(){ + Sci calculator = new Sci(); + assertEquals(8, calculator.inverseLogarithm(2, 3), 0.01); + } + + @Test + public void testNaturalLog1(){ + Sci calculator = new Sci(); + assertEquals(1, calculator.naturalLogarithm(Math.E), 0.01); + } + + @Test + public void testNaturalLog2(){ + Sci calculator = new Sci(); + assertEquals(0, calculator.naturalLogarithm(1), 0.01); + } + + @Test + public void testEPower1(){ + Sci calculator = new Sci(); + assertEquals(1, calculator.inverseNaturalLogarithm(Math.E, 0), 0.01); + } + + @Test + public void testEPower2(){ + Sci calculator = new Sci(); + assertEquals(Math.E, calculator.inverseNaturalLogarithm(Math.E, 1), 0.01); + } +/* + @Test + public void mainApp(){ + MainApplication mainMenu = new MainApplication(); + assertEquals("1", mainMenu.main("1")); + } + + */ } diff --git a/testfile.md b/testfile.md new file mode 100644 index 00000000..e69de29b