diff --git a/pom.xml b/pom.xml index e7cb4f6b..d3824273 100644 --- a/pom.xml +++ b/pom.xml @@ -7,6 +7,35 @@ <groupId>com.zipcodewilmington</groupId> <artifactId>scientific_calculator</artifactId> <version>1.0-SNAPSHOT</version> + <dependencies> + <dependency> +<<<<<<< HEAD +======= + <groupId>org.junit.jupiter</groupId> + <artifactId>junit-jupiter-api</artifactId> + <version>RELEASE</version> + <scope>test</scope> + </dependency> + <dependency> +>>>>>>> 5fc5379bcfd98a961ba3060a7a722a4d6924258b + <groupId>junit</groupId> + <artifactId>junit</artifactId> + <version>4.12</version> + <scope>test</scope> + </dependency> + <dependency> + <groupId>junit</groupId> + <artifactId>junit</artifactId> + <version>4.12</version> + <scope>compile</scope> + </dependency> + <dependency> + <groupId>junit</groupId> + <artifactId>junit</artifactId> + <version>4.12</version> + <scope>compile</scope> + </dependency> + </dependencies> </project> \ 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..dc7e62f8 100644 --- a/src/main/java/com/zipcodewilmington/scientificcalculator/Console.java +++ b/src/main/java/com/zipcodewilmington/scientificcalculator/Console.java @@ -23,10 +23,18 @@ public static String getStringInput(String prompt) { } public static Integer getIntegerInput(String prompt) { - return null; + Scanner scanner = new Scanner(System.in); + println(prompt); + Integer userInput = Integer.valueOf(scanner.nextLine()); + return userInput; } + public static Double getDoubleInput(String prompt) { - return null; + Scanner scanner = new Scanner(System.in); + println(prompt); + Double userInput = Double.valueOf(scanner.nextLine()); + return userInput; } + } diff --git a/src/main/java/com/zipcodewilmington/scientificcalculator/LogFunctions.java b/src/main/java/com/zipcodewilmington/scientificcalculator/LogFunctions.java new file mode 100644 index 00000000..355b5941 --- /dev/null +++ b/src/main/java/com/zipcodewilmington/scientificcalculator/LogFunctions.java @@ -0,0 +1,20 @@ +package com.zipcodewilmington.scientificcalculator; + +public class LogFunctions { + public Double log(double num1) { + return Math.log10(num1); + } + + public Double inverseLog(double num1) { + return Math.pow(10, num1); + } + + public Double naturalLog(double num1) { + return Math.log(num1); + } + + public Double inverseNaturalLog(double num1) { + return Math.pow(2.71828182846, num1); + } +} + diff --git a/src/main/java/com/zipcodewilmington/scientificcalculator/MainApplication.java b/src/main/java/com/zipcodewilmington/scientificcalculator/MainApplication.java index 5f421325..bbe49bf1 100644 --- a/src/main/java/com/zipcodewilmington/scientificcalculator/MainApplication.java +++ b/src/main/java/com/zipcodewilmington/scientificcalculator/MainApplication.java @@ -4,14 +4,205 @@ * 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); + + Integer operation; + Integer choice; + Integer choice3 = 1; + String result; + Double num1 = 1.0; + Integer display = 4; + + + + SimpleMath simpleMath = new SimpleMath(); + LogFunctions logFunctions = new LogFunctions(); + ScientificFunctions scientificFunctions = new ScientificFunctions(); + SwitchDisplay switchDisplay = new SwitchDisplay(); + + Console.println("Welcome to my calculator!\n"); + + do { + Console.println("Please type one of the following options:\n" + + "1 = switchDisplay to change calculator to Binary, Octal, Decimal (normal), or Hexadecimal.\n" + + "2 = switchUnits to change between radians and degrees.\n" + + "3 = turn calculator off completely.\n" + + "4 = the calculator cause.... that's really what you need.\n"); + choice = Console.getIntegerInput("Enter the choice you would like to make."); + + if (choice == 1) { + Console.println("Pick one of the following please:\n"); + + do { + Console.println( "1 = Binary\n" + + "2 = Octal\n" + + "3 = Hex\n" + + "4 = Decimal\n"); + + display = Console.getIntegerInput("\n"); + + if (display != 1 && display != 2 && display != 3 && display != 4){ + Console.println("You have entered something incorrectly"); + } + + } while (display != 1 && display != 2 && display != 3 && display != 4); + + } else if (choice == 2) { + + Console.println("Pick one of the following please:\n"); + do { + Console.println( "1 = Radians\n" + + "2 = Degrees\n"); + choice3 = Console.getIntegerInput(""); + } while (choice3 != 1 && choice3 != 2); + + } else if (choice == 3) { + Console.println("SHUTTING DOOOWWNNNNNN!!!!!!"); + + } else if (choice == 4) { + Console.println("0 will exit you out of the Calculator!!!!\n" + + "1 for addition 2 for subtraction\n" + + "3 for multiplication 4 for division\n" + + "5 for squaring 6 for exponent\n" + + "7 for square root 8 for inverse\n" + + "9 for invert 10 for logarithms\n" + + "11 for natural logarithms 12 for inverse logarithms\n" + + "13 for inverse natural logarithms 14 for sine\n" + + "15 for cosine 16 for tangent\n" + + "17 for arcsine 18 for arccosine\n" + + "19 for arctangent 20 for factorial\n" + + "Any other number for HELLLPPPPPPP\n\n\n"); + + do { + + operation = Console.getIntegerInput("Enter the operation you would like to perform."); + if (operation != 0 ) { + num1 = Console.getDoubleInput("Enter your first number."); + } + + switch (operation) { + case 1: + Double num2 = Console.getDoubleInput("Enter your second number."); + result = switchDisplay.toDisplay(simpleMath.add(num1, num2), display); + System.out.println(num1 + " + " + num2 + " = " + result); + break; + case 2: + num2 = Console.getDoubleInput("Enter your second number."); + result = switchDisplay.toDisplay(simpleMath.subtract(num1, num2), display); + System.out.println(num1 + " - " + num2 + " = " + result); + break; + case 3: + num2 = Console.getDoubleInput("Enter your second number."); + result = switchDisplay.toDisplay(simpleMath.multiplication(num1, num2), display); + System.out.println(num1 + " x " + num2 + " = " + result); + break; + case 4: + num2 = Console.getDoubleInput("Enter your second number."); + if (num2 != 0) { + result = switchDisplay.toDisplay(simpleMath.division(num1, num2), display); + System.out.println(num1 + " / " + num2 + " = " + result); + } else { + System.out.println("ERrER EeRRrRROO--OOOrrRR!?!?!"); + } + break; + case 5: + result = switchDisplay.toDisplay(simpleMath.square(num1), display); + System.out.println(num1 + " squared is " + result); + break; + case 6: + num2 = Console.getDoubleInput("Enter your second number."); + result = switchDisplay.toDisplay(simpleMath.expo(num1, num2), display); + System.out.println(num1 + " to the power of " + num2 + " = " + result); + break; + case 7: + result = switchDisplay.toDisplay(simpleMath.squareRoot(num1), display); + System.out.println("The square root of " + num1 + " is " + result); + break; + case 8: + result = switchDisplay.toDisplay(simpleMath.inverse(num1), display); + if (num1 != 0) { + System.out.println("The inverse of " + num1 + " is " + result); + } else { + System.out.println("ERrER EeRRrRROO--OOOrrRR!?!?!"); + } + break; + case 9: + result = switchDisplay.toDisplay(simpleMath.invertSign(num1), display); + if (num1 != 0) { + System.out.println("The invert of " + num1 + " is " + result); + } else { + System.out.println("ERrER EeRRrRROO--OOOrrRR!?!?!"); + } + break; + case 10: + result = switchDisplay.toDisplay(logFunctions.log(num1), display); + System.out.println("The logarithm of " + num1 + " is " + result); + break; + case 11: + result = switchDisplay.toDisplay(logFunctions.naturalLog(num1), display); + System.out.println("The natural logarithm of " + num1 + " is " + result); + break; + case 12: + result = switchDisplay.toDisplay(logFunctions.inverseLog(num1), display); + System.out.println("The inverse logarithm of " + num1 + " is " + result); + break; + case 13: + result = switchDisplay.toDisplay(logFunctions.inverseNaturalLog(num1), display); + System.out.println("The inverse natural logarithm of " + num1 + " is " + result); + case 14: + result = switchDisplay.toDisplay(scientificFunctions.sin(scientificFunctions.switchUnits(num1, choice3)), display); + System.out.println("The sine of " + num1 + " is " + result); + break; + case 15: + result = switchDisplay.toDisplay(scientificFunctions.cos(scientificFunctions.switchUnits(num1, choice3)), display); + System.out.println("The cosine of " + num1 + " is " + result); + break; + case 16: + result = switchDisplay.toDisplay(scientificFunctions.tan(scientificFunctions.switchUnits(num1, choice3)), display); + System.out.println("The tangent of " + num1 + " is " + result); + break; + case 17: + result = switchDisplay.toDisplay(scientificFunctions.asin(scientificFunctions.switchUnits(num1, choice3)), display); + System.out.println("The arcsine of " + num1 + " is " + result); + break; + case 18: + result = switchDisplay.toDisplay(scientificFunctions.acos(scientificFunctions.switchUnits(num1, choice3)), display); + System.out.println("The arccosine of " + num1 + " is " + result); + break; + case 19: + result = switchDisplay.toDisplay(scientificFunctions.atan(scientificFunctions.switchUnits(num1, choice3)), display); + System.out.println("The arctangent of " + num1 + " is " + result); + break; + case 20: + result = switchDisplay.toDisplay(scientificFunctions.factorial(num1), display); + System.out.println("The factorial of " + num1 + " is " + result); + break; + default: + System.out.println("Your input was incorrect please type one of the following:\n" + + "0 will exit you out of the Calculator!!!!\n" + + "1 for addition 2 for subtraction\n" + + "3 for multiplication 4 for division\n" + + "5 for squaring 6 for exponent\n" + + "7 for square root 8 for inverse\n" + + "9 for invert 10 for logarithms\n" + + "11 for natural logarithms 12 for inverse logarithms\n" + + "13 for inverse natural logarithms 14 for sine\n" + + "15 for cosine 16 for tangent\n" + + "17 for arcsine 18 for arccosine\n" + + "19 for arctangent 20 for factorial\n" + + "Any other number for HELLLPPPPPPP\n\n\n"); + break; + } + + + } while (operation != 0); + } else { + choice = 5; + Console.println("SOMETHING WROOoNNNNNGGGGgggggg!!!!\n"); + } + } while (choice != 3); } + } + diff --git a/src/main/java/com/zipcodewilmington/scientificcalculator/ScientificFunctions.java b/src/main/java/com/zipcodewilmington/scientificcalculator/ScientificFunctions.java new file mode 100644 index 00000000..9d7ad6d2 --- /dev/null +++ b/src/main/java/com/zipcodewilmington/scientificcalculator/ScientificFunctions.java @@ -0,0 +1,52 @@ +package com.zipcodewilmington.scientificcalculator; +import java.lang.Math; +public class ScientificFunctions { + + public Boolean radians; + public Boolean degrees; + + public static double sin(double a) { + double b = Math.toRadians(a); + return(Math.sin(b)); + } + public static double cos(double a) { + double b = Math.toRadians(a); + return(Math.cos(b)); + } + public static double tan(double a) { + double b = Math.toRadians(a); + return(Math.tan(b)); + } + public static double asin(double a) { + a = Math.PI; + return(Math.asin(a)); + } + public static double acos(double a) { + a = Math.PI / 2; + a = Math.toRadians(a); + return(Math.acos(a)); + } + public static double atan(double a) { + a = Math.PI; + return(Math.atan(a)); + } + public static double factorial(double n) { + int res = 1, i; + for(i =2; i<=n; i++) + res *=i; + return res; + } + public static double toDegrees(double rad) { + return(Math.toDegrees(rad)); + } + + public double switchUnits (double num1, int setter) { + if (setter == 1) { + double num2 = toDegrees(num1); + return num2; + } else { + return num1; + } + } + +} \ No newline at end of file diff --git a/src/main/java/com/zipcodewilmington/scientificcalculator/SimpleMath.java b/src/main/java/com/zipcodewilmington/scientificcalculator/SimpleMath.java new file mode 100644 index 00000000..52e1e04d --- /dev/null +++ b/src/main/java/com/zipcodewilmington/scientificcalculator/SimpleMath.java @@ -0,0 +1,40 @@ +package com.zipcodewilmington.scientificcalculator; + +import static java.lang.Math.sqrt; + +public class SimpleMath { + + //Simple Operations + public Double add(double num1, double num2) { + return num1 + num2; + } + public Double subtract(double num1, double num2) { + return num1 - num2; + } + public Double multiplication(double num1, double num2){ + return num1 * num2; + } + public Double division(double num1, double num2){ + return num1 / num2; + } + + public Double square(double num1){ + return num1 * num1; + } + + public Double squareRoot(double num1){ + return Math.sqrt(num1); + } + + public Double expo(double num1, double num2){ + return Math.pow(num1, num2); + } + + public Double inverse(double num1){ + return 1 / num1; + } + + public Double invertSign(double num1){ + return num1 * -1; + } +} \ No newline at end of file diff --git a/src/main/java/com/zipcodewilmington/scientificcalculator/SwitchDisplay.java b/src/main/java/com/zipcodewilmington/scientificcalculator/SwitchDisplay.java new file mode 100644 index 00000000..8b6ce5c2 --- /dev/null +++ b/src/main/java/com/zipcodewilmington/scientificcalculator/SwitchDisplay.java @@ -0,0 +1,36 @@ +package com.zipcodewilmington.scientificcalculator; + +public class SwitchDisplay { + + public Boolean binary; + public Boolean octal; + public Boolean hex; + + public String toBinary(int num1){ + return Integer.toBinaryString(num1); + } + + public String toOctal(int num1){ + return Integer.toOctalString(num1); + } + + public String toHex(int num1){ + return Integer.toHexString(num1); + } + + public String toDisplay(double num1, int setter) { + + int num2 = (int) Math.round(num1); + if (setter == 1) { + return toBinary(num2); + } else if (setter == 2) { + return toOctal(num2); + } else if (setter == 3) { + return toHex(num2); + } else { + return String.valueOf(num1); + } + } +} + + diff --git a/src/test/java/com/zipcodewilmington/scientific_calculator/LogFunctionsTest.java b/src/test/java/com/zipcodewilmington/scientific_calculator/LogFunctionsTest.java new file mode 100644 index 00000000..338d62c9 --- /dev/null +++ b/src/test/java/com/zipcodewilmington/scientific_calculator/LogFunctionsTest.java @@ -0,0 +1,45 @@ +package com.zipcodewilmington.scientific_calculator; +import com.zipcodewilmington.scientificcalculator.LogFunctions; +import org.junit.Assert; + +public class LogFunctionsTest { + + @org.junit.Before + public void setUp() throws Exception { + } + @org.junit.After + public void tearDown() throws Exception{ + } + @org.junit.Test + public void testLogFunctionsLog(){ + LogFunctions log1 = new LogFunctions(); + Assert.assertEquals(0.7781512503836436, log1.log(6), 0.01); + Assert.assertEquals(1.65321251378, log1.log(45), 0.01); + Assert.assertEquals(-0.5376020021, log1.log(0.29), 0.01); + Assert.assertEquals(0.19865708695, log1.log(1.58), 0.01); + } + @org.junit.Test + public void testLogFunctionsInverseLog(){ + LogFunctions inverse1 = new LogFunctions(); + Assert.assertEquals(10000, inverse1.inverseLog(4), 0.01); + Assert.assertEquals(1.58489319246, inverse1.inverseLog(0.2), 0.01); + Assert.assertEquals(1.20226443462, inverse1.inverseLog(0.08), 0.01); + Assert.assertEquals(15.8489319246, inverse1.inverseLog(1.2), 0.01); + } + @org.junit.Test + public void testLogFunctionsNaturalLog() { + LogFunctions natLog1 = new LogFunctions(); + Assert.assertEquals(2.99573227355, natLog1.naturalLog(20), 0.01); + Assert.assertEquals(-1.38629436112, natLog1.naturalLog(0.25), 0.01); + Assert.assertEquals(1.5260563035, natLog1.naturalLog(4.6), 0.01); + Assert.assertEquals(-0.22314355131, natLog1.naturalLog(0.8), 0.01); + } + @org.junit.Test + public void testLogFunctionsInverseNaturalLog() { + LogFunctions invNatLog1 = new LogFunctions(); + Assert.assertEquals(1.10517091808, invNatLog1.inverseNaturalLog(0.1), 0.01); + Assert.assertEquals(1.34985880758, invNatLog1.inverseNaturalLog(0.3), 0.01); + Assert.assertEquals(1202604.28416, invNatLog1.inverseNaturalLog(14), 0.01); + Assert.assertEquals(11.0231763806, invNatLog1.inverseNaturalLog(2.4), 0.01); + } +} diff --git a/src/test/java/com/zipcodewilmington/scientific_calculator/TestScientificFunctions.java b/src/test/java/com/zipcodewilmington/scientific_calculator/TestScientificFunctions.java new file mode 100644 index 00000000..096973d1 --- /dev/null +++ b/src/test/java/com/zipcodewilmington/scientific_calculator/TestScientificFunctions.java @@ -0,0 +1,67 @@ +package com.zipcodewilmington.scientific_calculator; +import org.junit.Assert; +import com.zipcodewilmington.scientificcalculator.ScientificFunctions; +public class TestScientificFunctions { + @org.junit.Before + public void setup()throws Exception { + } + @org.junit.After + public void tearDown() throws Exception{ + } + @org.junit.Test + public void TestScientificFunctionsSin() { + ScientificFunctions sin1 = new ScientificFunctions(); + Assert.assertEquals(0.49, sin1.sin(30), 0.01); + Assert.assertEquals(0.71, sin1.sin(45), 0.01); + Assert.assertEquals(1.00, sin1.sin(90), 0.01); + } + @org.junit.Test + public void TestScientificFunctionsCos() { + ScientificFunctions cos1 = new ScientificFunctions(); + Assert.assertEquals(0.64, cos1.cos(50), 0.01); + Assert.assertEquals(0.99, cos1.cos(5), 0.01); + Assert.assertEquals(0.98, cos1.cos(10), 0.01); + } + @org.junit.Test + public void TestScientificFunctionsTan() { + ScientificFunctions tan1 = new ScientificFunctions(); + Assert.assertEquals(0.08, tan1.tan(5.00), 0.01); + Assert.assertEquals(0.17, tan1.tan(10.00), 0.01); + Assert.assertEquals(0.16, tan1.tan(9.00), 0.02); + } + @org.junit.Test + public void TestScientificFunctionsAsin() { + ScientificFunctions asin1 = new ScientificFunctions(); + Assert.assertEquals(1.57, Math.asin(1.00), 0.01); + Assert.assertEquals(-0.52, Math.asin(-0.50), 0.01); + Assert.assertEquals(0.52, Math.asin(0.50), 0.01); + } + @org.junit.Test + public void TestScientificFunctionsAcos() { + ScientificFunctions acos1 = new ScientificFunctions(); + Assert.assertEquals(1.54, acos1.acos(1), 0.01); + Assert.assertEquals(1.54, acos1.acos(-1), 0.01); + Assert.assertEquals(0.99, acos1.cos(-0.5), 0.01); + } + @org.junit.Test + public void TestScientificFunctionsAtan() { + ScientificFunctions atan1 = new ScientificFunctions(); + Assert.assertEquals(1.26, atan1.atan(1), 0.01); + Assert.assertEquals(1.26, atan1.atan(-1), 0.01); + Assert.assertEquals(1.26, atan1.atan(0), 0.01); + } + @org.junit.Test + public void TestScientificFunctionsConvert() { + ScientificFunctions toDegrees1 = new ScientificFunctions(); + Assert.assertEquals(57.29, toDegrees1.toDegrees(1), 0.01); + Assert.assertEquals(114.59, toDegrees1.toDegrees(2), 0.01); + Assert.assertEquals(171.88, toDegrees1.toDegrees(3), 0.01); + } + @org.junit.Test + public void TestFactorial() { + ScientificFunctions factorial1 = new ScientificFunctions(); + Assert.assertEquals(120, factorial1.factorial(5), 0.01); + Assert.assertEquals(6, factorial1.factorial(3), 0.01); + Assert.assertEquals(40320, factorial1.factorial(8), 0.01); + } +} \ No newline at end of file diff --git a/src/test/java/com/zipcodewilmington/scientific_calculator/TestSimpleMath.java b/src/test/java/com/zipcodewilmington/scientific_calculator/TestSimpleMath.java new file mode 100644 index 00000000..cf7e029f --- /dev/null +++ b/src/test/java/com/zipcodewilmington/scientific_calculator/TestSimpleMath.java @@ -0,0 +1,119 @@ +package com.zipcodewilmington.scientific_calculator; +import com.zipcodewilmington.scientificcalculator.SimpleMath; +import org.junit.Assert; + + +public class TestSimpleMath { + + @org.junit.Before + public void setUp() throws Exception { + } + + @org.junit.After + public void tearDown() throws Exception{ + + } + + @org.junit.Test + public void testSimpleMathAdd() { + + SimpleMath add1 = new SimpleMath(); + Assert.assertEquals(20, add1.add(10, 10), 0.00); + Assert.assertEquals(56.50, add1.add(20.25, 36.25), 0.00); + Assert.assertEquals(357, add1.add(206, 151), 0.00); + Assert.assertEquals(652.27, add1.add(563.25, 89.02), 0.00); + } + + @org.junit.Test + public void testSimpleMathSub(){ + + SimpleMath sub1 = new SimpleMath(); + Assert.assertEquals(15, sub1.subtract(20, 5), 0.00); + Assert.assertEquals(378, sub1.subtract(456, 78), 0.00); + Assert.assertEquals(55.64, sub1.subtract(89.67, 34.03), 0.00); + Assert.assertEquals(28, sub1.subtract(37,9), 0.00); + + } + + @org.junit.Test + public void testSimpleMathMul(){ + + SimpleMath mul1 = new SimpleMath(); + Assert.assertEquals(81, mul1.multiplication(9,9), 0.00); + Assert.assertEquals(150.4, mul1.multiplication(37.6,4), 0.00); + Assert.assertEquals(120, mul1.multiplication(30,4), 0.00); + Assert.assertEquals(950, mul1.multiplication(100,9.5), 0.00); + + } + + @org.junit.Test + public void testSimpleMathDiv(){ + + SimpleMath div1 = new SimpleMath(); + Assert.assertEquals(125, div1.division(250, 2), 0.00); + Assert.assertEquals(14.383333333333333, div1.division(86.3, 6), 0.00); + Assert.assertEquals(18.666666666666668, div1.division(56, 3), 0.00); + Assert.assertEquals(3, div1.division(21, 7), 0.00); + + } + + + @org.junit.Test + public void testSimpleMathSq() { + + SimpleMath square1 = new SimpleMath(); + Assert.assertEquals(4, square1.square(2), 0.00); + Assert.assertEquals(625, square1.square(25), 0.00); + Assert.assertEquals(529, square1.square(23), 0.00); + Assert.assertEquals(90.25, square1.square(9.5), 0.00); + + } + + @org.junit.Test + public void testSimpleMathSqRt() { + + SimpleMath sqRoot1 = new SimpleMath(); + Assert.assertEquals(7, sqRoot1.squareRoot(49), 0.00); + Assert.assertEquals(4.878524367060187, sqRoot1.squareRoot(23.8), 0.00); + Assert.assertEquals(10.099504938362077, sqRoot1.squareRoot(102), 0.00); + Assert.assertEquals(1.449137674618944, sqRoot1.squareRoot(2.1), 0.00); + } + + @org.junit.Test + public void testSimpleMathExpo() { + + SimpleMath expo1 = new SimpleMath(); + Assert.assertEquals(1000, expo1.expo(10, 3), 0.00); + Assert.assertEquals(97.65625, expo1.expo(2.5, 5), 0.00); + Assert.assertEquals(64, expo1.expo(2, 6), 0.00); + Assert.assertEquals(300.76300000000003, expo1.expo(6.7, 3), 0.00); + } + + @org.junit.Test + public void testSimpleMathInverse() { + + SimpleMath inverse1 = new SimpleMath(); + Assert.assertEquals(0.125, inverse1.inverse(8), 0.00); + Assert.assertEquals(0.16129032258064516, inverse1.inverse(6.2), 0.00); + Assert.assertEquals(0.043478260869565216, inverse1.inverse(23), 0.00); + Assert.assertEquals(0.998003992015968, inverse1.inverse(1.002), 0.00); + } + + @org.junit.Test + public void testSimpleMathInvertSign() { + + SimpleMath sign1 = new SimpleMath(); + Assert.assertEquals(- 9, sign1.invertSign(9), 0.00); + Assert.assertEquals(56, sign1.invertSign(- 56), 0.00); + Assert.assertEquals(- 123.34, sign1.invertSign(123.34), 0.00); + Assert.assertEquals(34.02, sign1.invertSign(- 34.02), 0.00); + + } + + + +} + + + + diff --git a/src/test/java/com/zipcodewilmington/scientific_calculator/TestSwitchDisplay.java b/src/test/java/com/zipcodewilmington/scientific_calculator/TestSwitchDisplay.java new file mode 100644 index 00000000..59b723f9 --- /dev/null +++ b/src/test/java/com/zipcodewilmington/scientific_calculator/TestSwitchDisplay.java @@ -0,0 +1,54 @@ +package com.zipcodewilmington.scientific_calculator; + + +import com.zipcodewilmington.scientificcalculator.SwitchDisplay; +import org.junit.Assert; + +public class TestSwitchDisplay { + + @org.junit.Before + public void setUp() throws Exception { + } + + @org.junit.After + public void tearDown() throws Exception{ + + } + + + @org.junit.Test + public void testSwitchDisplayBinary(){ + + SwitchDisplay binary1 = new SwitchDisplay(); + Assert.assertEquals("10111", binary1.toBinary(23)); + Assert.assertEquals("1000110111", binary1.toBinary(567)); + Assert.assertEquals("10001100101000", binary1.toBinary(9000)); + Assert.assertEquals("1001001", binary1.toBinary(73)); + + } + + @org.junit.Test + public void testSwitchDisplayOctal(){ + + SwitchDisplay octal1 = new SwitchDisplay(); + Assert.assertEquals("27", octal1.toOctal(23)); + Assert.assertEquals("173", octal1.toOctal(123)); + Assert.assertEquals("1067", octal1.toOctal(567)); + Assert.assertEquals("21460", octal1.toOctal(9008)); + + + } + + @org.junit.Test + public void testSwitchDisplayHex(){ + + SwitchDisplay hex1 = new SwitchDisplay(); + Assert.assertEquals("17", hex1.toHex(23)); + Assert.assertEquals("1cb", hex1.toHex(459)); + Assert.assertEquals("30c", hex1.toHex(780)); + Assert.assertEquals("2d", hex1.toHex(45)); + } + +} + +