Commit c7b5e7ea authored by Jim Newton's avatar Jim Newton

initial files

parents
.idea/*
target/
src/main/scala/hwSolution
*~
name := "scalain-e-course-code"
version := "0.1"
scalaVersion := "2.12.8"
libraryDependencies += "junit" % "junit" % "4.10" % "test"
libraryDependencies += "org.scalactic" %% "scalactic" % "3.0.5"
libraryDependencies += "org.scalatest" %% "scalatest" % "3.0.5" % "test"
libraryDependencies += "org.scala-lang.plugins" %% "scala-continuations-library" % "1.0.3"
libraryDependencies += "org.scalacheck" %% "scalacheck" % "1.14.0" % "test"
libraryDependencies += "org.scalafx" %% "scalafx" % "8.0.144-R12"
// added the following lines as per advice from
// https://stackoverflow.com/questions/57628274/sbt-wont-compile-helloworld-scalafx-example-complains-about-javafx-missing-fro/57628433#57628433
// begin
lazy val osName = System.getProperty("os.name") match {
case n if n.startsWith("Linux") => "linux"
case n if n.startsWith("Mac") => "mac"
case n if n.startsWith("Windows") => "win"
case _ => throw new Exception("Unknown platform!")
}
// Add JavaFX dependencies
lazy val javaFXModules = Seq("base", "controls", "fxml", "graphics", "media", "swing", "web")
libraryDependencies ++= javaFXModules.map( m=>
"org.openjfx" % s"javafx-$m" % "11" classifier osName
)
// end
val circeVersion = "0.12.3"
libraryDependencies ++= Seq(
"io.circe" %% "circe-core",
"io.circe" %% "circe-generic",
"io.circe" %% "circe-parser"
).map(_ % circeVersion)
\ No newline at end of file
sbt.version = 1.2.8
\ No newline at end of file
// Copyright (c) 2020 EPITA Research and Development Laboratory
//
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation
// files (the "Software"), to deal in the Software without restriction,
// including without limitation the rights to use, copy, modify, merge,
// publish, distribute, sublicense, and/or sell copies of the Software,
// and to permit persons to whom the Software is furnished to do so,
// subject to the following conditions:
//
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
package lecture
object Greeting {
def hello() = {
println("hello world ")
}
def main(argv:Array[String]) = {
}
}
// Copyright (c) 2020 EPITA Research and Development Laboratory
//
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation
// files (the "Software"), to deal in the Software without restriction,
// including without limitation the rights to use, copy, modify, merge,
// publish, distribute, sublicense, and/or sell copies of the Software,
// and to permit persons to whom the Software is furnished to do so,
// subject to the following conditions:
//
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
package lecture
object Recursion {
def sumIntegersBySimpleRecursion(ints: List[Int]): Int = {
ints match {
case List() => 0
// common variable names are also h::t or head::tail or first::rest
case i :: is => i + sumIntegersBySimpleRecursion(is)
}
}
def sumIntegersByTailRecursion(ints: List[Int]): Int = {
def sumRest(acc: Int, rest: List[Int]): Int = {
rest match {
case List() => acc
case i :: is => sumRest(acc + i, is)
}
}
sumRest(0, ints)
}
def sumIntegersByFold(ints: List[Int]): Int = {
ints.fold(0)(_ + _)
}
def genLongList(len:Int, value:Double):List[Double] = {
List.tabulate(len)(_ => value)
}
def main(argv:Array[String]):Unit = {
val longList = List.tabulate(5673)(n => 0)
println(s"sum = ${sumIntegersBySimpleRecursion(longList)}")
}
}
This diff is collapsed.
// Copyright (c) 2020 EPITA Research and Development Laboratory
//
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation
// files (the "Software"), to deal in the Software without restriction,
// including without limitation the rights to use, copy, modify, merge,
// publish, distribute, sublicense, and/or sell copies of the Software,
// and to permit persons to whom the Software is furnished to do so,
// subject to the following conditions:
//
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
package homework
// Assignment name: Implement a simple function
//
// This homework assignment accompanies section "Basics".
// The test cases can be found in the file GreetingTestSuite.scala
// You should complete the function, replacing ??? with correct Scala
// code so that the tests pass.
object Greeting {
def hello(name:String) = {
println(???)
}
def main(argv:Array[String]) = {
}
}
// Copyright (c) 2020 EPITA Research and Development Laboratory
//
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation
// files (the "Software"), to deal in the Software without restriction,
// including without limitation the rights to use, copy, modify, merge,
// publish, distribute, sublicense, and/or sell copies of the Software,
// and to permit persons to whom the Software is furnished to do so,
// subject to the following conditions:
//
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
package homework
import lecture.Recursion._
// Assignment name: Recursion excercise
//
// This homework assignment accompanies section "Recursion".
// The test cases can be found in the file RecursionTestSuite.scala
// You should complete the functions, replacing ??? with correct Scala
// code so that the tests pass.
//
// In the lecture we developed three functions for summing a list of
// integers. Three different techniques were used. In this assignment
// you should use similar techniques to create three functions to sum a
// list of Double, and also to find the product of a list of Double.
object Recursion {
// follow the examples from the lecture to create the following functions
// sumDoublesBySimpleRecursion()
// sumDoublesByTailRecursion()
// sumDoublesByFold()
//
// and also
//
// productDoublesBySimpleRecursion()
// productDoublesByTailRecursion()
// productDoublesByFold()
def sumDoublesBySimpleRecursion(doubles: List[Double]): Double = {
doubles match {
case List() => ???
case d :: ds => ??? + sumDoublesBySimpleRecursion(???)
}
}
def sumDoublesByTailRecursion(doubles: List[Double]): Double = {
def sumRest(acc: Double, rest: List[Double]): Double = {
???
}
}
sumRest(???, ???)
}
def sumDoublesByFold(doubles: List[Double]): Double = {
doubles.fold(??)(???)
}
def productDoublesBySimpleRecursion(doubles: List[Double]): Double = {
doubles match {
???
}
}
def productDoublesByTailRecursion(doubles: List[Double]): Double = {
def productRest (acc: Double, rest: List[Double] ): Double = {
???
}
???
}
def productDoublesByFold(doubles: List[Double]): Double = {
???
}
}
// Copyright (c) 2020 EPITA Research and Development Laboratory
//
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation
// files (the "Software"), to deal in the Software without restriction,
// including without limitation the rights to use, copy, modify, merge,
// publish, distribute, sublicense, and/or sell copies of the Software,
// and to permit persons to whom the Software is furnished to do so,
// subject to the following conditions:
//
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
package homework
// In this exercise, you should take one of the makeAdj_* functions
// developed in the lecture, and change the name to makeAdj.
// You must choose one which fulfills the requirements and satisfies
// the test cases.
//
// ATTENTION: do not use any mutation in this assignment. You will not
// receive credit for the assignment if you use mutation.
//
// Your functions will manipulate a graph which may be DIRECTED or
// UNDIRECTED, and whose vertices may be any type. But any one graph
// contains only edges of the same type. E.g., no graph will have
// some vertices which are String and others which are Int.
// The graph will be specified by its edges. Each edge is a
// pair of vertices.
// There are no self loops, I.e., no edge has the same source and destination.
// And there is at most one edge between any two vertices.
// The graph has no isolated vertices.
// The graph is not guaranteed to be connected.
//
// The function makeAdj should take 2 arguments, edges and directed.
// directed is a boolean indicating whether the edges should
// be interpreted as directed or undirected.
// edges should be a parameter capable of receiving a List of any
// type or an Array of any type. I.e., edges specifies a *collection*
// of pairs of vertices. And the vertices may be String, Integer, Double,
// List, Array, any type at all, but all vertices are the same type
// on any one call to makeAdj.
// In the case that the graph is DIRECTED, there may be vertices
// which have no successors. For example there might be an edge from 1 to 2
// but no edge started at 2. In this case the Map returned from makeAdj
// should contain 1 -> Set(... 2 ...), but should not contain 2 -> Set().
//
// Implement the function reachableVertices which takes a parameter representing
// the graph edges. The function should return a Set of vertices which
// can be reached starting from the given starting vertex by tracing edges.
// Edges are traced in a directed sense if the graph is DIRECTED, and edges
// may be trace in both directions if the graph is UNDIRECTED.
// The function should implement a breadth-first search starting at
// the given vertex, to collect a set of vertices that are reachable from
// that starting vertex. E.g., if a graph has only two edges (1,2) and (3,4)
// then 1 and 2 are reachable starting with 1; 3 and 4 are reachable starting
// with 3. If the graph is directed then only 4 is reachable starting with 4,
// but if the graph is undirected, then both 3 and 4 are reachable starting
// with 4.
//
// If you attended the THEG graph theory course, then you have already implemented
// a similar function in Python. You may have used mutable data structures.
// You must implement the Scala function using IMMUTABLE data structures.
// Even if your function passes all the test cases, you will not receive credit
// for the assigment if your code mutates any of its data structures.
//
// The two functions, makeAdj and reachableVertices, are missing type declarations
// for their input parameters. You must provide these.
//
// If you need to, you may implement other function definitions with this Theg object.
//
object Theg {
def makeAdj[???](edges, directed): Map[V, Set[V]] = {
???
}
def reachableVertices[V](edges: Seq[(V, V)], vStart: V, directed: Boolean): Set[V] = {
val adj = makeAdj(???, ???)
def collectVertices(done: Set[V], toDo: Set[V]): Set[V] = {
if (???)
done
else {
val v1 = toDo.head
// In this recursive call you must provide the two required arguments,
// the next value of done, and the next value of toDo.
// The next value of done is the current value with v1 added.
// The next value of toDo is the old value, but with v1 removed
// and all the neighbors of v1 (which are not in done) added.
// You may wish to create several local variables.
// You may use + to add an element (nondestructively) to a set,
// use - to remove an element (nondestructively) from a set,
// use ++ to append two sets (nondestructively), and
// use diff for set-difference.
val neighbors = adj.getOrElse(v1,Set())
collectVertices(???, ???)
}
}
collectVertices(???, ???)
}
}
// Copyright (c) 2020 EPITA Research and Development Laboratory
//
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation
// files (the "Software"), to deal in the Software without restriction,
// including without limitation the rights to use, copy, modify, merge,
// publish, distribute, sublicense, and/or sell copies of the Software,
// and to permit persons to whom the Software is furnished to do so,
// subject to the following conditions:
//
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
import org.scalatest._
class GreetingTestSuite extends FunSuite {
test("greeting") {
import lecture.Greeting._
hello()
}
test("HW customized greeting") {
import homework.Greeting._
hello("jim")
}
}
// Copyright (c) 2020 EPITA Research and Development Laboratory
//
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation
// files (the "Software"), to deal in the Software without restriction,
// including without limitation the rights to use, copy, modify, merge,
// publish, distribute, sublicense, and/or sell copies of the Software,
// and to permit persons to whom the Software is furnished to do so,
// subject to the following conditions:
//
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
import lecture.Recursion._
import org.scalatest._
import homework.Recursion._
// This test suite accompanies the lecture section called "Recursion".
// The tests are intended to test the student's completion of
// homework assignment "Recursion exercise".
class RecursionTestSuite extends FunSuite {
test("simple recursion"){
assert(0 == sumIntegersBySimpleRecursion(List()))
assert(0 == sumIntegersBySimpleRecursion(List(0,0,0,0,0,0,0,0,0,0)))
assert(15 == sumIntegersBySimpleRecursion(List(1,2,3,4,5)))
}
test("tail recursion"){
assert(0 == sumIntegersByTailRecursion(List()))
assert(0 == sumIntegersByTailRecursion(List(0,0,0,0,0,0,0,0,0,0)))
assert(15 == sumIntegersByTailRecursion(List(1,2,3,4,5)))
}
test("folding"){
assert(0 == sumIntegersByFold(List()))
assert(0 == sumIntegersByFold(List(0,0,0,0,0,0,0,0,0,0)))
assert(15 == sumIntegersByFold(List(1,2,3,4,5)))
}
test("HW sum doubles"){
assert(0.0 == sumDoublesBySimpleRecursion(List()))
assert(0.0 == sumDoublesBySimpleRecursion(List(0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0)))
// we should actually have exact equality
assert(16.5 == sumDoublesBySimpleRecursion(List(1.5,2.0,3.25,4.0,5.75)))
assert(0.0 == sumDoublesByTailRecursion(List()))
assert(0.0 == sumDoublesByTailRecursion(List(0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0)))
// we should actually have exact equality
assert(16.5 == sumDoublesByTailRecursion(List(1.5,2.0,3.25,4.0,5.75)))
assert(0.0 == sumDoublesByFold(List()))
assert(0.0 == sumDoublesByFold(List(0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0)))
// we should actually have exact equality
assert(16.5 == sumDoublesByFold(List(1.5,2.0,3.25,4.0,5.75)))
}
test("HW product doubles"){
assert(1.0 == productDoublesBySimpleRecursion(List()))
assert(0.0 == productDoublesBySimpleRecursion(List(0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0)))
assert(1.0 == productDoublesBySimpleRecursion(List(1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0)))
assert(0.0 == productDoublesBySimpleRecursion(List(1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,0.0)))
// we should actually have exact equality
assert(12.0 == productDoublesBySimpleRecursion(List(2.0, 3.0, 4.0, 0.5)))
assert(1.0 == productDoublesByTailRecursion(List()))
assert(0.0 == productDoublesByTailRecursion(List(0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0)))
assert(1.0 == productDoublesByTailRecursion(List(1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0)))
assert(0.0 == productDoublesByTailRecursion(List(1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,0.0)))
// we should actually have exact equality
assert(12.0 == productDoublesByTailRecursion(List(2.0, 3.0, 4.0, 0.5)))
assert(1.0 == productDoublesByFold(List()))
assert(0.0 == productDoublesByFold(List(0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0)))
assert(1.0 == productDoublesByFold(List(1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0)))
assert(0.0 == productDoublesByFold(List(1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,0.0)))
// we should actually have exact equality
assert(12.0 == productDoublesByFold(List(2.0, 3.0, 4.0, 0.5)))
}
}
// Copyright (c) 2020 EPITA Research and Development Laboratory
//
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation
// files (the "Software"), to deal in the Software without restriction,
// including without limitation the rights to use, copy, modify, merge,
// publish, distribute, sublicense, and/or sell copies of the Software,
// and to permit persons to whom the Software is furnished to do so,
// subject to the following conditions:
//
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
import homework.Theg._
import org.scalatest.FunSuite
class ThegTestSuite extends FunSuite {
test("building adjacency list") {
assert(makeAdj(Array((1,2)),true).get(2) == None)
assert(makeAdj(Array((1,2)),false).get(2) == Some(Set(1)))
assert(makeAdj(Array((1,2)),false)
== Map(1 -> Set(2),
2 -> Set(1)))
assert(makeAdj(List((1,2),(2,3)), false)
== Map(1 -> Set(2),
2 -> Set(1,3),
3 -> Set(2)))
assert(makeAdj(List(("a","b"),("b","c"),("a","c"),("b","d")),true)
== Map("a" -> Set("b","c"),
"b" -> Set("c","d")))
}
test("collect connected vertices by Array") {
assert(reachableVertices(Array((1, 2), (3, 4), (4, 2)), 1, false) == Set(1, 2, 3, 4))
assert(reachableVertices(Array((1, 2), (3, 4), (4, 2)), 2, false) == Set(1, 2, 3, 4), "undirected")
assert(reachableVertices(Array((1, 2), (3, 4), (4, 2)), 3, false) == Set(1, 2, 3, 4))
assert(reachableVertices(Array((1, 2), (3, 4), (4, 2)), 4, false) == Set(1, 2, 3, 4))
assert(reachableVertices(Array((1, 2), (3, 4), (4, 2)), 1, true) == Set(1, 2))
assert(reachableVertices(Array((1, 2), (3, 4), (4, 2)), 2, true) == Set(2), "directed")
assert(reachableVertices(Array((1, 2), (3, 4), (4, 2)), 3, true) == Set(3, 4, 2))
assert(reachableVertices(Array((1, 2), (3, 4), (4, 2)), 4, true) == Set(4, 2))
}
test("disconnected graph by Array") {
// now a disconnected graph
assert(reachableVertices(Array((1,2),(1,3),(1,4),(4,1),
(10.1,11),(10.1,12),(11,12)),11,false) == Set(10.1,11,12))
assert(reachableVertices(Array((1,2),(1,3),(1,4),(4,1),
(10.1,11),(10.1,12),(11,12)),11,true) == Set(11,12))
assert(reachableVertices(Array((1,2),(1,3),(1,4),(4,1),
(10.1,11),(10.1,12),(11,12)),1,false) == Set(1,2,3,4))
assert(reachableVertices(Array((1,2),(1,3),(1,4),(4,1),
(10.1,11),(10.1,12),(11,12)),1,true) == Set(1,2,3,4))
}
test("collect connected vertices by List") {
assert(reachableVertices(List((1, 2), (3, 4), (4, 2)), 1, false) == Set(1, 2, 3, 4))
assert(reachableVertices(List((1, 2), (3, 4), (4, 2)), 2, false) == Set(1, 2, 3, 4), "undirected")
assert(reachableVertices(List((1, 2), (3, 4), (4, 2)), 3, false) == Set(1, 2, 3, 4))
assert(reachableVertices(List((1, 2), (3, 4), (4, 2)), 4, false) == Set(1, 2, 3, 4))
assert(reachableVertices(List((1, 2), (3, 4), (4, 2)), 1, true) == Set(1, 2))
assert(reachableVertices(List((1, 2), (3, 4), (4, 2)), 2, true) == Set(2), "directed")
assert(reachableVertices(List((1, 2), (3, 4), (4, 2)), 3, true) == Set(3, 4, 2))
assert(reachableVertices(List((1, 2), (3, 4), (4, 2)), 4, true) == Set(4, 2))
}
test("disconnected graph by List") {
// now a disconnected graph
assert(reachableVertices(List((1,2),(1,3),(1,4),(4,1),
(10,11),(10,12),(11,12)),11,false) == Set(10,11,12))
assert(reachableVertices(List((1,2),(1,3),(1,4),(4,1),
(10,11),(10,12),(11,12)),11,true) == Set(11,12))
assert(reachableVertices(List((1,2),(1,3),(1,4),(4,1),
(10,11),(10,12),(11,12)),1,false) == Set(1,2,3,4))
assert(reachableVertices(List((1,2),(1,3),(1,4),(4,1),
(10,11),(10,12),(11,12)),1,true) == Set(1,2,3,4))
}
test("disconnected graph with doubles") {
// now a disconnected graph
assert(reachableVertices(List((1.1,2.2),(1.1,3.3),(1.1,4.4),(4.4,1.1),
(10.1,11.1),(10.1,12.2),(11.1,12.2)),11.1,false) == Set(10.1,11.1,12.2))
assert(reachableVertices(List((1.1,2.2),(1.1,3.3),(1.1,4.4),(4.4,1.1),