Skip to content

Commit c79ba0a

Browse files
committed
Solution to P82
1 parent edff848 commit c79ba0a

File tree

2 files changed

+26
-6
lines changed

2 files changed

+26
-6
lines changed

src/main/scala/graphs/P82/P82Digraph.scala

+13-3
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,13 @@
1+
/*******************************************************************************
2+
* Copyright (c) 2014 Guillaume DUBUISSON DUPLESSIS <guillaume.dubuisson_duplessis@insa-rouen.fr>.
3+
* All rights reserved. This program and the accompanying materials
4+
* are made available under the terms of the GNU Public License v3.0
5+
* which accompanies this distribution, and is available at
6+
* http://www.gnu.org/licenses/gpl.html
7+
*
8+
* Contributors:
9+
* Guillaume DUBUISSON DUPLESSIS <guillaume.dubuisson_duplessis@insa-rouen.fr> - initial API and implementation
10+
******************************************************************************/
111
package graphs.P82
212

313
import util.ExerciseTemplate
@@ -13,12 +23,12 @@ trait P82Digraph extends ExerciseTemplate with Digraphs with digraph.EdgesAsPair
1323
res0: List[List[String]] = List(List(f, c, b, f), List(f, b, c, f))
1424
*/
1525
val name = "P82 (Cycle from a given node)"
16-
def findsCycles(graph: Digraph, start: Node, end: Node): List[List[Node]]
26+
def findsCycles(graph: Digraph, start: Node): List[List[Node]]
1727

1828
type Node = Char
1929
test("Invoking findsCycles with the same start and end node should not return a cycle") {
2030
val graph = newGraph(Set('a'), Set())
21-
assert(findsCycles(graph, 'a', 'a') == List())
31+
assert(findsCycles(graph, 'a') == List())
2232
}
2333

2434
test("Invoking findsCycles should return all the cycles starting at a given node") {
@@ -31,7 +41,7 @@ trait P82Digraph extends ExerciseTemplate with Digraphs with digraph.EdgesAsPair
3141
*/
3242
val graph = newGraph(Set('a', 'b', 'c', 'd'), Set(('a', 'b'), ('b', 'c'), ('b', 'd'), ('c', 'd'), ('c', 'a'), ('d', 'a')))
3343

34-
val cycles = findsCycles(graph, 'a', 'd')
44+
val cycles = findsCycles(graph, 'b')
3545
assert(cycles.size == 3)
3646
assert(cycles.contains(List('b', 'd', 'a', 'b')))
3747
assert(cycles.contains(List('b', 'c', 'd', 'a', 'b')))

src/main/scala/graphs/P82/P82Graph.scala

+13-3
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,13 @@
1+
/*******************************************************************************
2+
* Copyright (c) 2014 Guillaume DUBUISSON DUPLESSIS <guillaume.dubuisson_duplessis@insa-rouen.fr>.
3+
* All rights reserved. This program and the accompanying materials
4+
* are made available under the terms of the GNU Public License v3.0
5+
* which accompanies this distribution, and is available at
6+
* http://www.gnu.org/licenses/gpl.html
7+
*
8+
* Contributors:
9+
* Guillaume DUBUISSON DUPLESSIS <guillaume.dubuisson_duplessis@insa-rouen.fr> - initial API and implementation
10+
******************************************************************************/
111
package graphs.P82
212

313
import util.ExerciseTemplate
@@ -13,12 +23,12 @@ trait P82Graph extends ExerciseTemplate with Graphs with graph.EdgesAsPairs {
1323
res0: List[List[String]] = List(List(f, c, b, f), List(f, b, c, f))
1424
*/
1525
val name = "P82 (Cycle from a given node)"
16-
def findsCycles(graph: Graph, start: Node, end: Node): List[List[Node]]
26+
def findsCycles(graph: Graph, start: Node): List[List[Node]]
1727

1828
type Node = Char
1929
test("Invoking findsCycles with the same start and end node should not return a cycle") {
2030
val graph = newGraph(Set('a'), Set())
21-
assert(findsCycles(graph, 'a', 'a') == List())
31+
assert(findsCycles(graph, 'a') == List())
2232
}
2333

2434
test("Invoking findsCycles should return all the cycles starting at a given node") {
@@ -31,7 +41,7 @@ trait P82Graph extends ExerciseTemplate with Graphs with graph.EdgesAsPairs {
3141
*/
3242
val graph = newGraph(Set('a', 'b', 'c', 'd'), Set(('a', 'b'), ('b', 'c'), ('b', 'd'), ('c', 'd'), ('c', 'a'), ('d', 'a')))
3343

34-
val cycles = findsCycles(graph, 'a', 'd')
44+
val cycles = findsCycles(graph, 'b')
3545
assert(cycles.size == 15)
3646
assert(cycles.contains(List('b', 'a', 'c', 'd', 'b')))
3747
assert(cycles.contains(List('b', 'd', 'c', 'a', 'b')))

0 commit comments

Comments
 (0)