tdd/lab-workbook.rst
author Puneeth Chaganti <punchagan@fossee.in>
Mon, 31 Jan 2011 12:48:45 +0530
changeset 150 8526f94072f6
parent 130 e5d183dce985
permissions -rw-r--r--
vcs: Add include directive for exercises in handOut.
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
126
b9c6563869ef First Lab exercise questions. Sorry for very small commits. I paid the penalty of losing my entire file on which I had worked on 1 and half days.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
     1
======================================
b9c6563869ef First Lab exercise questions. Sorry for very small commits. I paid the penalty of losing my entire file on which I had worked on 1 and half days.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
     2
Lab Workbook - Test Driven Development
b9c6563869ef First Lab exercise questions. Sorry for very small commits. I paid the penalty of losing my entire file on which I had worked on 1 and half days.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
     3
======================================
b9c6563869ef First Lab exercise questions. Sorry for very small commits. I paid the penalty of losing my entire file on which I had worked on 1 and half days.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
     4
b9c6563869ef First Lab exercise questions. Sorry for very small commits. I paid the penalty of losing my entire file on which I had worked on 1 and half days.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
     5
The notation that follows every question denotes the level on the
b9c6563869ef First Lab exercise questions. Sorry for very small commits. I paid the penalty of losing my entire file on which I had worked on 1 and half days.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
     6
Revised Bloom's Taxonomy.
b9c6563869ef First Lab exercise questions. Sorry for very small commits. I paid the penalty of losing my entire file on which I had worked on 1 and half days.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
     7
b9c6563869ef First Lab exercise questions. Sorry for very small commits. I paid the penalty of losing my entire file on which I had worked on 1 and half days.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
     8
Lab - 1
b9c6563869ef First Lab exercise questions. Sorry for very small commits. I paid the penalty of losing my entire file on which I had worked on 1 and half days.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
     9
=======
b9c6563869ef First Lab exercise questions. Sorry for very small commits. I paid the penalty of losing my entire file on which I had worked on 1 and half days.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    10
b9c6563869ef First Lab exercise questions. Sorry for very small commits. I paid the penalty of losing my entire file on which I had worked on 1 and half days.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    11
  1. Write a stub function for calculating the LCM of two numbers.
130
e5d183dce985 RBT Levels to the questions.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 129
diff changeset
    12
                                                            - U-level
126
b9c6563869ef First Lab exercise questions. Sorry for very small commits. I paid the penalty of losing my entire file on which I had worked on 1 and half days.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    13
  2. Write the tests for the LCM function, place the tests in if
b9c6563869ef First Lab exercise questions. Sorry for very small commits. I paid the penalty of losing my entire file on which I had worked on 1 and half days.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    14
     __name__ == '__main__': part of the Python file. Demonstrate that
130
e5d183dce985 RBT Levels to the questions.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 129
diff changeset
    15
     the tests fail.                                        - U-level
126
b9c6563869ef First Lab exercise questions. Sorry for very small commits. I paid the penalty of losing my entire file on which I had worked on 1 and half days.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    16
  3. Implement the code for the LCM function, using the gcd function
b9c6563869ef First Lab exercise questions. Sorry for very small commits. I paid the penalty of losing my entire file on which I had worked on 1 and half days.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    17
     provided in the examples in the chapter. Demonstrate the tests
130
e5d183dce985 RBT Levels to the questions.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 129
diff changeset
    18
     pass. (For the algorithm refer to Wikipedia - [0])     - Ap-level
126
b9c6563869ef First Lab exercise questions. Sorry for very small commits. I paid the penalty of losing my entire file on which I had worked on 1 and half days.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    19
  4. Alternatively, build a set of test cases, preferably a large
b9c6563869ef First Lab exercise questions. Sorry for very small commits. I paid the penalty of losing my entire file on which I had worked on 1 and half days.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    20
     number of cases, place it in a text file and use these test cases
b9c6563869ef First Lab exercise questions. Sorry for very small commits. I paid the penalty of losing my entire file on which I had worked on 1 and half days.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    21
     to test your LCM function. Demonstrate that tests still continue
