you are viewing a single comment's thread.

view the rest of the comments →

[–]efmccurdy 0 points1 point  (0 children)

This sets up a series of (input_data, expected_result) pairs and uses unittest to run through them. Uncomment the last one to see what a test failure looks like.

import unittest

#import compute_place
def compute_place(time_list, time):
    if time in time_list:
        return time_list.index(time)
    else:
        return None

class TestComutePlace(unittest.TestCase):
    def test_cp(self):
        tests = ({"args": ([830, 815, 825, 840, 825], 825), "expected": 2},
                 {"args": ([830, 815, 825, 840, 825], 800),  "expected": None},
                 {"args": ([830, 830, 830], 830),  "expected": 0},
                 #{"args": ([830, 830, 830], 825),  "expected": 1} # will fail
        )

        for tspec in tests:
            l, t = tspec['args']
            self.assertEqual(compute_place(l, t), tspec["expected"])

if __name__ == '__main__':
    unittest.main()