aboutsummaryrefslogtreecommitdiffstats
path: root/config-provisioning/src/test/java/com/yahoo/config/provision/IntRangeTestCase.java
blob: ee1c8daa2134a8928125fb8c654fe14e983204f7 (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
// Copyright Vespa.ai. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
package com.yahoo.config.provision;

import org.junit.jupiter.api.Test;

import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.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));
    }

}