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.

Greatest common divisor

Write a function to calculate the greatest common divisor (gcd) of its two parameters \(x\) and \(y\), which are integers and greater than zero.

  1. Use Euclid’s algorithm. Let \(x\) e \(y\) be the original values of the variables \(a\) and \(b\), the algorithm says:

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:

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.