Skip to content

Instantly share code, notes, and snippets.

@jadeallenx
Created February 8, 2017 20:44
Show Gist options
  • Save jadeallenx/3ff503f44b196f9fbf31e9a41b96efdc to your computer and use it in GitHub Desktop.
Save jadeallenx/3ff503f44b196f9fbf31e9a41b96efdc to your computer and use it in GitHub Desktop.
Property based testing example
-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