1 /***
2 * Ambient - A music player for the Android platform
3 Copyright (C) 2007 Martin Vysny
4
5 This program is free software: you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation, either version 3 of the License, or
8 (at your option) any later version.
9
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
14
15 You should have received a copy of the GNU General Public License
16 along with this program. If not, see <http://www.gnu.org/licenses/>.
17 */
18
19 package sk.baka.ambient.commons;
20
21 import junit.framework.TestCase;
22
23 /***
24 * Tests the {@link Interval} class.
25 *
26 * @author Martin Vysny
27 */
28 public class IntervalTest extends TestCase {
29 /***
30 * Tests the {@link Interval#subtract(Interval)} method.
31 */
32 public void testSubtractOuter() {
33 assertEquals(Interval.fromRange(2, 3), Interval.fromRange(2, 3)
34 .subtract(Interval.fromRange(5, 10)));
35 assertEquals(Interval.fromRange(2, 3), Interval.fromRange(2, 3)
36 .subtract(Interval.fromRange(4, 10)));
37 assertEquals(Interval.fromItem(2), Interval.fromRange(2, 3).subtract(
38 Interval.fromRange(3, 10)));
39 assertEquals(Interval.EMPTY, Interval.fromRange(2, 3).subtract(
40 Interval.fromRange(2, 10)));
41 assertEquals(Interval.EMPTY, Interval.fromRange(2, 3).subtract(
42 Interval.fromRange(1, 10)));
43 assertEquals(Interval.EMPTY, Interval.fromRange(2, 3).subtract(
44 Interval.fromRange(0, 10)));
45 assertEquals(Interval.EMPTY, Interval.fromRange(2, 3).subtract(
46 Interval.fromRange(0, 3)));
47 assertEquals(Interval.fromItem(3), Interval.fromRange(2, 3).subtract(
48 Interval.fromRange(0, 2)));
49 assertEquals(Interval.fromRange(2, 3), Interval.fromRange(2, 3)
50 .subtract(Interval.fromRange(0, 1)));
51 assertEquals(Interval.fromRange(2, 3), Interval.fromRange(2, 3)
52 .subtract(Interval.EMPTY));
53 }
54
55 /***
56 * Tests the {@link Interval#subtract(Interval)} method.
57 */
58 public void testSubtractInner() {
59 assertEquals(Interval.fromRange(2, 4), Interval.fromRange(2, 5)
60 .subtract(Interval.fromRange(5, 10)));
61 assertEquals(Interval.fromRange(2, 3), Interval.fromRange(2, 5)
62 .subtract(Interval.fromRange(4, 10)));
63 assertEquals(Interval.fromRange(2, 3), Interval.fromRange(2, 5)
64 .subtract(Interval.fromRange(4, 5)));
65 Interval[] result = (Interval[]) Interval.fromRange(2, 5).subtract(
66 Interval.fromRange(4, 4));
67 assertEquals(Interval.fromRange(2, 3), result[0]);
68 assertEquals(Interval.fromRange(5, 5), result[1]);
69 assertEquals(Interval.fromRange(4, 5), Interval.fromRange(2, 5)
70 .subtract(Interval.fromRange(2, 3)));
71 assertEquals(Interval.fromRange(4, 5), Interval.fromRange(2, 5)
72 .subtract(Interval.fromRange(0, 3)));
73 assertEquals(Interval.fromRange(2, 5), Interval.fromRange(2, 5)
74 .subtract(Interval.fromRange(0, 1)));
75 }
76 }