Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Create a class called InfixExpressionEvaluator in Java. Methods must pass test cases. Thanks! import static org.junit.Assert.*; import org.junit.FixMethodorder; import org.junit.Test; import org.junit.runners.MethodSorters; @FixHethodOrder (MethodSorters.NAME_ASCENDING) public

Create a class called InfixExpressionEvaluator in Java. Methods must pass test cases. Thanks!

image text in transcribedimage text in transcribedimage text in transcribedimage text in transcribed

import static org.junit.Assert.*; import org.junit.FixMethodorder; import org.junit.Test; import org.junit.runners.MethodSorters; @FixHethodOrder (MethodSorters.NAME_ASCENDING) public class InfixExpressionEvaluatorTest f @Test public void aSimpleAddTest) { int[] variableValues[0,0,0,0,0,0; String input -"3 + 3"; double actual InfixExpressionEvaluator.evaluateInfix(input,variableValues); double expected6.0; assertEquals("When given the input string 3 3 we",expected,actual, .0001); @Test public void aSimpleSubtractTest) f int[] variableValues[0,0,0,0,0,0; String input "4 - 5"; double actual- InfixExpressionEvaluator.evaluateInfix(input,variableValues); double expected-1.0; assertEquals("When given the input string 4 - 5 we",expected,actual,.0001); @Test public void aSimpleMultTest) int[] variableValueso,0,0,0,0,0 String input "6 * 3"; double actual InfixExpressionEvaluator.evaluateInfix(input,variableValues); double expected- 18.0 assertEquals("When given the input string 6 3 we",expected,actual,.0001); @Test public void aSimpleDivideTest) int[] variableValueso,0,0,0,0,0 String input -"7/ 3"; double actual-InfixExpressionEvaluator.evaluateInfix(input,variableValues); double expected-2.33333; assertEquals("When given the input string 7/ 3 we",expected,actual,.0001); @Test public void aSimpleExponentTest() { int[] variableValues[0,0,0,0,0,0; String input"2 A 8"; double actual InfixExpressionEvaluator.evaluateInfix(input,variableValues); double expected256.0; assertEquals("When given the input string 28 we",expected,actual, .0001); @Test public void multipleExpressionTest) i int[] variableValueso,0,0,0,0,0 String input -"3+ 3 * 4"; double actual InfixExpressionEvaluator.evaluateInfix(input,variableValues); double expected15.0; assertEquals("When given the input string 33 *4 we",expected,actual,.0001); @Test public void multipleExpressionTest2) int [ ] variableValues {0,0,0,0,0,0); String input ''9 / 3-4"; double actual InfixExpressionEvaluator.evaluateInfix(input,variableValues); double expected1.0 assertEquals("When given the input string 9/3 - 4 we",expected,actual,.0001); @Test public void parenthesesTest) int[] variableValues[0,0,0,0,0,0; String input = "( 10-4 ) * 3"; double actual- InfixExpressionEvaluator.evaluateInfix(input,variableValues); double expected 18.0; assertEquals("When given the input string (10-4) * 3 we",expected, actual, .0001); @Test public void parenthesesTest2) t int[] variableValueso,0,0,0,0,0 String input -"11 / (2 + 4 )" double actual = InfixExpressionEvaluator .evaluateInfix(input,variableValues); double expected 1.8333333; assertEquals("When given the input string 11/ (2 + 4) we",expected,actual,.e001); @Test public void parenthesesTest3) t int[] variableValueso,0,0,0,0,0 string input ( 2 + 2 )"; double actual-InfixExpressionEvaluator.evaluateInfix(input,variableValues); double expected4.0; assertEquals("When given the input string (2 +2) we",expected,actual,.0001); @Test public void parenthesesTest4Complex() int [ ] variableValues {0,0,0,0,0,0); String input"3 4*4)/ 8 )"; double actual InfixExpressionEvaluator.evaluateInfix(input,variableValues); double expected9.0; assertEquals("When given the input string 3 4*4)/ 8) we"expected,actual, .0001); @Test public void variableTestSubtract() { int[] variableValues -121,50,0,0,0,0}; string input a b"; double actual InfixExpressionEvaluator.evaluateInfix(input,variableValues); double expected -29.0; assertEquals("When given the input string a - b where a 21 and b 50 we",expected , actual, .0001); @Test public void variableTestDivide)f int[] variableValues[0,0,10,25,0,0}; String input"c/ d"; double actual InfixExpressionEvaluator.evaluateInfix(input,variableValues); double expected0.4; assertEquals("When given the input string c / d where c = 10 and d 2! we",expected , actual, .0001); @Test public void variableTestExponent) f int[] variableValues[0,0,0,0,3,4; String input"e f"; double actual- InfixExpressionEvaluator.evaluateInfix(input,variableValues); double expected = 81.0; assertEquals("When given the input string e ^ f where e 3 and f 4 we " , expected , actual, .0001); @Test public void variableTestCapitalization1) { int[] variableValues {4,2,0,0,0,0); String input -"A+ a * B"; double actual InfixExpressionEvaluator.evaluateInfix(input,variableValues); double expected- 12.0 assertEquals("When given the input string A + a * B where a 4 and b 2 we " , expected , actual, .0001); @Test public void variableTestCapitalization2) f int[] variableValues[0,0,10,0,6,18}; String input -"f/E - c; double actual InfixExpressionEvaluator.evaluateInfix(input,variableValues); double expected7.0; assertEquals("When given the input string f / E - c where c 10, e 6 and f 18 we",expected,actual, .0001); @Test public void variableTestParentheses) int[] variableValues2,0,18,0,0,0 String input"C 4) * a"; double actual InfixExpressionEvaluator.evaluateInfix(input,variableValues); double expected28.0 assertEquals("When given the input string ( C -4 ) * a where c 18 and a 2 we " , expected,actual, .0001); Test public void variableTestParentheses2) int] variableValues ,0,8,0,0,4); String input"ftf" double actlInfixExpressionEvaluator.evaluateInfix(input,variableValues); double expected-8.0 assertEquals("When given the input string ( f + f ) where f = 4 we",expected,actual, .0001); Test public void variableTestParentheses3 nt variableValuese,4,8,0,4,0; String input 3EE)/ b ); double actual InfixExpressionEvaluator.evaluateInfix(input,variableValues); double expected -81.8; assertEquals("When given the input string 3AE E)b) where b 4 and e-4 we",expected,actual,.e01) est public void variableTestGarbageVariableData) f intl] variableValues (180,4,32,5,6,8]; String input3 AEEb ); double actual InfixExpressionEvaluator.evaluateInfix(input,variableValues); double expected 19683.e; assertEquals("When given the input string 3 ^ ( ( E * E )b ) where b . 4 and e . 6 we , expected, actual, .0001); Test public void variableTestcomplex() f int] variableValues 2,8,32,156,8,20 String input"a (bci(d -ef)) 1e ) double actlInfixExpressionEvaluator.evaluateInfix(input,variableValues); double expected 14.8; assertEquals("ihen given the input string ( a ^ ( ( b * c ) / ( d- ( e + f ) ) ) + 10 ) where a 2, b 8, c 32, d 156, e 8 and f 2e we'' , expected , actual, .0001); Test(expected-IllegalStateException.class) // Testing start position greater than end position public void parenthesesSingleopenTest) int variableValues ,0,0,0,8,0) String input"(A2; InfixExpressionEvaluator.evaluateInfix(input,variableValues); Test(expected IllegalStateException.class) I/ Testing start position greater than end position public void parenthesesSingleClosedTest)f inti] variableValues (e,8,0,0,8,0); String input"A 2 ); InfixExpressionEvaluator.evaluateInfix(input,variableValues); gTest(expected IllegalstateException.class) I/ Testing start position greater than end position public void parenthesesUnbalancedopenTest) int variableValues-e,8,0,0,0,0; String input -"A 2) )"; InfixExpressionEvaluator.evaluateInfix(input,variableValues)

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access with AI-Powered Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Students also viewed these Databases questions