Use group discussion to help students figure out boundary cases for removing duplicate adjacent elements on their own so that they get to discuss a variety of test cases in depth before focusing on the code.

  • This is a great way to introduce or reinforce test-driven development (TDD).
  • Ask students to discuss writing a method to “remove duplicates” from the array [2, 3, 55, 3, 3, 16, 16].
    • Without further prompting, students will likely devise an algorithm that only removes the duplicates in the middle or the end of the array.
  • Next, encourage students figure out all the test/boundary cases removing duplicate adjacent elements.
    • Have students create a table to keep track of all their test cases like the table at the bottom of this tip.
      • Students should keep track of their thinking in tabular form to encourage the correct use of test cases.
        • Students will be tracking their progress as they successfully remove more and more duplicate elements from the array.
      • Students will either have to trace through all algorithms by hand, or program them and run them as a group.
      • The table should include the following four columns:
        • Contents of the test array initially.
        • Contents of the test array after duplicates are removed.
        • Information about the test case.
        • Information about the array that remains.
    • If students get stuck or too overwhelmed give them a hint that there are 8 test cases they need to account for.
      • The eight test cases (i.e., boundary conditions) students need to consider are as follows:
        • Ending with a non-duplicate
        • Starting with a duplicate
        • Duplicates only in the middle
        • A array of one element
        • A longer array with all duplicates
        • A longer array with no duplicates
        • An empty array
          • A null array is not possible.
        • A single element between sequences of duplicates.
          • For example, the array [2, 3, 55, 3, 3, 16, 16, 16] is an array with duplicates at the end and in the middle.
    • Collect a list of wrong answers and wrong test cases, to use for introducing debugging.
    • Below is the beginning of a sample table students will create:
      Initial Test Array Contents of Test Array after Duplicates are Removed Information about Test Case Information about the Remaining Array
      [2, 3, 55, 3, 3, 16, 16, 16] [2, 3, 55, 3, 3, 16] The code written for this test case removed the duplicates the end of the array. 1 boundary case identified. There are still duplicates to remove in other parts of the array.
      [2, 3, 55, 3, 3, 16]