ICU-11976 test & fix ByteArrayWrapper.hashCode()

This commit is contained in:
Markus Scherer 2019-08-30 16:26:59 -07:00
parent 710b6e1421
commit 0b5b3bcdb1
2 changed files with 5 additions and 5 deletions

View File

@ -237,7 +237,7 @@ public class ByteArrayWrapper implements Comparable<ByteArrayWrapper>
*/
@Override
public int hashCode() {
int result = bytes.length;
int result = size;
for (int i = 0; i < size; ++i) {
result = 37*result + bytes[i];
}

View File

@ -137,10 +137,10 @@ public class UtilityTest extends TestFmwk {
}
// test equality
if (!x.equals(y) || !x.equals(z))
errln("FAIL: test (operator ==): Failed!");
if (x.hashCode()!=y.hashCode())
errln("FAIL: identical objects have different hash codes.");
assertEquals("x==y", x, y);
assertEquals("y==z", y, z);
assertEquals("x.hashCode()==y.hashCode()", x.hashCode(), y.hashCode());
assertEquals("y.hashCode()==z.hashCode()", y.hashCode(), z.hashCode());
// test non-equality
y = new ByteArrayWrapper(bb, 4);