summary refs log blame commit diff stats
path: root/test/defaultbucket.cratera
blob: fd7281ef21e2bbd22292aab9ec023764953ae2af (plain) (tree)





















                                              
local bucketlib = require "cratera.lib.bucket"

local Bucket = bucketlib.Bucket
local DefaultBucket = bucketlib.DefaultBucket

local function hash_n(n)
    local bucket = DefaultBucket()
    bucket:[Bucket].put_number(n)
    return bucket:[Bucket].finish()
end

local function hash_s(n)
    local bucket = DefaultBucket()
    bucket:[Bucket].put_string(n)
    return bucket:[Bucket].finish()
end

assert(hash_n(1) == 1)
assert(hash_n(2) == 2)
assert(hash_n(-1) == 1)
assert(hash_s("") == 0)
assert(hash_s("h") == string.byte("h")+31)