130
e5d183dce985 RBT Levels to the questions.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 129
diff changeset
    22
     to pass.                                               - U-level
126
b9c6563869ef First Lab exercise questions. Sorry for very small commits. I paid the penalty of losing my entire file on which I had worked on 1 and half days.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    23
b9c6563869ef First Lab exercise questions. Sorry for very small commits. I paid the penalty of losing my entire file on which I had worked on 1 and half days.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    24
[0] - http://en.wikipedia.org/wiki/Least_common_multiple#Reduction_by_the_greatest_common_divisor
b9c6563869ef First Lab exercise questions. Sorry for very small commits. I paid the penalty of losing my entire file on which I had worked on 1 and half days.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    25
b9c6563869ef First Lab exercise questions. Sorry for very small commits. I paid the penalty of losing my entire file on which I had worked on 1 and half days.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    26
Lab - 2
b9c6563869ef First Lab exercise questions. Sorry for very small commits. I paid the penalty of losing my entire file on which I had worked on 1 and half days.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    27
=======
b9c6563869ef First Lab exercise questions. Sorry for very small commits. I paid the penalty of losing my entire file on which I had worked on 1 and half days.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    28
127
f65aec952da7 Add second lab exercise questions.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 126
diff changeset
    29
  1. Write the stub function, followed by the tests(demonstrating the
f65aec952da7 Add second lab exercise questions.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 126
diff changeset
    30
     failed tests), in turn followed by the code(demonstrating the
f65aec952da7 Add second lab exercise questions.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 126
diff changeset
    31
     passing tests) to calculate the number of days between two
f65aec952da7 Add second lab exercise questions.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 126
diff changeset
    32
     dates. Name your function num_of_days(). The function should take
f65aec952da7 Add second lab exercise questions.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 126
diff changeset
    33
     two arguments, both being tuples. Each tuple represents the date
f65aec952da7 Add second lab exercise questions.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 126
diff changeset
    34
     in the format of (dd, mm, yyyy) where dd, mm and yyyy are
130
e5d183dce985 RBT Levels to the questions.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 129
diff changeset
    35
     integers.                                              - Ap-level
e5d183dce985 RBT Levels to the questions.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 129
diff changeset
    36
127
f65aec952da7 Add second lab exercise questions.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 126
diff changeset
    37
  2. Rewrite the num_of_days() function to take the start date as an
f65aec952da7 Add second lab exercise questions.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 126
diff changeset
    38
     optional argument. If the start date is not specified calculate
f65aec952da7 Add second lab exercise questions.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 126
diff changeset
    39
     the number of days between the only specified date since Unix
f65aec952da7 Add second lab exercise questions.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 126
diff changeset
    40
     epoch. Prior to manipulating the code to do this, make sure you
f65aec952da7 Add second lab exercise questions.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 126
diff changeset
    41
     change the tests, make them fail and then refactor the code.
130
e5d183dce985 RBT Levels to the questions.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 129
diff changeset
    42
                                                            - Ap-level
126
b9c6563869ef First Lab exercise questions. Sorry for very small commits. I paid the penalty of losing my entire file on which I had worked on 1 and half days.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    43
b9c6563869ef First Lab exercise questions. Sorry for very small commits. I paid the penalty of losing my entire file on which I had worked on 1 and half days.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    44
b9c6563869ef First Lab exercise questions. Sorry for very small commits. I paid the penalty of losing my entire file on which I had worked on 1 and half days.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    45
Lab -3
b9c6563869ef First Lab exercise questions. Sorry for very small commits. I paid the penalty of losing my entire file on which I had worked on 1 and half days.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    46
======
b9c6563869ef First Lab exercise questions. Sorry for very small commits. I paid the penalty of losing my entire file on which I had worked on 1 and half days.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    47
128
29e6b1d5e5f5 Add third lab exercise questions.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 127
diff changeset
    48
  1. Move the tests that were written to GCD function in the examples
