Test Informed Learning with Examples

Logo

Repository with assignments using the Test Informed Learning with Examples (TILE) method to integrate testing into existing programming courses for free.

Menu

LinkedIN Community

Join our LinkedIN Community.

Cite this work

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}
}

Is this a digit?

Write a function is_digit which receives a string as a parameter and returns a boolean. The function will return True when the parameter coincides with a character that is a digit from 0 to 9, otherwise it will return False).

You can use the following test cases to test your function:

test_case_ID  | test_input  | expected_output  | reason for testing this
--------------| ------------| -----------------|-----------------------------------
1             |    `'0'`    |  `True`          |  smallest digit
2             |  `'9'`      |  `True`          |   largest digit
3             |  `'5'`      |  `True`          |   other digit
4             |  `'12'`     |   `False`        |   it is not a digit between 0 and 9
5             |  `'-2'`     |  `False`         |  negative digit
6             |   `'hello'` |  `False`         |  string
7             |   `'r'`     |  `False`         |  a character
8             |   `'O'`     |  `False`         |  letter O, not 0

In pytest these could be implemented like:

@pytest.mark.parametrize("testcase, entrada, salida_esperada",[
    (1, '0', True),     # smallest digit
    (2, '9', True),     # largest digit
    (3, '5', True),     # other digit
    (4, '12', False),    # it is not a digit between 0 and 9 
    (5, '-2', False),    # negative digit
    (6, 'hello', False),# string
    (7, 'r', False), #character
    (8, 'O', False), #character
    ]
)

def test_is_digit(test_case_ID, test_input, expected_output): 
    assert is_digit(test_input) == expected_output, "case 0".format(test_case_ID)
Insist that the students test their programs by giving them example
pytests. And make the connection to the tables with test cases they
have seen before.