get-random-values-polypony
Version:
Synchronous randombytes function that works in node, the browser & react-native!
1 lines • 1.8 kB
JavaScript
const test=require("fresh-tape"),lng=require("../long.js"),xor=lng.xor,murmur=require("../murmurhash3.js"),murmurhash3Long=murmur.murmurhash3Long,murmurhash3String=murmur.murmurhash3String,TMP={low:0,high:0},TMP2={low:0,high:0},TMP3={low:0,high:0},data=[{input:{low:1,high:0},result:{low:159932351,high:1569927747}},{input:{low:0,high:0},result:{low:0,high:0}},{input:{low:0,high:1},result:{low:800744850,high:-299444368}},{input:{low:3424112,high:4234234},result:{low:-527662042,high:794622717}},{input:{low:0,high:131414123123},result:{low:776941238,high:1035631136}}];test("murmurhash3Number",function(t){data.forEach(function(obj){const input=obj.input,result=obj.result,output={low:0,high:0};murmurhash3Long(input,output),t.deepEquals(output,result,"{low:"+input.low+",high:"+input.high+"}")}),t.end()}),test("murmurhash3String",function(t){const simple=function(input,expectedOut){t.deepEquals(murmurhash3String(input,TMP),murmurhash3Long(expectedOut,TMP2),"\""+encodeURIComponent(input)+"\"")};simple("a",{low:97,high:0}),simple("\0a",{low:0,high:97}),simple("\0\0a",{low:24832,high:0}),simple("\0\0\0a",{low:0,high:24832}),simple("\0\0\0\0a",{low:6356992,high:0}),simple("\0\0\0\0\0a",{low:0,high:6356992}),simple("\0\0\0\0\0\0a",{low:1627389952,high:0}),simple("\0\0\0\0\0\0\0a",{low:0,high:1627389952}),simple("\0\0\0\0\0\0\0\0a",{low:97,high:0}),simple("abcdefgh",{low:1734697825,high:1751540834}),t.deepEquals(murmurhash3String("abcdefghijklmnop",TMP),xor(murmurhash3Long({low:1734697825,high:1751540834},TMP2),murmurhash3Long({low:1869441897,high:1886284906},TMP3),TMP3),"\"abcdefghijklmnop\""),t.deepEquals(murmurhash3String("abcdefghijkl",TMP),xor(murmurhash3Long({low:1734697825,high:1751540834},TMP2),murmurhash3Long({low:27497,high:27754},TMP3),TMP3),"\"abcdefghijkl\""),t.end()});