aboutsummaryrefslogtreecommitdiffstats
path: root/vespajlib/src/test/java/com/yahoo/collections/MD5TestCase.java
blob: 7ddb49ede772839b68b79b5f216ebd90d9a763e3 (plain) (blame)
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
34
35
36
37
38
39
40
41
// Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
package com.yahoo.collections;

import org.junit.Test;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;

/**
 * @author Einar M R Rosenvinge
 */
public class MD5TestCase {

    @Test
    public void testMD5() {
        MD5 md5 = new MD5();
        int a = md5.hash("foobar");
        int b = md5.hash("foobar");

        assertEquals(a, b);

        int c = md5.hash("foo");

        assertTrue(a != c);
        assertTrue(b != c);

        //rudimentary check; see that all four bytes contain something:

        assertTrue((a & 0xFF000000) != 0);
        assertTrue((a & 0x00FF0000) != 0);
        assertTrue((a & 0x0000FF00) != 0);
        assertTrue((a & 0x000000FF) != 0);


        assertTrue((c & 0xFF000000) != 0);
        assertTrue((c & 0x00FF0000) != 0);
        assertTrue((c & 0x0000FF00) != 0);
        assertTrue((c & 0x000000FF) != 0);
    }

}