local S=require("\046\046\047\109\111\100\117\108\101\115\047\120\120\104\097\115\104\051\050")local H=os.clock()local a=gcinfo()assert(S("\097\098\099")==852579327,"\040\088\088\072\051\050\041 \097\098\099 \104\097\115\104 \100\111\101\115 \110\111\116 \109\097\116\099\104")assert(S("\097\098\099",852579327)==2420236504,"\040\088\088\072\051\050\041 \097\098\099 \104\097\115\104 \119\105\116\104 \115\101\101\100 \100\111\101\115 \110\111\116 \109\097\116\099\104")assert(S("")==46947589,"\040\088\088\072\051\050\041 \101\109\112\116\121 \104\097\115\104 \100\111\101\115 \110\111\116 \109\097\116\099\104")assert(S("",46947589)==4128325988,"\040\088\088\072\051\050\041 \101\109\112\116\121 \104\097\115\104 \119\105\116\104 \115\101\101\100 \100\111\101\115 \110\111\116 \109\097\116\099\104")assert(S("\097\098\099\100\098\099\100\101\099\100\101\102\100\101\102\103\101\102\103\104\102\103\104\105\103\104\105\106\104\105\106\107\105\106\107\108\106\107\108\109\107\108\109\110\108\109\110\111\109\110\111\112\110\111\112\113")==2313838787,"\040\088\088\072\051\050\041 \052\052\056 \098\105\116 \097\108\112\104\097\098\101\116 \104\097\115\104 \100\111\101\115 \110\111\116 \109\097\116\099\104")assert(S("\097\098\099\100\098\099\100\101\099\100\101\102\100\101\102\103\101\102\103\104\102\103\104\105\103\104\105\106\104\105\106\107\105\106\107\108\106\107\108\109\107\108\109\110\108\109\110\111\109\110\111\112\110\111\112\113",2313838787)==1078489571,"\040\088\088\072\051\050\041 \052\052\056 \098\105\116 \097\108\112\104\097\098\101\116 \104\097\115\104 \119\105\116\104 \115\101\101\100 \100\111\101\115 \110\111\116 \109\097\116\099\104")assert(S("\097\098\099\100\101\102\103\104\098\099\100\101\102\103\104\105\099\100\101\102\103\104\105\106\100\101\102\103\104\105\106\107\101\102\103\104\105\106\107\108\102\103\104\105\106\107\108\109\103\104\105\106\107\108\109\110\104\105\106\107\108\109\110\111\105\106\107\108\109\110\111\112\106\107\108\109\110\111\112\113\107\108\109\110\111\112\113\114\108\109\110\111\112\113\114\115\109\110\111\112\113\114\115\116\110\111\112\113\114\115\116\117")==1493909861,"\040\088\088\072\051\050\041 \056\057\054 \098\105\116 \097\108\112\104\097\098\101\116 \104\097\115\104 \100\111\101\115 \110\111\116 \109\097\116\099\104")assert(S("\097\098\099\100\101\102\103\104\098\099\100\101\102\103\104\105\099\100\101\102\103\104\105\106\100\101\102\103\104\105\106\107\101\102\103\104\105\106\107\108\102\103\104\105\106\107\108\109\103\104\105\106\107\108\109\110\104\105\106\107\108\109\110\111\105\106\107\108\109\110\111\112\106\107\108\109\110\111\112\113\107\108\109\110\111\112\113\114\108\109\110\111\112\113\114\115\109\110\111\112\113\114\115\116\110\111\112\113\114\115\116\117",1493909861)==3224620435,"\040\088\088\072\051\050\041 \056\057\054 \098\105\116 \097\108\112\104\097\098\101\116 \104\097\115\104 \119\105\116\104 \115\101\101\100 \100\111\101\115 \110\111\116 \109\097\116\099\104")assert(S("\102\111\111")==3792637401,"\040\088\088\072\051\050\041 \102\111\111 \104\097\115\104 \100\111\101\115 \110\111\116 \109\097\116\099\104")assert(S("\102\111\111",3792637401)==4107531977,"\040\088\088\072\051\050\041 \102\111\111 \104\097\115\104 \119\105\116\104 \115\101\101\100 \100\111\101\115 \110\111\116 \109\097\116\099\104")assert(S("\098\097\114")==1101146924,"\040\088\088\072\051\050\041 \098\097\114 \104\097\115\104 \100\111\101\115 \110\111\116 \109\097\116\099\104")assert(S("\098\097\114",1101146924)==2597645011,"\040\088\088\072\051\050\041 \098\097\114 \104\097\115\104 \119\105\116\104 \115\101\101\100 \100\111\101\115 \110\111\116 \109\097\116\099\104")assert(S("\098\097\122")==2611677575,"\040\088\088\072\051\050\041 \098\097\122 \104\097\115\104 \100\111\101\115 \110\111\116 \109\097\116\099\104")assert(S("\098\097\122",2611677575)==598711193,"\040\088\088\072\051\050\041 \098\097\122 \104\097\115\104 \119\105\116\104 \115\101\101\100 \100\111\101\115 \110\111\116 \109\097\116\099\104")assert(S("\084\104\101 \070\105\116\110\101\115\115-\071\114\097\109 \080\097\099\101\114 \084\101\115\116 \105\115 \097 \109\117\108\116\105-\115\116\097\103\101 \097\101\114\111\098\105\099 \099\097\112\097\099\105\116\121 \116\101\115\116")==3198588583,"\040\088\088\072\051\050\041 \070\105\116\110\101\115\115-\071\114\097\109 \104\097\115\104 \100\111\101\115 \110\111\116 \109\097\116\099\104")assert(S("\084\104\101 \070\105\116\110\101\115\115-\071\114\097\109 \080\097\099\101\114 \084\101\115\116 \105\115 \097 \109\117\108\116\105-\115\116\097\103\101 \097\101\114\111\098\105\099 \099\097\112\097\099\105\116\121 \116\101\115\116",3198588583)==1013905389,"\040\088\088\072\051\050\041 \070\105\116\110\101\115\115-\071\114\097\109 \104\097\115\104 \119\105\116\104 \115\101\101\100 \100\111\101\115 \110\111\116 \109\097\116\099\104")if true then local H=string.rep("\101",199999)local a=string.rep("\097",1000000.0)assert(S(H)==2994591064,"\040\088\088\072\051\050\041 \101 \104\097\115\104 \100\111\101\115 \110\111\116 \109\097\116\099\104")assert(S(H,2994591064)==1635035581,"\040\088\088\072\051\050\041 \101 \104\097\115\104 \119\105\116\104 \115\101\101\100 \100\111\101\115 \110\111\116 \109\097\116\099\104")assert(S(a)==3776272672,"\040\088\088\072\051\050\041 \109\105\108\108\105\111\110 \097 \104\097\115\104 \100\111\101\115 \110\111\116 \109\097\116\099\104")assert(S(a,3776272672)==3234315950,"\040\088\088\072\051\050\041 \109\105\108\108\105\111\110 \097 \104\097\115\104 \119\105\116\104 \115\101\101\100 \100\111\101\115 \110\111\116 \109\097\116\099\104")end print("\067\104\097\110\103\101 \105\110 \109\101\109\111\114\121\058",gcinfo()-a)print("\088\088\072\051\050 \116\101\115\116\115 \099\111\109\112\108\101\116\101\100\046 \084\111\111\107",os.clock()-H)
local xxhash32 = require("../modules/xxhash32")

