Skip to main content
summaryrefslogtreecommitdiffstats
blob: 278a53a860179b0b24a72efb259cb4a32053befc (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
/*******************************************************************************
 * Copyright (c) 2014 Boeing.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 *
 * Contributors:
 *     Boeing - initial API and implementation
 *******************************************************************************/
package org.eclipse.osee.orcs.core.internal.branch;

import java.util.LinkedList;
import java.util.List;
import org.eclipse.osee.framework.core.enums.BranchState;
import org.eclipse.osee.framework.core.enums.BranchType;
import org.eclipse.osee.framework.core.model.Branch;
import org.eclipse.osee.framework.jdk.core.util.GUID;
import org.junit.Assert;
import org.junit.Test;

/**
 * @author David W. Miller
 */
public class BranchUtilBranchTest {

   private final Branch one = new Branch(GUID.create(), "one", BranchType.WORKING, BranchState.COMMITTED, true);
   private final Branch two = new Branch(GUID.create(), "two", BranchType.WORKING, BranchState.COMMITTED, true);
   private final Branch three = new Branch(GUID.create(), "three", BranchType.WORKING, BranchState.COMMITTED, true);
   private final Branch four = new Branch(GUID.create(), "four", BranchType.WORKING, BranchState.COMMITTED, true);
   private final Branch five = new Branch(GUID.create(), "five", BranchType.WORKING, BranchState.COMMITTED, true);
   private final Branch six = new Branch(GUID.create(), "six", BranchType.WORKING, BranchState.COMMITTED, true);
   private final Branch seven = new Branch(GUID.create(), "seven", BranchType.WORKING, BranchState.COMMITTED, true);
   private final Branch eight = new Branch(GUID.create(), "eight", BranchType.WORKING, BranchState.COMMITTED, true);
   private final Branch nine = new Branch(GUID.create(), "nine", BranchType.WORKING, BranchState.COMMITTED, true);
   private final Branch ten = new Branch(GUID.create(), "ten", BranchType.WORKING, BranchState.COMMITTED, true);
   private final Branch outside = new Branch(GUID.create(), "outside", BranchType.WORKING, BranchState.COMMITTED, true);

   private void initBranchParentageList() {
      two.setParentBranch(one);
      three.setParentBranch(two);
      four.setParentBranch(three);
      five.setParentBranch(four);
      six.setParentBranch(five);
      seven.setParentBranch(six);
      eight.setParentBranch(seven);
      nine.setParentBranch(eight);
      ten.setParentBranch(nine);
   }

   private void initDisjointParentageList() {
      two.setParentBranch(one);
      three.setParentBranch(two);
      four.setParentBranch(three);
      five.setParentBranch(one);
      six.setParentBranch(five);
      seven.setParentBranch(six);
      eight.setParentBranch(one);
      nine.setParentBranch(eight);
      ten.setParentBranch(nine);
   }

   private void initOutsideParentList() {
      one.setParentBranch(outside);
      two.setParentBranch(one);
      three.setParentBranch(two);
      four.setParentBranch(three);
      five.setParentBranch(outside);
      six.setParentBranch(five);
      seven.setParentBranch(six);
      eight.setParentBranch(outside);
      nine.setParentBranch(eight);
      ten.setParentBranch(nine);
   }

   private void initDisjointOrderList(List<Branch> branchList) {
      branchList.add(0, two);
      branchList.add(1, three);
      branchList.add(2, four);
      branchList.add(3, five);
      branchList.add(4, six);
      branchList.add(5, seven);
      branchList.add(6, eight);
      branchList.add(7, nine);
      branchList.add(8, ten);
      branchList.add(9, one);
   }

   private void initOutOfOrderList(List<Branch> branchList) {
      branchList.add(0, three);
      branchList.add(1, eight);
      branchList.add(2, one);
      branchList.add(3, four);
      branchList.add(4, five);
      branchList.add(5, six);
      branchList.add(6, ten);
      branchList.add(7, nine);
      branchList.add(8, two);
      branchList.add(9, seven);
   }

   @Test
   public void testConnectedBranchSorting() {
      List<Branch> branchList = new LinkedList<Branch>();
      initBranchParentageList();
      initOutOfOrderList(branchList);
      List<Branch> ordered = BranchUtil.orderByParent(branchList);
      Assert.assertEquals("[ten, nine, eight, seven, six, five, four, three, two, one]", ordered.toString());
   }

   @Test
   public void testDisjointBranchSorting() {
      List<Branch> branchList = new LinkedList<Branch>();
      initDisjointParentageList();
      initDisjointOrderList(branchList);
      List<Branch> ordered = BranchUtil.orderByParent(branchList);
      Assert.assertEquals("[four, three, two, seven, six, five, ten, nine, eight, one]", ordered.toString());
   }

   @Test
   public void testDisjointOutOfOrderBranchSorting() {
      List<Branch> branchList = new LinkedList<Branch>();
      initDisjointParentageList();
      initOutOfOrderList(branchList);
      List<Branch> ordered = BranchUtil.orderByParent(branchList);
      Assert.assertEquals("[four, ten, seven, three, six, nine, eight, two, five, one]", ordered.toString());
   }

   @Test
   public void testOutsideParentsBranchSorting() {
      List<Branch> branchList = new LinkedList<Branch>();
      initOutsideParentList();
      initOutOfOrderList(branchList);
      List<Branch> ordered = BranchUtil.orderByParent(branchList);
      Assert.assertEquals("[four, ten, three, two, seven, six, nine, eight, one, five]", ordered.toString());
   }
}

Back to the top