summaryrefslogtreecommitdiffstats
path: root/vespajlib/src/test/java/com/yahoo/collections/IntRangeTestCase.java
blob: dc3c39ea19b4a42c591da03b055973c884e2dc60 (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
package com.yahoo.collections;

import org.junit.Test;

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

/**
 * @author bratseth
 */
public class IntRangeTestCase {

    @Test
    public void testStringAndEquals() {
        assertEquals(IntRange.empty(), IntRange.from(IntRange.from("[]").toString()));
        assertEquals(IntRange.from(1), IntRange.from(IntRange.from("[1,]").toString()));
        assertEquals(IntRange.to(3), IntRange.from(IntRange.from("[,3]").toString()));
        assertEquals(IntRange.of(1, 3), IntRange.from(IntRange.from("[1,3]").toString()));
        assertEquals(IntRange.of(1, 3), IntRange.from(IntRange.from("[1, 3]").toString()));
    }

    @Test
    public void testInclusion() {
        assertFalse(IntRange.of(3, 5).includes(2));
        assertTrue(IntRange.of(3, 5).includes(3));
        assertTrue(IntRange.of(3, 5).includes(4));
        assertTrue(IntRange.of(3, 5).includes(5));
        assertFalse(IntRange.of(3, 5).includes(6));

        assertTrue(IntRange.from(3).includes(1000));
        assertFalse(IntRange.from(3).includes(2));

        assertTrue(IntRange.to(5).includes(-1000));
        assertFalse(IntRange.to(3).includes(4));
    }

}