29e6b1d5e5f5 Add third lab exercise questions.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 127
diff changeset
    49
     of this chapter to a separate function called test_gcd(). Do the
29e6b1d5e5f5 Add third lab exercise questions.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 127
diff changeset
    50
     same for LCM function and num_of_days() function. Make sure when
29e6b1d5e5f5 Add third lab exercise questions.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 127
diff changeset
    51
     the respective Python files are executed as stand alone scripts
130
e5d183dce985 RBT Levels to the questions.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 129
diff changeset
    52
     these tests executed.                                  - U-level
128
29e6b1d5e5f5 Add third lab exercise questions.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 127
diff changeset
    53
  2. Put all these files in a single directory called utils and run
130
e5d183dce985 RBT Levels to the questions.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 129
diff changeset
    54
     the nosetests command. Make a report of the results.   - U-level
128
29e6b1d5e5f5 Add third lab exercise questions.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 127
diff changeset
    55
  3. Write doctests to each of the above functions. Demonstrate and
29e6b1d5e5f5 Add third lab exercise questions.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 127
diff changeset
    56
     report the results as executed by running the doctests using
130
e5d183dce985 RBT Levels to the questions.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 129
diff changeset
    57
     doctest.testmod() function and using nosetests command. -Ap-level
128
29e6b1d5e5f5 Add third lab exercise questions.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 127
diff changeset
    58
29e6b1d5e5f5 Add third lab exercise questions.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 127
diff changeset
    59
Lab - 4
29e6b1d5e5f5 Add third lab exercise questions.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 127
diff changeset
    60
=======
29e6b1d5e5f5 Add third lab exercise questions.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 127
diff changeset
    61
129
6e237b9442cd Adding a huge question for lab exercise 4.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 128
diff changeset
    62
  1. Consider the following use case: We are given a large list of
6e237b9442cd Adding a huge question for lab exercise 4.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 128
diff changeset
    63
     items called *data* where each item is a again a list with three
6e237b9442cd Adding a huge question for lab exercise 4.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 128
diff changeset
    64
     values: username, which is a string; status of the user which
6e237b9442cd Adding a huge question for lab exercise 4.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 128
diff changeset
    65
     can be one of the following three strings 'new', 'valid' or
6e237b9442cd Adding a huge question for lab exercise 4.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 128
diff changeset
    66
     'invalid'; and the last login time which is a datetime Python
6e237b9442cd Adding a huge question for lab exercise 4.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 128
diff changeset
    67
     object.  Write a function called **query** that takes a filter
6e237b9442cd Adding a huge question for lab exercise 4.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 128
diff changeset
    68
     dictionary as a parameter and returns the result of the items in
6e237b9442cd Adding a huge question for lab exercise 4.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 128
diff changeset
    69
     the *data* list. They keys of the dictionary can be 'user',
6e237b9442cd Adding a huge question for lab exercise 4.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 128
diff changeset
    70
     'status' and 'logtime' and their corresponding values can be any
6e237b9442cd Adding a huge question for lab exercise 4.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 128
diff changeset
    71
     of the valid values for the corresponding key. Example filter
6e237b9442cd Adding a huge question for lab exercise 4.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 128
diff changeset
    72
     dictionary::
6e237b9442cd Adding a huge question for lab exercise 4.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 128
diff changeset
    73
6e237b9442cd Adding a huge question for lab exercise 4.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 128
diff changeset
    74
       filter = {
6e237b9442cd Adding a huge question for lab exercise 4.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 128
diff changeset
    75
           'user': 'john'
6e237b9442cd Adding a huge question for lab exercise 4.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 128
diff changeset
    76
           'status': 'new'
6e237b9442cd Adding a huge question for lab exercise 4.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 128
diff changeset
    77
           }
6e237b9442cd Adding a huge question for lab exercise 4.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 128
diff changeset
    78
6e237b9442cd Adding a huge question for lab exercise 4.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 128
diff changeset
    79
     Place your function in a file called query.py. Before writing the
