Add a test with random input

This commit is contained in:
Hans Svensson 2019-02-25 15:17:50 +01:00
parent af8ac8ba28
commit b70d59333b
2 changed files with 14 additions and 1 deletions

View File

@ -4,7 +4,8 @@
{plugins, [rebar3_hex]}. {plugins, [rebar3_hex]}.
{profiles, [{test, [{deps, [{jsx, {git, "https://github.com/talentdeficit/jsx.git", {tag, "2.8.0"}}}]}]} {profiles, [{test, [{deps, [{jsx, {git, "https://github.com/talentdeficit/jsx.git", {tag, "2.8.0"}}},
{enacl, "0.17.2"}]}]}
]}. ]}.
{xref_checks, [undefined_function_calls, undefined_functions, {xref_checks, [undefined_function_calls, undefined_functions,

View File

@ -24,6 +24,18 @@ blake2s_test_() ->
blake2s(_TC = #{in := Msg, key := Key, out := ExpectedOut}) -> blake2s(_TC = #{in := Msg, key := Key, out := ExpectedOut}) ->
?assertEqual(eblake2:blake2s(byte_size(ExpectedOut), Msg, Key), {ok, ExpectedOut}). ?assertEqual(eblake2:blake2s(byte_size(ExpectedOut), Msg, Key), {ok, ExpectedOut}).
random_test_() ->
{generator, fun() ->
[ {lists:concat(["Random test ", I]), fun() -> random_test(I) end} || I <- lists:seq(1, 50) ]
end}.
random_test(I) ->
Data = crypto:strong_rand_bytes(I * 50),
{ok, Enacl} = enacl:generichash(64, Data),
{ok, Eblake} = eblake2:blake2b(64, Data),
?assertEqual(Eblake, Enacl).
%% Helper functions %% Helper functions
test_vectors() -> test_vectors() ->
parse_test_vectors("test/blake2_testvectors.json"). parse_test_vectors("test/blake2_testvectors.json").