Test-Driven Experiment

  1. Create a directory called "test" to house your unit tests
  2. Download the unit test template file to the "test" directory
  3. Create a directory called "lib" to house your binary search code
  4. Code up your tests and binary search function

    Binary search specification:
    Implement binary search in a function called binary_search that takes a sorted array as a parameter and a value. If the value occurs in the array, return the index at which it occurs in the array (if multiple occur, any index is fine). If it does not occur, return nil. You may assume that the value and the entries in the array support the comparison operators.

    You should time how long each part takes you (writing tests and writing the function) regardless of which order you've been asked to do it. To do this, write down what time it is each time you start/end a new task.

    Recall that to run unit tests in this framework you type:
    ruby -I lib test/test_binary_search.rb
    (assuming you're in the base directory)
  5. When you're done coding, go up to the board and record your times.
  6. Download the test script. Record on the chalkboard whether or not you passed all of the tests.