4
* Copyright (c) 2012, CloudBees, Inc.
6
* Permission is hereby granted, free of charge, to any person obtaining a copy
7
* of this software and associated documentation files (the "Software"), to deal
8
* in the Software without restriction, including without limitation the rights
9
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10
* copies of the Software, and to permit persons to whom the Software is
11
* furnished to do so, subject to the following conditions:
13
* The above copyright notice and this permission notice shall be included in
14
* all copies or substantial portions of the Software.
16
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
24
package jenkins.model.lazy;
26
import org.junit.Assert;
27
import org.junit.Test;
29
import java.util.ArrayList;
30
import java.util.Arrays;
33
* @author Kohsuke Kawaguchi
35
public class SortedListTest extends Assert {
36
SortedList<String> l = new SortedList<String>(new ArrayList<String>(Arrays.asList("B","D","F")));
39
public void testCeil() {
40
assertEquals(0,l.ceil("A"));
41
assertEquals(0,l.ceil("B"));
42
assertEquals(1,l.ceil("C"));
43
assertEquals(1,l.ceil("D"));
44
assertEquals(2,l.ceil("E"));
45
assertEquals(2,l.ceil("F"));
46
assertEquals(3,l.ceil("G"));
50
public void testFloor() {
51
assertEquals(-1,l.floor("A"));
52
assertEquals(0,l.floor("B"));
53
assertEquals(0,l.floor("C"));
54
assertEquals(1,l.floor("D"));
55
assertEquals(1,l.floor("E"));
56
assertEquals(2,l.floor("F"));
57
assertEquals(2,l.floor("G"));
61
public void testLower() {
62
assertEquals(-1,l.lower("A"));
63
assertEquals(-1,l.lower("B"));
64
assertEquals(0,l.lower("C"));
65
assertEquals(0,l.lower("D"));
66
assertEquals(1,l.lower("E"));
67
assertEquals(1,l.lower("F"));
68
assertEquals(2,l.lower("G"));
72
public void testHigher() {
73
assertEquals(0,l.higher("A"));
74
assertEquals(1,l.higher("B"));
75
assertEquals(1,l.higher("C"));
76
assertEquals(2,l.higher("D"));
77
assertEquals(2,l.higher("E"));
78
assertEquals(3,l.higher("F"));
79
assertEquals(3,l.higher("G"));
83
public void testRange() {
84
assertTrue(l.isInRange(0));
85
assertTrue(l.isInRange(1));
86
assertTrue(l.isInRange(2));
88
assertFalse(l.isInRange(-1));
89
assertFalse(l.isInRange(3));
93
public void remove() {
94
l.remove("nosuchthing");
95
assertEquals(3,l.size());
98
assertEquals(2, l.size());
99
assertEquals("D",l.get(0));
100
assertEquals("F",l.get(1));
104
public void testClone() {
105
final int originalSize = l.size();
106
SortedList<String> l2 = new SortedList<String>(l);
107
assertEquals(originalSize, l2.size());
108
assertEquals(originalSize, l.size());
109
for (int i = 0; i < originalSize; i++) {
110
assertEquals(l.get(i), l2.get(i));
113
assertEquals(originalSize - 1, l.size());
114
assertEquals(originalSize, l2.size());
117
assertEquals(originalSize - 1, l.size());
118
assertEquals(originalSize - 2, l2.size());