6e237b9442cd Adding a huge question for lab exercise 4.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 128
diff changeset
    80
     actual function, follow the test driven development
6e237b9442cd Adding a huge question for lab exercise 4.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 128
diff changeset
    81
     approach. First write a stub, fail the tests and then write the
6e237b9442cd Adding a huge question for lab exercise 4.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 128
diff changeset
    82
     code and make sure the tests pass. Specifically use unittest
6e237b9442cd Adding a huge question for lab exercise 4.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 128
diff changeset
    83
     framework to test this function. Place your tests in a file
6e237b9442cd Adding a huge question for lab exercise 4.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 128
diff changeset
    84
     called test_query.py
6e237b9442cd Adding a huge question for lab exercise 4.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 128
diff changeset
    85
6e237b9442cd Adding a huge question for lab exercise 4.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 128
diff changeset
    86
     A developer wrote a small utility function in a file named
6e237b9442cd Adding a huge question for lab exercise 4.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 128
diff changeset
    87
     user_utils.py which uses your **query** function which looks as
6e237b9442cd Adding a huge question for lab exercise 4.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 128
diff changeset
    88
     follows::
6e237b9442cd Adding a huge question for lab exercise 4.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 128
diff changeset
    89
6e237b9442cd Adding a huge question for lab exercise 4.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 128
diff changeset
    90
       def login_util(user=None):
6e237b9442cd Adding a huge question for lab exercise 4.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 128
diff changeset
    91
           """Takes a user name and returns his last login time if the
6e237b9442cd Adding a huge question for lab exercise 4.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 128
diff changeset
    92
           user is a valid user, else return None. If the user is
6e237b9442cd Adding a huge question for lab exercise 4.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 128
diff changeset
    93
           'host' it returns the last login time of all the users.
6e237b9442cd Adding a huge question for lab exercise 4.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 128
diff changeset
    94
           """
6e237b9442cd Adding a huge question for lab exercise 4.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 128
diff changeset
    95
6e237b9442cd Adding a huge question for lab exercise 4.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 128
diff changeset
    96
           filter_dict = {
6e237b9442cd Adding a huge question for lab exercise 4.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 128
diff changeset
    97
               'user': user
6e237b9442cd Adding a huge question for lab exercise 4.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 128
diff changeset
    98
               'status': 'active'
6e237b9442cd Adding a huge question for lab exercise 4.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 128
diff changeset
    99
               }
6e237b9442cd Adding a huge question for lab exercise 4.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 128
diff changeset
   100
6e237b9442cd Adding a huge question for lab exercise 4.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 128
diff changeset
   101
           if user == 'host':
6e237b9442cd Adding a huge question for lab exercise 4.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 128
diff changeset
   102
               filter_dict['status'] + ['new', 'invalid']
6e237b9442cd Adding a huge question for lab exercise 4.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 128
diff changeset
   103
6e237b9442cd Adding a huge question for lab exercise 4.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 128
diff changeset
   104
           return query(filter_dict)
6e237b9442cd Adding a huge question for lab exercise 4.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 128
diff changeset
   105
6e237b9442cd Adding a huge question for lab exercise 4.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 128
diff changeset
   106
     Unfortunately the developer did not provide us with the test
6e237b9442cd Adding a huge question for lab exercise 4.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 128
diff changeset
   107
     cases. We wrote the following test cases for you to only discover
6e237b9442cd Adding a huge question for lab exercise 4.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 128
diff changeset
   108
     that the function miserably fails. 
6e237b9442cd Adding a huge question for lab exercise 4.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 128
diff changeset
   109
6e237b9442cd Adding a huge question for lab exercise 4.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 128
diff changeset
   110
     The tests were placed in a file called test_user_utils.py and we
6e237b9442cd Adding a huge question for lab exercise 4.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 128
diff changeset
   111
     have used the unittest framework::
6e237b9442cd Adding a huge question for lab exercise 4.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 128
diff changeset
   112
