diff options
Diffstat (limited to 'guava-tests/test/com/google/common/hash/AbstractNonStreamingHashFunctionTest.java')
-rw-r--r-- | guava-tests/test/com/google/common/hash/AbstractNonStreamingHashFunctionTest.java | 69 |
1 files changed, 7 insertions, 62 deletions
diff --git a/guava-tests/test/com/google/common/hash/AbstractNonStreamingHashFunctionTest.java b/guava-tests/test/com/google/common/hash/AbstractNonStreamingHashFunctionTest.java index 2cec063..b4edf42 100644 --- a/guava-tests/test/com/google/common/hash/AbstractNonStreamingHashFunctionTest.java +++ b/guava-tests/test/com/google/common/hash/AbstractNonStreamingHashFunctionTest.java @@ -1,18 +1,4 @@ -/* - * Copyright (C) 2011 The Guava Authors - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ +// Copyright 2011 Google Inc. All Rights Reserved. package com.google.common.hash; @@ -36,8 +22,8 @@ public class AbstractNonStreamingHashFunctionTest extends TestCase { * Constructs two trivial HashFunctions (output := input), one streaming and one non-streaming, * and checks that their results are identical, no matter which newHasher version we used. */ - public void testExhaustive() { - List<Hasher> hashers = ImmutableList.of( + public void test() { + List<Hasher> hashers = ImmutableList.of( new StreamingVersion().newHasher(), new StreamingVersion().newHasher(52), new NonStreamingVersion().newHasher(), @@ -54,43 +40,7 @@ public class AbstractNonStreamingHashFunctionTest extends TestCase { assertEquals(codes[i - 1], codes[i]); } } - - public void testPutStringWithLowSurrogate() { - // we pad because the dummy hash function we use to test this, merely copies the input into - // the output, so the input must be at least 32 bits, since the output has to be that long - assertPutString(new char[] { 'p', HashTestUtils.randomLowSurrogate(new Random()) }); - } - - public void testPutStringWithHighSurrogate() { - // we pad because the dummy hash function we use to test this, merely copies the input into - // the output, so the input must be at least 32 bits, since the output has to be that long - assertPutString(new char[] { 'p', HashTestUtils.randomHighSurrogate(new Random()) }); - } - - public void testPutStringWithLowHighSurrogate() { - assertPutString(new char[] { - HashTestUtils.randomLowSurrogate(new Random()), - HashTestUtils.randomHighSurrogate(new Random()) }); - } - - public void testPutStringWithHighLowSurrogate() { - assertPutString(new char[] { - HashTestUtils.randomHighSurrogate(new Random()), - HashTestUtils.randomLowSurrogate(new Random()) }); - } - - private static void assertPutString(char[] chars) { - Hasher h1 = new NonStreamingVersion().newHasher(); - Hasher h2 = new NonStreamingVersion().newHasher(); - String s = new String(chars); - // this is the correct implementation of the spec - for (int i = 0; i < s.length(); i++) { - h1.putChar(s.charAt(i)); - } - h2.putString(s); - assertEquals(h1.hash(), h2.hash()); - } - + static class StreamingVersion extends AbstractStreamingHashFunction { @Override public int bits() { @@ -122,7 +72,7 @@ public class AbstractNonStreamingHashFunctionTest extends TestCase { }; } } - + static class NonStreamingVersion extends AbstractNonStreamingHashFunction { @Override public int bits() { @@ -138,12 +88,12 @@ public class AbstractNonStreamingHashFunctionTest extends TestCase { public HashCode hashBytes(byte[] input, int off, int len) { return HashCodes.fromBytes(Arrays.copyOfRange(input, off, off + len)); } - + @Override public HashCode hashString(CharSequence input) { throw new UnsupportedOperationException(); } - + @Override public HashCode hashString(CharSequence input, Charset charset) { throw new UnsupportedOperationException(); @@ -153,10 +103,5 @@ public class AbstractNonStreamingHashFunctionTest extends TestCase { public HashCode hashLong(long input) { throw new UnsupportedOperationException(); } - - @Override - public HashCode hashInt(int input) { - throw new UnsupportedOperationException(); - } } } |