Tutorial 8

This tutorial we’ll practice writing Tests for our functions.

We will write a function that calculates whether or not a particular year is a leap year. This is how the Gregorian calendar calculates leap years:

Write a function named is_leap. It should:

Here are some examples of what the function should return:

In addition from the above examples, here are some test cases you should write as well

What are some other edge cases you can think of?

R

  1. Write an R function that meets the above criteria
  2. Using {testthat} write unit tests that can test your function
  3. You may opt to source your function file in your test file.

Python (optional)

  1. Write an R function that meets the above criteria
  2. Write tests for your function that can be run with pytest
  3. For this tutorial, create your function and test files in the same directory, so it’s easier to import your function module for testing.