Sonar Fixes, Formatting
[aaf/authz.git] / misc / rosetta / src / test / java / org / onap / aaf / misc / rosetta / test / JU_Ladder.java
1 /**
2  * ============LICENSE_START====================================================
3  * org.onap.aaf
4  * ===========================================================================
5  * Copyright (c) 2018 AT&T Intellectual Property. All rights reserved.
6  * ===========================================================================
7  * Licensed under the Apache License, Version 2.0 (the "License");
8  * you may not use this file except in compliance with the License.
9  * You may obtain a copy of the License at
10  *
11  *      http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing, software
14  * distributed under the License is distributed on an "AS IS" BASIS,
15  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16  * See the License for the specific language governing permissions and
17  * limitations under the License.
18  * ============LICENSE_END====================================================
19  *
20  */
21
22 package org.onap.aaf.misc.rosetta.test;
23
24 import org.junit.Test;
25 import org.onap.aaf.misc.rosetta.Ladder;
26
27 import static org.junit.Assert.*;
28
29 public class JU_Ladder {
30
31     @Test
32     public void test() {
33         Ladder<String> ladder = new Ladder<String>();
34
35         for (int i=0;i<30;++i) {
36             for (int j=0;j<i;++j)ladder.ascend();
37             String str = "Rung " + i;
38             assertEquals(ladder.peek(),null);
39             ladder.push(str);
40             assertEquals(str,ladder.peek());
41             assertEquals(str,ladder.pop());
42             assertEquals(null,ladder.peek());
43             for (int j=0;j<i;++j)ladder.descend();
44         }
45         assertEquals(ladder.height(),32); // Sizing, when naturally created is by 8
46
47         ladder.cutTo(8);
48         assertEquals(ladder.height(),8);
49
50         for (int i=0;i<30;++i) {
51             ladder.jumpTo(i);
52             String str = "Rung " + i;
53             assertEquals(ladder.peek(),null);
54             ladder.push(str);
55             assertEquals(ladder.peek(),str);
56         }
57
58         ladder.bottom();
59
60         for (int i=0;i<30;++i) {
61             assertEquals("Rung " + i,ladder.peek());
62             ladder.ascend();
63         }
64
65         ladder.bottom();
66         ladder.top();
67         assertEquals("Rung 29",ladder.peek());
68
69         for (int i=0;i<30;++i) {
70             ladder.jumpTo(i);
71             assertEquals("Rung " + i,ladder.peek());
72         }
73
74     }
75
76 }