blob: 058b820b7908eb5d5409594362d090d333f7b49b [file] [log] [blame]
#! /usr/bin/env escript
%% This file is part of khash released under the MIT license.
%% See the LICENSE file for more information.
%% Copyright 2013 Cloudant, Inc <support@cloudant.com>
-mode(compile).
main([]) ->
code:add_pathz("test"),
util:run(12, fun() ->
test(),
ok
end).
test() ->
{ok, C} = khash:new(),
etap:is(khash:lookup(C, <<"foo">>), not_found, "Lookup missing is ok"),
etap:is(khash:get(C, <<"foo">>), undefined, "Get missing is ok"),
etap:is(khash:del(C, <<"foo">>), not_found, "Del missing is ok"),
etap:is(khash:put(C, <<"foo">>, bar), ok, "Stored a key"),
etap:is(khash:lookup(C, <<"foo">>), {value, bar}, "Lookuped a key"),
etap:is(khash:get(C, <<"foo">>), bar, "Retrieved a key"),
etap:is(khash:put(C, <<"bar">>, foo), ok, "Stored a key"),
etap:is(khash:size(C), 2, "Correct size for hash"),
etap:is(khash:del(C, <<"foo">>), ok, "Deleted a key"),
etap:is(khash:size(C), 1, "Correct size after delete"),
etap:is(khash:clear(C), ok, "Cleared the hash"),
etap:is(khash:size(C), 0, "Correct size after clear").