1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
|
// Copyright 2016 Yahoo Inc. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
package com.yahoo.collections;
import com.yahoo.collections.BobHash;
/**
* Basic consistency check of BobHash implementation
*
* @author <a href="mailto:steinar@yahoo-inc.com">Steinar Knutsen</a>
*/
public class BobHashTestCase extends junit.framework.TestCase {
public BobHashTestCase(String name) {
super(name);
}
public void testit() {
// Teststring: minprice
// Basic ASCII string
byte[] minprice = { 109, 105, 110, 112, 114, 105, 99, 101 };
assertEquals(BobHash.hash(minprice, 0), 0x90188543);
// Teststring: a\u00FFa\u00FF
// String with non-ASCII characters
byte[] ayay = { 97, -1, 97, -1 };
assertEquals(BobHash.hash(ayay, 0), 0x1C798331);
// lots of a's to ensure testing unsigned type emulation
byte[] aa = {
97, 97, 97, 97, 97, 97, 97, 97, 97, 97, 97, 97, 97, 97, 97,
97, 97, 97, 97, 97, 97, 97, 97, 97, 97, 97, 97, 97 };
assertEquals(BobHash.hash(aa, 0), 0xE09ED5E9);
// A string which caused problems during developmen of another
// feature
byte[] lastnamefirstinitial = {
0x6c, 0x61, 0x73, 0x74, 0x6e, 0x61, 0x6d,
0x65, 0x66, 0x69, 0x72, 0x73, 0x74, 0x69, 0x6e, 0x69, 0x74, 0x69,
0x61, 0x6c };
assertEquals(BobHash.hash(lastnamefirstinitial, 0), 0xF36B4BD3);
}
}
|