6e237b9442cd Adding a huge question for lab exercise 4.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 128
diff changeset
   113
       import query
6e237b9442cd Adding a huge question for lab exercise 4.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 128
diff changeset
   114
       import user_utils
6e237b9442cd Adding a huge question for lab exercise 4.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 128
diff changeset
   115
       import unittest
6e237b9442cd Adding a huge question for lab exercise 4.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 128
diff changeset
   116
6e237b9442cd Adding a huge question for lab exercise 4.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 128
diff changeset
   117
       class TestUserUtils(unittest.TestCase):
6e237b9442cd Adding a huge question for lab exercise 4.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 128
diff changeset
   118
        
6e237b9442cd Adding a huge question for lab exercise 4.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 128
diff changeset
   119
           def setUp(self):
6e237b9442cd Adding a huge question for lab exercise 4.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 128
diff changeset
   120
               """Boiler plate method to provide common data to all
6e237b9442cd Adding a huge question for lab exercise 4.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 128
diff changeset
   121
               the test methods.
6e237b9442cd Adding a huge question for lab exercise 4.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 128
diff changeset
   122
               """
6e237b9442cd Adding a huge question for lab exercise 4.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 128
diff changeset
   123
               self.test_names = ['Alex', 'Guido', 'Thomas', 'host',
6e237b9442cd Adding a huge question for lab exercise 4.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 128
diff changeset
   124
                   'Tom', 'James']
6e237b9442cd Adding a huge question for lab exercise 4.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 128
diff changeset
   125
               self.data_len = len(query.data)
6e237b9442cd Adding a huge question for lab exercise 4.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 128
diff changeset
   126
6e237b9442cd Adding a huge question for lab exercise 4.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 128
diff changeset
   127
           def test_login_utils(self):
6e237b9442cd Adding a huge question for lab exercise 4.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 128
diff changeset
   128
               """Tests for the login_utils function.
6e237b9442cd Adding a huge question for lab exercise 4.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 128
diff changeset
   129
               """
6e237b9442cd Adding a huge question for lab exercise 4.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 128
diff changeset
   130
6e237b9442cd Adding a huge question for lab exercise 4.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 128
diff changeset
   131
               for name in self.test_names:
6e237b9442cd Adding a huge question for lab exercise 4.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 128
diff changeset
   132
                   if name == 'host':
6e237b9442cd Adding a huge question for lab exercise 4.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 128
diff changeset
   133
                       assertEqual(len(user_utils.login_utils(name)), self.data_len)
6e237b9442cd Adding a huge question for lab exercise 4.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 128
diff changeset
   134
                   else:
6e237b9442cd Adding a huge question for lab exercise 4.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 128
diff changeset
   135
                       assertLess(len(user_utils.login_utils(name)), self.data_len)
6e237b9442cd Adding a huge question for lab exercise 4.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 128
diff changeset
   136
6e237b9442cd Adding a huge question for lab exercise 4.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 128
diff changeset
   137
           def tearDown(self):
6e237b9442cd Adding a huge question for lab exercise 4.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 128
diff changeset
   138
               """Boiler plate method to clean up all the data created
6e237b9442cd Adding a huge question for lab exercise 4.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 128
diff changeset
   139
               for tests.
6e237b9442cd Adding a huge question for lab exercise 4.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 128
diff changeset
   140
               """
6e237b9442cd Adding a huge question for lab exercise 4.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 128
diff changeset
   141
6e237b9442cd Adding a huge question for lab exercise 4.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 128
diff changeset
   142
               del self.test_names
6e237b9442cd Adding a huge question for lab exercise 4.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 128
diff changeset
   143
               del self.data_len
6e237b9442cd Adding a huge question for lab exercise 4.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 128
diff changeset
   144
6e237b9442cd Adding a huge question for lab exercise 4.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 128
diff changeset
   145
     Fix the bug, run the tests to make sure the function passes the
130
e5d183dce985 RBT Levels to the questions.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 129
diff changeset
   146
     tests and if possible refactor the code with a better approach. - An-level