Skip to content

Commit a1fb848

Browse files
committed
MurmurHashTest2: Use Assert.equals and conditional Assert.fail.
1 parent 48b2331 commit a1fb848

1 file changed

Lines changed: 17 additions & 16 deletions

File tree

src/test/java/org/apache/commons/codec/digest/MurmurHash2Test.java

Lines changed: 17 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,7 @@
1717

1818
package org.apache.commons.codec.digest;
1919

20-
import static org.junit.Assert.assertTrue;
21-
import static org.junit.Assert.fail;
22-
20+
import org.junit.Assert;
2321
import org.junit.Test;
2422

2523
public class MurmurHash2Test {
@@ -85,8 +83,8 @@ public void testHash32ByteArrayIntInt() {
8583
for (int i = 0; i < input.length; i++) {
8684
final int hash = MurmurHash2.hash32(input[i], input[i].length, 0x71b4954d);
8785
if (hash != results32_seed[i]) {
88-
fail(String.format("Unexpected hash32 result for example %d: 0x%08x instead of 0x%08x", i, hash,
89-
results32_seed[i]));
86+
Assert.fail(String.format("Unexpected hash32 result for example %d: 0x%08x instead of 0x%08x", i, hash,
87+
results32_seed[i]));
9088
}
9189
}
9290
}
@@ -96,52 +94,55 @@ public void testHash32ByteArrayInt() {
9694
for (int i = 0; i < input.length; i++) {
9795
final int hash = MurmurHash2.hash32(input[i], input[i].length);
9896
if (hash != results32_standard[i]) {
99-
fail(String.format("Unexpected hash32 result for example %d: 0x%08x instead of 0x%08x", i, hash,
100-
results32_standard[i]));
97+
Assert.fail(String.format("Unexpected hash32 result for example %d: 0x%08x instead of 0x%08x", i, hash,
98+
results32_standard[i]));
10199
}
102100
}
103101
}
104102

105103
@Test
106104
public void testHash32String() {
107105
final int hash = MurmurHash2.hash32(text);
108-
assertTrue(hash == 0xb3bf597e);
106+
Assert.assertEquals(0xb3bf597e, hash);
109107
}
110108

111109
@Test
112110
public void testHash32StringIntInt() {
113111
final int hash = MurmurHash2.hash32(text, 2, text.length() - 4);
114-
assertTrue(hash == 0x4d666d90);
112+
Assert.assertEquals(0x4d666d90, hash);
115113
}
116114

117115
@Test
118116
public void testHash64ByteArrayIntInt() {
119117
for (int i = 0; i < input.length; i++) {
120118
final long hash = MurmurHash2.hash64(input[i], input[i].length, 0x344d1f5c);
121-
assertTrue(String.format("Unexpected hash64 result for example %d: 0x%016x instead of 0x%016x", i, hash,
122-
results64_seed[i]), hash == results64_seed[i]);
119+
if (hash != results64_seed[i]) {
120+
Assert.fail(String.format("Unexpected hash64 result for example %d: 0x%016x instead of 0x%016x", i, hash,
121+
results64_seed[i]));
122+
}
123123
}
124124
}
125125

126126
@Test
127127
public void testHash64ByteArrayInt() {
128128
for (int i = 0; i < input.length; i++) {
129129
final long hash = MurmurHash2.hash64(input[i], input[i].length);
130-
assertTrue(String.format("Unexpected hash64 result for example %d: 0x%016x instead of 0x%016x", i, hash,
131-
results64_standard[i]), hash == results64_standard[i]);
130+
if (hash != results64_standard[i]) {
131+
Assert.fail(String.format("Unexpected hash64 result for example %d: 0x%016x instead of 0x%016x", i, hash,
132+
results64_standard[i]));
133+
}
132134
}
133135
}
134136

135137
@Test
136138
public void testHash64String() {
137139
final long hash = MurmurHash2.hash64(text);
138-
assertTrue(hash == 0x0920e0c1b7eeb261l);
140+
Assert.assertEquals(0x0920e0c1b7eeb261L, hash);
139141
}
140142

141143
@Test
142144
public void testHash64StringIntInt() {
143145
final long hash = MurmurHash2.hash64(text, 2, text.length() - 4);
144-
assertTrue(hash == 0xa8b33145194985a2l);
146+
Assert.assertEquals(0xa8b33145194985a2L, hash);
145147
}
146-
147148
}

0 commit comments

Comments
 (0)