local t = os.clock()
local startgc = gcinfo()

assert(xxhash32("abc") == 0x32d153ff, "(XXH32) abc hash does not match")
-- 852579327
assert(xxhash32("abc", 0x32d153ff) == 0x9041e0d8, "(XXH32) abc hash with seed does not match")

assert(xxhash32("") == 0x02cc5d05, "(XXH32) empty hash does not match")
--46947589
assert(xxhash32("", 0x02cc5d05) == 0xf6114164, "(XXH32) empty hash with seed does not match")
assert(
	xxhash32("abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq") == 0x89ea60c3,
	"(XXH32) 448 bit alphabet hash does not match"
)
--2313838787
assert(
	xxhash32("abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq", 0x89ea60c3) == 0x404871e3,
	"(XXH32) 448 bit alphabet hash with seed does not match"
)
assert(
	xxhash32(
		"abcdefghbcdefghicdefghijdefghijkefghijklfghijklmghijklmnhijklmnoijklmnopjklmnopqklmnopqrlmnopqrsmnopqrstnopqrstu"
	) == 0x590b4165,
	"(XXH32) 896 bit alphabet hash does not match"
)
-- 1493909861
assert(
	xxhash32(
		"abcdefghbcdefghicdefghijdefghijkefghijklfghijklmghijklmnhijklmnoijklmnopjklmnopqklmnopqrlmnopqrsmnopqrstnopqrstu",
		0x590b4165
	) == 0xc033cd93,
	"(XXH32) 896 bit alphabet hash with seed does not match"
)
assert(xxhash32("foo") == 0xe20f0dd9, "(XXH32) foo hash does not match")
--3792637401
assert(xxhash32("foo", 0xe20f0dd9) == 0xf4d3f6c9, "(XXH32) foo hash with seed does not match")
assert(xxhash32("bar") == 0x41a22b2c, "(XXH32) bar hash does not match")
--1101146924
assert(xxhash32("bar", 0x41a22b2c) == 0x9ad4ead3, "(XXH32) bar hash with seed does not match")
assert(xxhash32("baz") == 0x9bab0987, "(XXH32) baz hash does not match")
--2611677575
assert(xxhash32("baz", 0x9bab0987) == 0x23af9b99, "(XXH32) baz hash with seed does not match")
assert(
	xxhash32("The Fitness-Gram Pacer Test is a multi-stage aerobic capacity test") == 0xbea696a7,
	"(XXH32) Fitness-Gram hash does not match"
)
--3198588583
assert(
	xxhash32("The Fitness-Gram Pacer Test is a multi-stage aerobic capacity test", 0xbea696a7) == 0x3c6ef7ed,
	"(XXH32) Fitness-Gram hash with seed does not match"
)
if true then
	local e = string.rep("e", 199999)
	local a = string.rep("a", 1e6)

	-- local t2 = os.clock()
	assert(xxhash32(e) == 0xb27dd558, "(XXH32) e hash does not match")
	--2994591064
	assert(xxhash32(e, 0xb27dd558) == 0x6174a9bd, "(XXH32) e hash with seed does not match")
	-- print(`e hash took {os.clock() - t2}`)

	-- t2 = os.clock()
	assert(xxhash32(a) == 0xe1155920, "(XXH32) million a hash does not match")
	--3776272672
	assert(xxhash32(a, 0xe1155920) == 0xc0c7beae, "(XXH32) million a hash with seed does not match")
	-- print(`million a hash took {os.clock() - t2}`)
end

print("Change in memory:", gcinfo() - startgc)
print("XXH32 tests completed. Took", os.clock() - t)
