1 | /* -*- C++ -*- |
---|
2 | * |
---|
3 | * This file is a part of LEMON, a generic C++ optimization library |
---|
4 | * |
---|
5 | * Copyright (C) 2003-2006 |
---|
6 | * Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport |
---|
7 | * (Egervary Research Group on Combinatorial Optimization, EGRES). |
---|
8 | * |
---|
9 | * Permission to use, modify and distribute this software is granted |
---|
10 | * provided that this copyright notice appears in all copies. For |
---|
11 | * precise terms see the accompanying LICENSE file. |
---|
12 | * |
---|
13 | * This software is provided "AS IS" with no warranty of any kind, |
---|
14 | * express or implied, and with no claim as to its suitability for any |
---|
15 | * purpose. |
---|
16 | * |
---|
17 | */ |
---|
18 | |
---|
19 | #include <string> |
---|
20 | #include <iostream> |
---|
21 | |
---|
22 | #include <lemon/concepts/path.h> |
---|
23 | #include <lemon/concepts/graph.h> |
---|
24 | |
---|
25 | #include <lemon/path.h> |
---|
26 | #include <lemon/list_graph.h> |
---|
27 | |
---|
28 | #include "test_tools.h" |
---|
29 | |
---|
30 | using namespace std; |
---|
31 | using namespace lemon; |
---|
32 | |
---|
33 | void check_concepts() { |
---|
34 | checkConcept<concepts::Path<concepts::Graph>, |
---|
35 | concepts::Path<concepts::Graph> >(); |
---|
36 | checkConcept<concepts::Path<concepts::Graph>, |
---|
37 | Path<concepts::Graph> >(); |
---|
38 | checkConcept<concepts::Path<ListGraph>, Path<ListGraph> >(); |
---|
39 | } |
---|
40 | |
---|
41 | int main() { |
---|
42 | check_concepts(); |
---|
43 | |
---|
44 | ListGraph g; |
---|
45 | |
---|
46 | ListGraph::Node n1 = g.addNode(); |
---|
47 | ListGraph::Node n2 = g.addNode(); |
---|
48 | ListGraph::Node n3 = g.addNode(); |
---|
49 | ListGraph::Node n4 = g.addNode(); |
---|
50 | ListGraph::Node n5 = g.addNode(); |
---|
51 | |
---|
52 | ListGraph::Edge e1 = g.addEdge(n1, n2); |
---|
53 | ListGraph::Edge e2 = g.addEdge(n2, n3); |
---|
54 | ListGraph::Edge e3 = g.addEdge(n3, n4); |
---|
55 | ListGraph::Edge e4 = g.addEdge(n4, n5); |
---|
56 | ListGraph::Edge e5 = g.addEdge(n5, n1); |
---|
57 | |
---|
58 | { |
---|
59 | Path<ListGraph> p(g); |
---|
60 | |
---|
61 | check(p.empty(), "Wrong Path"); |
---|
62 | check(p.length() == 0, "Wrong Path"); |
---|
63 | |
---|
64 | { |
---|
65 | Path<ListGraph>::Builder b(p); |
---|
66 | b.setStartNode(n3); |
---|
67 | b.commit(); |
---|
68 | } |
---|
69 | |
---|
70 | check(!p.empty(), "Wrong Path"); |
---|
71 | check(p.length() == 0, "Wrong Path"); |
---|
72 | check(p.source() == n3, "Wrong Path"); |
---|
73 | check(p.target() == n3, "Wrong Path"); |
---|
74 | |
---|
75 | { |
---|
76 | Path<ListGraph>::Builder b(p); |
---|
77 | b.pushBack(e3); |
---|
78 | b.pushBack(e4); |
---|
79 | b.pushFront(e2); |
---|
80 | b.commit(); |
---|
81 | } |
---|
82 | |
---|
83 | check(!p.empty(), "Wrong Path"); |
---|
84 | check(p.length() == 3, "Wrong Path"); |
---|
85 | check(p.source() == n2, "Wrong Path"); |
---|
86 | check(p.target() == n5, "Wrong Path"); |
---|
87 | |
---|
88 | { |
---|
89 | Path<ListGraph>::NodeIt it(p); |
---|
90 | check((ListGraph::Node)it == n2, "Wrong Path"); ++it; |
---|
91 | check((ListGraph::Node)it == n3, "Wrong Path"); ++it; |
---|
92 | check((ListGraph::Node)it == n4, "Wrong Path"); ++it; |
---|
93 | check((ListGraph::Node)it == n5, "Wrong Path"); ++it; |
---|
94 | check((ListGraph::Node)it == INVALID, "Wrong Path"); |
---|
95 | } |
---|
96 | |
---|
97 | { |
---|
98 | Path<ListGraph>::EdgeIt it(p); |
---|
99 | check((ListGraph::Edge)it == e2, "Wrong Path"); ++it; |
---|
100 | check((ListGraph::Edge)it == e3, "Wrong Path"); ++it; |
---|
101 | check((ListGraph::Edge)it == e4, "Wrong Path"); ++it; |
---|
102 | check((ListGraph::Edge)it == INVALID, "Wrong Path"); |
---|
103 | } |
---|
104 | |
---|
105 | } |
---|
106 | |
---|
107 | return 0; |
---|
108 | } |
---|