summary refs log tree commit diff stats
path: root/test/defaultbucket.cratera
blob: fd7281ef21e2bbd22292aab9ec023764953ae2af (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
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)