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 to calculate the greatest common divisor (gcd
) of its two parameters \(x\) and \(y\), which are integers and greater than zero.
As long as a and b are not equal, change the greater of the two for
the difference between the greater and the lesser. When they have
the same value, that’s the gcd
of \(x\) and \(y\).
Properties on which the Euclid algorithm is based:
At the end of each iteration: gcd
(\(x\), \(y\))= gcd
(\(a\), \(b\))
This property is a consequence of the mathematical property:
gcd
(\(a\), \(b\)) = gcd
(\(a - b\), \(b\)) when \(a > b\)
gcd
(\(a\), \(b\)) = gcd
(\(a\), \(b - a\)) when \(b > a\)
When finally \(a = b\), gcd
(\(x\), \(y\)) = gcd
(\(a\), \(b\))
Write pytests to test your implementation. If we read the description of the exercise well, we see that the function does not have to work for numbers that are not greater than 0.
Insist that the students test their programs by adding a line
telling them to do it and make sure they read well what the function
is supposed to do.