f05fc14fa2f4f7fdcf3bac8aaae19f74370f4c5a
[deliverable/tracecompass.git] / statesystem / org.eclipse.tracecompass.datastore.core.tests / src / org / eclipse / tracecompass / internal / datastore / core / condition / ContinuousRangeConditionTest.java
1 /*******************************************************************************
2 * Copyright (c) 2017 École Polytechnique de Montréal
3 *
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 ******************************************************************************/
9
10 package org.eclipse.tracecompass.internal.datastore.core.condition;
11
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;
16
17 import org.eclipse.tracecompass.internal.provisional.datastore.core.condition.RangeCondition;
18 import org.junit.Test;
19
20 /**
21 * Test the continuous range condition with Integers.
22 *
23 * @author Loïc Prieur-Drevon
24 */
25 public class ContinuousRangeConditionTest {
26
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);
30
31 /**
32 * Ensure that we cannot build a condition with a bigger low than high bound.
33 */
34 @Test(expected = IllegalArgumentException.class)
35 public void testConstructor() {
36 new ContinuousRangeCondition<>(HIGH, LOW);
37 }
38
39 /**
40 * Ensure that the minimum and maximum functions return the correct values.
41 */
42 @Test
43 public void testBounds() {
44 int low = CONDITION.min();
45 assertEquals(LOW, low);
46 int high = CONDITION.max();
47 assertEquals(HIGH, high);
48 }
49
50 /**
51 * Test that the right elements are contained in the condition.
52 */
53 @Test
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));
60 }
61
62 /**
63 * Test that the right intervals intersect the condition.
64 */
65 @Test
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));
72 }
73
74 /**
75 * Test that the returned subcondition has the correct bounds.
76 */
77 @Test
78 public void testSubCondition() {
79 RangeCondition<Integer> sub = CONDITION.subCondition(-5, 8);
80 assertNotNull(sub);
81 assertEquals(ContinuousRangeCondition.class, sub.getClass());
82 int low = sub.min();
83 int high = sub.max();
84 assertEquals(LOW, low);
85 assertEquals(8, high);
86 }
87
88 }
This page took 0.045621 seconds and 4 git commands to generate.