2 * Copyright (c) 2013 Cisco Systems, Inc. and others. All rights reserved.
4 * This program and the accompanying materials are made available under the
5 * terms of the Eclipse Public License v1.0 which accompanies this distribution,
6 * and is available at http://www.eclipse.org/legal/epl-v10.html
8 package org.opendaylight.yangtools.yang.parser.util;
10 import static org.junit.Assert.assertEquals;
12 import com.google.common.collect.Sets;
14 import java.util.List;
17 import org.junit.Test;
18 import org.opendaylight.yangtools.yang.parser.util.TopologicalSort.Node;
19 import org.opendaylight.yangtools.yang.parser.util.TopologicalSort.NodeImpl;
21 public class TopologicalSortTest {
23 @Test(expected = IllegalStateException.class)
24 public void test() throws Exception {
25 Set<Node> nodes = Sets.newHashSet();
27 NodeImpl node1 = new NodeImpl();
29 NodeImpl node2 = new NodeImpl();
31 NodeImpl node3 = new NodeImpl();
38 // We expect an IllegalStateException here
39 TopologicalSort.sort(nodes);
43 public void testValidSimple() throws Exception {
44 Set<Node> nodes = Sets.newHashSet();
46 Node node1 = new NodeImpl();
48 Node node2 = new NodeImpl();
50 Node node3 = new NodeImpl();
52 Node node4 = new NodeImpl();
55 ((NodeImpl) node1).addEdge(node2);
56 ((NodeImpl) node1).addEdge(node3);
57 ((NodeImpl) node2).addEdge(node4);
58 ((NodeImpl) node3).addEdge(node2);
60 List<Node> sorted = TopologicalSort.sort(nodes);
62 assertEquals(node4, sorted.get(0));
63 assertEquals(node2, sorted.get(1));
64 assertEquals(node3, sorted.get(2));
65 assertEquals(node1, sorted.get(3));