Debian Codegraph @

test/uk/me/parabola/imgfmt/app/srt/CombinedSortKeyTest.java

raw symbols SCIP
1 /*
2 * Copyright (C) 2011.
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License version 3 or
6 * version 2 as published by the Free Software Foundation.
7 *
8 * This program is distributed in the hope that it will be useful, but
9 * WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 * General Public License for more details.
12 */
13
14 package uk.me.parabola.imgfmt.app.srt;
15
16 import org.junit.Test;
17
18 import static org.junit.Assert.*;
19
20 public class CombinedSortKeyTest {
21
22 private static final String HELLO1 = "hello1";
23
24 @Test
25 public void testGetObject() {
26 IntegerSortKey<String> k1 = new IntegerSortKey<>(HELLO1, 1, 1);
27 CombinedSortKey<String> ck1 = new CombinedSortKey<>(k1, 2, 2);
28
29 assertEquals("retrieve original object", HELLO1, ck1.getObject());
30 }
31
32 @Test
33 public void testCompletelyEqual() {
34 IntegerSortKey<String> k1 = new IntegerSortKey<>(HELLO1, 1, 1);
35 CombinedSortKey<String> ck1 = new CombinedSortKey<>(k1, 2, 2);
36 CombinedSortKey<String> ck2 = new CombinedSortKey<>(k1, 2, 2);
37
38 assertEquals(0, ck1.compareTo(ck2));
39 }
40
41 @Test
42 public void testDifferentKey() {
43 IntegerSortKey<String> k1 = new IntegerSortKey<>(HELLO1, 1, 1);
44 IntegerSortKey<String> k2 = new IntegerSortKey<>(HELLO1, 1, 2);
45 CombinedSortKey<String> ck1 = new CombinedSortKey<>(k1, 2, 2);
46 CombinedSortKey<String> ck2 = new CombinedSortKey<>(k2, 2, 2);
47
48 assertEquals(-1, k1.compareTo(k2));
49
50 assertEquals(-1, ck1.compareTo(ck2));
51 assertEquals(1, ck2.compareTo(ck1));
52 }
53
54 @Test
55 public void testDifferentFirst() {
56 IntegerSortKey<String> k1 = new IntegerSortKey<>(HELLO1, 1, 1);
57 IntegerSortKey<String> k2 = new IntegerSortKey<>(HELLO1, 1, 1);
58 CombinedSortKey<String> ck1 = new CombinedSortKey<>(k1, 2, 2);
59 CombinedSortKey<String> ck2 = new CombinedSortKey<>(k2, 3, 2);
60
61 assertEquals(0, k1.compareTo(k2));
62
63 assertEquals(-1, ck1.compareTo(ck2));
64 assertEquals(1, ck2.compareTo(ck1));
65 }
66
67 @Test
68 public void testDifferentSecond() {
69 IntegerSortKey<String> k1 = new IntegerSortKey<>(HELLO1, 1, 1);
70 IntegerSortKey<String> k2 = new IntegerSortKey<>(HELLO1, 1, 1);
71 CombinedSortKey<String> ck1 = new CombinedSortKey<>(k1, 2, 2);
72 CombinedSortKey<String> ck2 = new CombinedSortKey<>(k2, 2, 3);
73
74 assertEquals(0, k1.compareTo(k2));
75
76 assertEquals(-1, ck1.compareTo(ck2));
77 assertEquals(1, ck2.compareTo(ck1));
78 }
79
80 @Test
81 public void testKeyOverridesFirst() {
82 IntegerSortKey<String> k1 = new IntegerSortKey<>(HELLO1, 1, 1);
83 IntegerSortKey<String> k2 = new IntegerSortKey<>(HELLO1, 2, 1);
84 CombinedSortKey<String> ck1 = new CombinedSortKey<>(k1, 3, 2);
85 CombinedSortKey<String> ck2 = new CombinedSortKey<>(k2, 2, 2);
86
87 assertEquals(-1, k1.compareTo(k2));
88
89 assertEquals(-1, ck1.compareTo(ck2));
90 assertEquals(1, ck2.compareTo(ck1));
91 }
92
93 @Test
94 public void testPrimaryOverridesSecond() {
95 IntegerSortKey<String> k1 = new IntegerSortKey<>(HELLO1, 1, 1);
96 IntegerSortKey<String> k2 = new IntegerSortKey<>(HELLO1, 1, 1);
97 CombinedSortKey<String> ck1 = new CombinedSortKey<>(k1, 2, 3);
98 CombinedSortKey<String> ck2 = new CombinedSortKey<>(k2, 3, 2);
99
100 assertEquals(0, k1.compareTo(k2));
101
102 assertEquals(-1, ck1.compareTo(ck2));
103 assertEquals(1, ck2.compareTo(ck1));
104 }
105 }