Week 8: Oct 15 TechSupport: String.split() and what is really going on Searching an array A for number x: i = 0; while (i all software has bugs bug[2] -> that's not a bug, it's a feature! bug[3] -> have you filed a bug report about that? What would it take to match two-word pairs, in order? (what,best) represents "what is the best way to ..." (what,wrong) represents "what is wrong with you?" (what,do) represents "what do I do now" Using docs to find the String methods we need. * skip leading spaces * just check for match with "bye" * ignore case Details of HashMap class, and its methods put(k,v) and get(k) MapTester demo go through demo use Inspector to find the collision! do examples on page (2nd ed: 131): how interface works use javadocs Logic of trying group1 words before group2 (question) words More elaborate logic for multiple tests ======================================================= Quick demo of balls private static final int gravity = 3; ================================================================================= ================================================================================= Wed, Oct 17 Chapter 6: Testing Diary example: overview concept of "Regression Testing": apply old test to each new version Test program Problem: how do we interpret the results?? JUnit testing: Create a new test in a copy of the Diary v2 example have it create a day, and two new appointments, and test some things JUnit testing doesn't work as well for simulating interactive input! Skip the calculator for now ======================================================================= ======================================================================= Fri, Oct 19 How to test generateResponse(ArrayList sentence)?? 1. sometimes you *do* have to write manual test code. BlueJ adds the Object Bench, but some objects (like ArrayLists) can't be created there. 2. Write (in the responseTest test class) a method testSentence() that returns a sentence. Then, using the test-recording feature of bluej, run a test on generateResponse() and as parameter supply responseTest.testSentence(); 3. JUnit supports the concept of a "Fixture"; a set of objects needed for tests. 4. Even if manual creation is necessary, automated run & interpret are still powerful. MAYBE: Take a quick look at finding problems with bricks example. Tools: inspector println (and if(DEBUG) {...}) debugger walkthroughs (manual) Testing: manual tests test methods JUnit testing Bricks test: check height, weight for 1 brick, 10 bricks 0 bricks? problem with height! Weight: 3 kg/brick BASE_WEIGHT not included?? Is weight of a brick even right? Use DEBUGGER to find problem with height: put a breakpoint at height method ====================================================== Chapter 7: World of Zuul Code duplication: avoid Coupling: minimize ("loose coupling") Responsibility-driven design localizing change cohesion refactoring Why do we care about these principles? Demo of Zuul Bad version of Zuul, then good version. Discuss differences. Goals: Loose COUPLING COHESION: a class should represent one thing; each method should do one thing non-cohesive: Iterator.next() returns current item & moves on. but this is probably ok Zuul-bad problems: 1. Public data fields in Room: VERY bad coupling 2. poor cohesion in goRoom(), printWelcome() 3. Code duplication in goRoom(), printWelcome()!!! End of class: fixed #1 by adding an accessor getNorth(), and making northRoom private, but that still leaves us a mess when it comes time to adding new directions ============