aboutsummaryrefslogtreecommitdiffstats
path: root/vespajlib/src/test/java/com/yahoo/collections/BobHashTestCase.java
blob: 36f88059daca173405b75ce6b8e7a5faaa186c76 (plain) (blame)
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
// Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
package com.yahoo.collections;

import org.junit.Test;

import static org.junit.Assert.assertEquals;

/**
 * Basic consistency check of BobHash implementation
 *
 * @author Steinar Knutsen
 */
public class BobHashTestCase {

    @Test
    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);
    }

}