1 /*
2  * Copyright (C) 2007-2010 Júlio Vilmar Gesser.
3  * Copyright (C) 2011, 2013-2016 The JavaParser Team.
4  *
5  * This file is part of JavaParser.
6  *
7  * JavaParser can be used either under the terms of
8  * a) the GNU Lesser General Public License as published by
9  *     the Free Software Foundation, either version 3 of the License, or
10  *     (at your option) any later version.
11  * b) the terms of the Apache License
12  *
13  * You should have received a copy of both licenses in LICENCE.LGPL and
14  * LICENCE.APACHE. Please refer to those files for details.
15  *
16  * JavaParser is distributed in the hope that it will be useful,
17  * but WITHOUT ANY WARRANTY; without even the implied warranty of
18  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
19  * GNU Lesser General Public License for more details.
20  */
21 
22 package com.github.javaparser;
23 
24 import org.junit.Test;
25 
26 import java.io.IOException;
27 
28 import static org.junit.Assert.assertEquals;
29 
30 public class RangeTest {
31 
32     @Test
aRangeContainsItself()33     public void aRangeContainsItself() throws IOException {
34         Range r = Range.range(1, 1, 3, 10);
35         assertEquals(true, r.contains(r));
36     }
37 
38     @Test
aRangeDoesNotStrictlyContainsItself()39     public void aRangeDoesNotStrictlyContainsItself() throws IOException {
40         Range r = Range.range(1, 1, 3, 10);
41         assertEquals(false, r.strictlyContains(r));
42     }
43 
44     @Test
overlappingButNotContainedRangesAreNotOnContains()45     public void overlappingButNotContainedRangesAreNotOnContains() throws IOException {
46         Range r1 = Range.range(1, 1, 3, 10);
47         Range r2 = Range.range(2, 1, 7, 10);
48         assertEquals(false, r1.contains(r2));
49         assertEquals(false, r2.contains(r1));
50     }
51 
52     @Test
overlappingButNotContainedRangesAreNotOnStrictlyContains()53     public void overlappingButNotContainedRangesAreNotOnStrictlyContains() throws IOException {
54         Range r1 = Range.range(1, 1, 3, 10);
55         Range r2 = Range.range(2, 1, 7, 10);
56         assertEquals(false, r1.strictlyContains(r2));
57         assertEquals(false, r2.strictlyContains(r1));
58     }
59 
60     @Test
unrelatedRangesAreNotOnContains()61     public void unrelatedRangesAreNotOnContains() throws IOException {
62         Range r1 = Range.range(1, 1, 3, 10);
63         Range r2 = Range.range(5, 1, 7, 10);
64         assertEquals(false, r1.contains(r2));
65         assertEquals(false, r2.contains(r1));
66     }
67 
68     @Test
unrelatedRangesAreNotOnStrictlyContains()69     public void unrelatedRangesAreNotOnStrictlyContains() throws IOException {
70         Range r1 = Range.range(1, 1, 3, 10);
71         Range r2 = Range.range(5, 1, 7, 10);
72         assertEquals(false, r1.strictlyContains(r2));
73         assertEquals(false, r2.strictlyContains(r1));
74     }
75 
76     @Test
strictlyContainedRangesOnContains()77     public void strictlyContainedRangesOnContains() throws IOException {
78         Range r1 = Range.range(1, 1, 3, 10);
79         Range r2 = Range.range(2, 1, 3, 4);
80         assertEquals(true, r1.contains(r2));
81         assertEquals(false, r2.contains(r1));
82     }
83 
84     @Test
strictlyContainedRangesOnStrictlyContains()85     public void strictlyContainedRangesOnStrictlyContains() throws IOException {
86         Range r1 = Range.range(1, 1, 3, 10);
87         Range r2 = Range.range(2, 1, 3, 4);
88         assertEquals(true, r1.strictlyContains(r2));
89         assertEquals(false, r2.strictlyContains(r1));
90     }
91 
92     @Test
containsConsiderLines()93     public void containsConsiderLines() {
94         Range r1 = Range.range(22, 9, 22, 29);
95         Range r2 = Range.range(26, 19, 26, 28);
96         assertEquals(false, r1.contains(r2));
97         assertEquals(false, r2.contains(r1));
98     }
99 
100 }
101