diff options
Diffstat (limited to 'vespajlib/src/test/java/com/yahoo/collections/BobHashTestCase.java')
-rw-r--r-- | vespajlib/src/test/java/com/yahoo/collections/BobHashTestCase.java | 45 |
1 files changed, 45 insertions, 0 deletions
diff --git a/vespajlib/src/test/java/com/yahoo/collections/BobHashTestCase.java b/vespajlib/src/test/java/com/yahoo/collections/BobHashTestCase.java new file mode 100644 index 00000000000..820adffcfc5 --- /dev/null +++ b/vespajlib/src/test/java/com/yahoo/collections/BobHashTestCase.java @@ -0,0 +1,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); + } +} |