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.hamcrest.core.Is.is;
11 import static org.junit.Assert.assertThat;
13 import com.google.common.collect.Sets;
14 import java.util.List;
16 import org.junit.Test;
17 import org.opendaylight.yangtools.yang.parser.util.TopologicalSort.Node;
18 import org.opendaylight.yangtools.yang.parser.util.TopologicalSort.NodeImpl;
20 public class TopologicalSortTest {
22 @Test(expected = IllegalStateException.class)
23 public void test() throws Exception {
24 Set<Node> nodes = Sets.newHashSet();
26 NodeImpl node1 = new NodeImpl();
28 NodeImpl node2 = new NodeImpl();
30 NodeImpl node3 = new NodeImpl();
38 TopologicalSort.sort(nodes);
39 } catch (IllegalStateException e) {
45 public void testValidSimple() throws Exception {
46 Set<Node> nodes = Sets.newHashSet();
48 Node node1 = new NodeImpl();
50 Node node2 = new NodeImpl();
52 Node node3 = new NodeImpl();
54 Node node4 = new NodeImpl();
57 ((NodeImpl) node1).addEdge(node2);
58 ((NodeImpl) node1).addEdge(node3);
59 ((NodeImpl) node2).addEdge(node4);
60 ((NodeImpl) node3).addEdge(node2);
62 List<Node> sorted = TopologicalSort.sort(nodes);
64 assertThat(sorted.get(0), is(node4));
65 assertThat(sorted.get(1), is(node2));
66 assertThat(sorted.get(2), is(node3));
67 assertThat(sorted.get(3), is(node1));