TDD in Python: determine if a number is prime

Опубликовано: 06 Май 2026
на канале: Richèl J.C. Bilderbeek
39
like

Here I show how to use TDD in Python to determine if a number is prime.

I use the built-in unittest package as a testing framework. I push the code to the GitHub repository only at the end. I do not test for style (there is a test in the repo that will fail) and I leave fixing the style as an exercise to the viewer.

TDD 1/3: TDD: https://richelbilderbeek.nl/programmi... and    • Programming Formalisms: TDD, hour 1 part 1  
TDD 2/3: `is_zero`: https://richelbilderbeek.nl/tdd_pytho... and    • TDD in Python 'is_zero' and upload to GitHub  
TDD 3/3: Introduce `is_even`: https://richelbilderbeek.nl/programmi...    • Programming Formalisms: TDD, hour 1, part 3  
Solution `is_even`: https://richelbilderbeek.nl/tdd_pytho... and    • TDD in Python: `is_even`  
TDD 2: introduce `is_odd`: https://richelbilderbeek.nl/programmi... and    • Programming Formalisms: TDD, hour 2, part 1  
Solution `is_odd`: https://richelbilderbeek.nl/tdd_pytho... and    • TDD in Python: `is_odd`  
TDD 3: TDD bottom line: https://richelbilderbeek.nl/programmi... and    • Programming Formalisms: TDD, hour 3, part 1  
Solution `is_prime`: https://richelbilderbeek.nl/tdd_pytho... and    • TDD in Python: determine if a number is prime  

Course homepage: https://github.com/UPPMAX/programming...