From 27e7cf18d35a1dc2c8ad2acf9a77b2799d884a43 Mon Sep 17 00:00:00 2001 From: Haidong Ji Date: Fri, 28 Dec 2018 14:58:39 -0600 Subject: Max exp value with paren done! Wow, translating the algo into code was tricky! Debugging was challenging, frustrating, and ultimately rewarding. Two debugging takeaways I can think of now: 1. Make the test case small, so it's easy to trace the whole thing through; 2. For bigger test case, the example from lecture notes was helpful. I just needed to set breakpoint intelligently to see the min and max arrays. Also, initializing the min and max value, then use the Math.min and Math.max was interesting. I may need to remember that, that's why I have the notes here!--- .../tests/PlacingParenTest.java | 35 ++++++++++++++++++++++ 1 file changed, 35 insertions(+) create mode 100644 AlgoDesignAndTechniqueEdxJava/tests/PlacingParenTest.java (limited to 'AlgoDesignAndTechniqueEdxJava/tests/PlacingParenTest.java') diff --git a/AlgoDesignAndTechniqueEdxJava/tests/PlacingParenTest.java b/AlgoDesignAndTechniqueEdxJava/tests/PlacingParenTest.java new file mode 100644 index 0000000..91885e9 --- /dev/null +++ b/AlgoDesignAndTechniqueEdxJava/tests/PlacingParenTest.java @@ -0,0 +1,35 @@ +import static org.junit.jupiter.api.Assertions.*; + +import org.junit.jupiter.api.Test; + +class PlacingParenTest { + + @Test + void test() { + String exp = "1+5"; + assertEquals(6, PlacingParen.getMaxValue(exp)); + ; + } + + @Test + void test1() { + String exp = "5-8+7*4-8+9"; + assertEquals(200, PlacingParen.getMaxValue(exp)); + ; + } + + @Test + void test2() { + String exp = "1+2-3*4-5"; + assertEquals(6, PlacingParen.getMaxValue(exp)); + ; + } + + @Test + void test3() { + String exp = "1+2*3"; + assertEquals(9, PlacingParen.getMaxValue(exp)); + ; + } + +} -- cgit v1.2.3