tdd/lab-workbook.rst
changeset 130 e5d183dce985
parent 129 6e237b9442cd
equal deleted inserted replaced
129:6e237b9442cd 130:e5d183dce985
     7 
     7 
     8 Lab - 1
     8 Lab - 1
     9 =======
     9 =======
    10 
    10 
    11   1. Write a stub function for calculating the LCM of two numbers.
    11   1. Write a stub function for calculating the LCM of two numbers.
       
    12                                                             - U-level
    12   2. Write the tests for the LCM function, place the tests in if
    13   2. Write the tests for the LCM function, place the tests in if
    13      __name__ == '__main__': part of the Python file. Demonstrate that
    14      __name__ == '__main__': part of the Python file. Demonstrate that
    14      the tests fail.
    15      the tests fail.                                        - U-level
    15   3. Implement the code for the LCM function, using the gcd function
    16   3. Implement the code for the LCM function, using the gcd function
    16      provided in the examples in the chapter. Demonstrate the tests
    17      provided in the examples in the chapter. Demonstrate the tests
    17      pass. (For the algorithm refer to Wikipedia - [0])
    18      pass. (For the algorithm refer to Wikipedia - [0])     - Ap-level
    18   4. Alternatively, build a set of test cases, preferably a large
    19   4. Alternatively, build a set of test cases, preferably a large
    19      number of cases, place it in a text file and use these test cases
    20      number of cases, place it in a text file and use these test cases
    20      to test your LCM function. Demonstrate that tests still continue
    21      to test your LCM function. Demonstrate that tests still continue
    21      to pass.
    22      to pass.                                               - U-level
    22 
    23 
    23 [0] - http://en.wikipedia.org/wiki/Least_common_multiple#Reduction_by_the_greatest_common_divisor
    24 [0] - http://en.wikipedia.org/wiki/Least_common_multiple#Reduction_by_the_greatest_common_divisor
    24 
    25 
    25 Lab - 2
    26 Lab - 2
    26 =======
    27 =======
    29      failed tests), in turn followed by the code(demonstrating the
    30      failed tests), in turn followed by the code(demonstrating the
    30      passing tests) to calculate the number of days between two
    31      passing tests) to calculate the number of days between two
    31      dates. Name your function num_of_days(). The function should take
    32      dates. Name your function num_of_days(). The function should take
    32      two arguments, both being tuples. Each tuple represents the date
    33      two arguments, both being tuples. Each tuple represents the date
    33      in the format of (dd, mm, yyyy) where dd, mm and yyyy are
    34      in the format of (dd, mm, yyyy) where dd, mm and yyyy are
    34      integers.
    35      integers.                                              - Ap-level
       
    36 
    35   2. Rewrite the num_of_days() function to take the start date as an
    37   2. Rewrite the num_of_days() function to take the start date as an
    36      optional argument. If the start date is not specified calculate
    38      optional argument. If the start date is not specified calculate
    37      the number of days between the only specified date since Unix
    39      the number of days between the only specified date since Unix
    38      epoch. Prior to manipulating the code to do this, make sure you
    40      epoch. Prior to manipulating the code to do this, make sure you
    39      change the tests, make them fail and then refactor the code.
    41      change the tests, make them fail and then refactor the code.
       
    42                                                             - Ap-level
    40 
    43 
    41 
    44 
    42 Lab -3
    45 Lab -3
    43 ======
    46 ======
    44 
    47 
    45   1. Move the tests that were written to GCD function in the examples
    48   1. Move the tests that were written to GCD function in the examples
    46      of this chapter to a separate function called test_gcd(). Do the
    49      of this chapter to a separate function called test_gcd(). Do the
    47      same for LCM function and num_of_days() function. Make sure when
    50      same for LCM function and num_of_days() function. Make sure when
    48      the respective Python files are executed as stand alone scripts
    51      the respective Python files are executed as stand alone scripts
    49      these tests executed.
    52      these tests executed.                                  - U-level
    50   2. Put all these files in a single directory called utils and run
    53   2. Put all these files in a single directory called utils and run
    51      the nosetests command. Make a report of the results.
    54      the nosetests command. Make a report of the results.   - U-level
    52   3. Write doctests to each of the above functions. Demonstrate and
    55   3. Write doctests to each of the above functions. Demonstrate and
    53      report the results as executed by running the doctests using
    56      report the results as executed by running the doctests using
    54      doctest.testmod() function and using nosetests command.
    57      doctest.testmod() function and using nosetests command. -Ap-level
    55 
    58 
    56 Lab - 4
    59 Lab - 4
    57 =======
    60 =======
    58 
    61 
    59   1. Consider the following use case: We are given a large list of
    62   1. Consider the following use case: We are given a large list of
   138 
   141 
   139                del self.test_names
   142                del self.test_names
   140                del self.data_len
   143                del self.data_len
   141 
   144 
   142      Fix the bug, run the tests to make sure the function passes the
   145      Fix the bug, run the tests to make sure the function passes the
   143      tests and if possible refactor the code with a better approach.
   146      tests and if possible refactor the code with a better approach. - An-level