Repository with assignments using the Test Informed Learning with Examples (TILE) method to integrate testing into existing programming courses for free.
Join our LinkedIN Community.
Use the following BibTeX entry to cite this work:
@INPROCEEDINGS{DVMB2023, author={Doorn, Niels and Vos, Tanja and MarĂn, Beatriz and Barendsen, Erik}, booktitle={2023 IEEE Conference on Software Testing, Verification and Validation (ICST)}, title={Set the right example when teaching programming: Test Informed Learning with Examples (TILE)}, year={2023}, volume={}, number={}, pages={269-280}, doi={10.1109/ICST57152.2023.00033} }
Write a function that, given an integer \(n\) greater than zero, returns a list of the multiples of 3 that exist between 3 and \(n\). Write another function that, given an integer \(n\) greater than zero, returns a list of the divisors of \(n\). Test your functions with pytest, for example:
@pytest.mark.parametrize('testcase, input, expected_output',[ (1, 10, [3, 6, 9]), (2, 0, []), (3, 1, []), (4, -5, []), (5, 12, [3, 6, 9, 12]), (6, 3, [3]) ])
def test_multiples_of_3(testcase, input, expected_output):
assert multiples_of_3(input) == expected_output, 'case 0'.format(testcase)
@pytest.mark.parametrize('testcase, input, expected_output',[ (1, 10, [1, 2, 5, 10]), (2, 18, [1, 2, 3, 6, 9, 18]), (3, 1, [1]), (4, -5, []), (5, 12, [1, 2, 3, 4, 6, 12]), (6, 0, []) ])
def test_divisors_of(testcase, input, expected_output):
assert divisors_of(input) == expected_output, 'case 0'.format(testcase)
Now, use these functions to write a main
program that asks the user for a number greater than zero through the keyboard that returns the following:
>>> %Run
Type an integer greater than zero: 1
There are no multiples of 3
>>> %Run
Type an integer greater than zero: 2
There are no multiples of 3
>>> %Run
Type an integer greater than zero: 3
multiple = 3, divisors of 3 = [1, 3]
>>> %Run
Type an integer greater than zero: 12
multiple = 3, divisors of 3 = [1, 3]
multiple = 6, divisors of 6 = [1, 2, 3, 6]
multiple = 9, divisors of 9 = [1, 3, 9]
multiple = 12, divisors of 12 = [1, 2, 3, 4, 6, 12]
>>>