Search in sources :

Example 11 with Range

use of com.vaadin.flow.internal.Range in project flow by vaadin.

the class RangeTest method restrictTo_endOutside.

@Test
public void restrictTo_endOutside() {
    Range r1 = Range.between(5, 10);
    Range r2 = Range.between(4, 7);
    Range r3 = r1.restrictTo(r2);
    assertEquals(Range.between(5, 7), r3);
    assertEquals(r2.restrictTo(r1), r3);
}
Also used : Range(com.vaadin.flow.internal.Range) Test(org.junit.Test)

Example 12 with Range

use of com.vaadin.flow.internal.Range in project flow by vaadin.

the class RangeTest method emptySplitTest.

@Test
public void emptySplitTest() {
    final Range range = Range.between(5, 10);
    final Range[] split1 = range.splitAt(0);
    assertTrue("split1, [0]", split1[0].isEmpty());
    assertEquals("split1, [1]", range, split1[1]);
    final Range[] split2 = range.splitAt(15);
    assertEquals("split2, [0]", range, split2[0]);
    assertTrue("split2, [1]", split2[1].isEmpty());
}
Also used : Range(com.vaadin.flow.internal.Range) Test(org.junit.Test)

Example 13 with Range

use of com.vaadin.flow.internal.Range in project flow by vaadin.

the class RangeTest method expand_basic.

@Test
public void expand_basic() {
    Range r1 = Range.between(5, 10);
    Range r2 = r1.expand(2, 3);
    assertEquals(Range.between(3, 13), r2);
}
Also used : Range(com.vaadin.flow.internal.Range) Test(org.junit.Test)

Example 14 with Range

use of com.vaadin.flow.internal.Range in project flow by vaadin.

the class RangeTest method containsTest.

@Test
public void containsTest() {
    final int start = 0;
    final int end = 10;
    final Range range = Range.between(start, end);
    assertTrue("start should be contained", range.contains(start));
    assertTrue("start-1 should not be contained", !range.contains(start - 1));
    assertTrue("end should not be contained", !range.contains(end));
    assertTrue("end-1 should be contained", range.contains(end - 1));
    assertTrue("[0..10[ contains 5", Range.between(0, 10).contains(5));
    assertTrue("empty range does not contain 5", !Range.between(5, 5).contains(5));
}
Also used : Range(com.vaadin.flow.internal.Range) Test(org.junit.Test)

Example 15 with Range

use of com.vaadin.flow.internal.Range in project flow by vaadin.

the class RangeTest method restrictTo_empty.

@Test
public void restrictTo_empty() {
    Range r1 = Range.between(5, 10);
    Range r2 = Range.between(0, 0);
    Range r3 = r1.restrictTo(r2);
    assertTrue(r3.isEmpty());
    Range r4 = r2.restrictTo(r1);
    assertTrue(r4.isEmpty());
}
Also used : Range(com.vaadin.flow.internal.Range) Test(org.junit.Test)

Aggregations

Range (com.vaadin.flow.internal.Range)33 Test (org.junit.Test)28 ArrayList (java.util.ArrayList)5 Comparator (java.util.Comparator)4 List (java.util.List)4 Objects (java.util.Objects)4 Collectors (java.util.stream.Collectors)4 Stream (java.util.stream.Stream)4 SerializablePredicate (com.vaadin.flow.function.SerializablePredicate)3 Arrays (java.util.Arrays)3 Collection (java.util.Collection)3 HashSet (java.util.HashSet)3 UI (com.vaadin.flow.component.UI)2 IntStream (java.util.stream.IntStream)2 Assert (org.junit.Assert)2 Assert.assertEquals (org.junit.Assert.assertEquals)2 Assert.assertTrue (org.junit.Assert.assertTrue)2 Before (org.junit.Before)2 Rule (org.junit.Rule)2 ExpectedException (org.junit.rules.ExpectedException)2