Skip to content

Instantly share code, notes, and snippets.

@giorgiosironi
Created June 14, 2015 12:17
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save giorgiosironi/4721aba8f1949cc3c938 to your computer and use it in GitHub Desktop.
Save giorgiosironi/4721aba8f1949cc3c938 to your computer and use it in GitHub Desktop.
Property-based testing fromZeroBasedDayOfYear()
$this->forAll(
Generator\int(2000, 2020),
Generator\int(0, 364),
Generator\int(0, 364)
)
->then(function($year, $dayOfYear, $anotherDayOfYear) {
$day = fromZeroBasedDayOfYear($year, $dayOfYear);
$anotherDay = fromZeroBasedDayOfYear($year, $anotherDayOfYear);
$this->assertEquals(
abs($dayOfYear - $anotherDayOfYear) * 86400,
abs($day->getTimestamp() - $anotherDay->getTimestamp()),
"Days of the year $year: $dayOfYear, $anotherDayOfYear" . PHP_EOL
. "{$day->format(DateTime::ISO8601)}, {$anotherDay->format(DateTime::ISO8601)}"
);
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment