| 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 | | | package org.jcoderz.commons.util; |
| 34 | | | |
| 35 | | | import java.util.Collections; |
| 36 | | | import junit.framework.TestCase; |
| 37 | | | |
| 38 | | | |
| 39 | | | {@link } |
| 40 | | | |
| 41 | | | @author |
| 42 | | | |
| 43 | 100 | | public class HashCodeTest |
| 44 | | | extends TestCase |
| 45 | | | { |
| 46 | | | |
| 47 | | | {@link } |
| 48 | | | |
| 49 | | | public void testToInt () |
| 50 | | | { |
| 51 | 100 | | final HashCode hashCode = new HashCode(); |
| 52 | 100 | | hashCode.hash(Constants.BITS_PER_INTEGER); |
| 53 | 100 | | hashCode.hash("string"); |
| 54 | 100 | | assertEquals("toInt should not modify the hashCode", |
| 55 | | | hashCode.toInt(), hashCode.toInt()); |
| 56 | 100 | | } |
| 57 | | | |
| 58 | | | |
| 59 | | | {@link } |
| 60 | | | |
| 61 | | | public void testToIntInitialValue () |
| 62 | | | { |
| 63 | 100 | | final HashCode hashCode = new HashCode(); |
| 64 | 100 | | assertEquals("toInt should be initialized to an initial prime number", |
| 65 | | | HashCodeUtil.SEED, hashCode.toInt()); |
| 66 | | | |
| 67 | 100 | | } |
| 68 | | | |
| 69 | | | |
| 70 | | | {@link } |
| 71 | | | {@link } |
| 72 | | | {@link } |
| 73 | | | {@link } |
| 74 | | | {@link } |
| 75 | | | {@link } |
| 76 | | | |
| 77 | | | public void testHash () |
| 78 | | | { |
| 79 | 100 | | final HashCode hashCode = new HashCode(); |
| 80 | 100 | | hashCode.hash(true); |
| 81 | 100 | | hashCode.hash('?'); |
| 82 | 100 | | hashCode.hash(Math.PI); |
| 83 | 100 | | hashCode.hash(Float.POSITIVE_INFINITY); |
| 84 | 100 | | hashCode.hash(0); |
| 85 | 100 | | hashCode.hash(Byte.MAX_VALUE); |
| 86 | 100 | | hashCode.hash(Character.MAX_VALUE); |
| 87 | 100 | | hashCode.hash("foo"); |
| 88 | 100 | | hashCode.hash(null); |
| 89 | 100 | | hashCode.hash(0L); |
| 90 | 100 | | hashCode.hash(Collections.EMPTY_LIST.toArray()); |
| 91 | 100 | | hashCode.hash(Collections.singletonList("foo").toArray()); |
| 92 | 100 | | } |
| 93 | | | |
| 94 | | | } |