Skip to content

leap: Test case is not suitable to get desired solution. #1281

Closed
@Stargator

Description

@Stargator

The canonical-data.json for leap only offers four cases.

Because I am mentoring on a track that implemented this, I've realized how easy it is for someone to meet the test criteria without implementing the desired solution.

Let me elaborate on how they can pass the test suite first and then I'll detail how that doesn't fit the desired solution.

The most basic solutions to pass the tests are:
First Solution (fixed a typo):

bool leapYear(int year) {
  if (year == 2015 || year == 2100 || year == 300) {
    return false;
  }
  return true;
}

Second Solution:

bool leapYear(int year) {
  if (year == 1996 || year == 2000) {
    return true;
  }
  return false;
}

The desired solution would have the algorithm:

  • Check whether the year is evenly divisible by 4 then return true
  • Unless the year is evenly divisible by 100
  • Except if the year is also evenly divisible by 400.

The only way I see to resolve this, is just to brute force add a lot of different cases with different years.

Would that be worth it to encourage folks to actually produce a solution instead of solving the test suite?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions