1 /*******************************************************************************
2 * Copyright (c) 2017 École Polytechnique de Montréal
4 * All rights reserved. This program and the accompanying materials are
5 * made available under the terms of the Eclipse Public License v1.0 which
6 * accompanies this distribution, and is available at
7 * http://www.eclipse.org/legal/epl-v10.html
8 ******************************************************************************/
10 package org
.eclipse
.tracecompass
.internal
.datastore
.core
.condition
;
12 import static org
.junit
.Assert
.assertEquals
;
13 import static org
.junit
.Assert
.assertFalse
;
14 import static org
.junit
.Assert
.assertNotNull
;
15 import static org
.junit
.Assert
.assertTrue
;
17 import org
.eclipse
.tracecompass
.internal
.provisional
.datastore
.core
.condition
.RangeCondition
;
18 import org
.junit
.Test
;
21 * Test the continuous range condition with Integers.
23 * @author Loïc Prieur-Drevon
25 public class ContinuousRangeConditionTest
{
27 private static final int LOW
= 0;
28 private static final int HIGH
= 10;
29 private static final ContinuousRangeCondition
<Integer
> CONDITION
= new ContinuousRangeCondition
<>(LOW
, HIGH
);
32 * Ensure that we cannot build a condition with a bigger low than high bound.
34 @Test(expected
= IllegalArgumentException
.class)
35 public void testConstructor() {
36 new ContinuousRangeCondition
<>(HIGH
, LOW
);
40 * Ensure that the minimum and maximum functions return the correct values.
43 public void testBounds() {
44 int low
= CONDITION
.min();
45 assertEquals(LOW
, low
);
46 int high
= CONDITION
.max();
47 assertEquals(HIGH
, high
);
51 * Test that the right elements are contained in the condition.
54 public void testPredicate() {
55 assertFalse(CONDITION
.test(-5));
56 assertTrue(CONDITION
.test(LOW
));
57 assertTrue(CONDITION
.test(5));
58 assertTrue(CONDITION
.test(HIGH
));
59 assertFalse(CONDITION
.test(15));
63 * Test that the right intervals intersect the condition.
66 public void testIntersects() {
67 assertFalse(CONDITION
.intersects(Integer
.MIN_VALUE
, LOW
- 1));
68 assertTrue(CONDITION
.intersects(-5, 5));
69 assertTrue(CONDITION
.intersects(2, 8));
70 assertTrue(CONDITION
.intersects(5, 15));
71 assertFalse(CONDITION
.intersects(HIGH
+ 1, Integer
.MAX_VALUE
));
75 * Test that the returned subcondition has the correct bounds.
78 public void testSubCondition() {
79 RangeCondition
<Integer
> sub
= CONDITION
.subCondition(-5, 8);
81 assertEquals(ContinuousRangeCondition
.class, sub
.getClass());
84 assertEquals(LOW
, low
);
85 assertEquals(8, high
);