Skip to content
SDETRole
SDETRole

Leap years in three tests

intermediate Equivalence partitioning Challenge 4 of 10

A calendar library tells whether a year is a leap year. Write tests that expose every bug in five buggy implementations, using no more than three test cases.

Requirements

  • A year is a leap year when it is divisible by 4.
  • Exception: a year divisible by 100 is not a leap year, unless it is also divisible by 400.
  • Results are true or false.
  • Use at most 3 tests. Each one needs an expected result that agrees with the rule.

Expected output

At most 3 tests that match the specification and expose all 5 planted bugs.

Function under test

isLeapYear(year) → result

  • year a number (a positive whole number)

How your tests are checked

  • ○Every expected value agrees with the specification
  • ○Your tests expose all 5 planted bugs
  • ○No more than 3 tests

The correct implementation is the oracle. A bug counts as caught when one of your valid tests gives a different result on the buggy copy than on the correct code.

testsMutation-tested in your browser
#yearnumbera positive whole numberexpected resultRemove
1
1 test · limit 3

Ctrl/⌘ + Enter to check tests · your tests are saved in this browser

Results

Check your tests to see which planted bugs they catch.

Type to search across SDETRole.

Full-text search by Pagefind · runs in your browser Open search page →