Created
February 8, 2017 20:44
-
-
Save jadeallenx/3ff503f44b196f9fbf31e9a41b96efdc to your computer and use it in GitHub Desktop.
Property based testing example
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-module(kata). | |
-compile([export_all]). | |
-include_lib("proper/include/proper.hrl"). | |
%% Test that calendar:is_leap_year/1 is fully compliant with the rules for computing leap years. | |
%% https://en.wikipedia.org/wiki/Leap_year#Algorithm | |
-define(ELSE, true). | |
gen_year() -> ?SUCHTHAT(Y, integer(), Y > 0 ). | |
my_is_leap_year(Year) -> | |
if | |
Year rem 400 == 0 -> true; | |
Year rem 100 == 0 -> false; | |
Year rem 4 == 0 -> true; | |
?ELSE -> false | |
end. | |
prop_leap_year() -> | |
?FORALL(Year, gen_year(), my_is_leap_year(Year) == calendar:is_leap_year(Year)). |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment