From ec52bb98f4066d16d376f13b6c63fcf06a8636bc Mon Sep 17 00:00:00 2001 From: Vince Reuter Date: Wed, 13 Nov 2024 13:15:33 +0100 Subject: [PATCH] apply formatter --- .../src/main/scala/NuclearDesignation.scala | 2 +- modules/graph/src/main/scala/package.scala | 41 +++++++++--------- modules/graph/src/test/scala/TestGraph.scala | 42 ++++++++++--------- .../instances/JsonInstancesForGeometry.scala | 1 - 4 files changed, 45 insertions(+), 41 deletions(-) diff --git a/modules/cell/src/main/scala/NuclearDesignation.scala b/modules/cell/src/main/scala/NuclearDesignation.scala index e8e784b..525f4e0 100644 --- a/modules/cell/src/main/scala/NuclearDesignation.scala +++ b/modules/cell/src/main/scala/NuclearDesignation.scala @@ -25,7 +25,7 @@ object NucleusNumber: given SimpleShow[NucleusNumber] = SimpleShow.instance(_.get.show) /** Try to read the given string as a nucleus number. */ - def parse(s: String): Either[String, NucleusNumber] = + def parse(s: String): Either[String, NucleusNumber] = readAsInt(s) .flatMap(PositiveInt.either) .bimap( diff --git a/modules/graph/src/main/scala/package.scala b/modules/graph/src/main/scala/package.scala index a4c5c68..d2dcd82 100644 --- a/modules/graph/src/main/scala/package.scala +++ b/modules/graph/src/main/scala/package.scala @@ -5,29 +5,30 @@ import scalax.collection.edges.UnDiEdge import scalax.collection.edges.UnDiEdgeImplicits // for syntax, like ~ import scalax.collection.immutable - /** Graph-related operations */ package object graph: - private[graph] type SimplestGraph[N] = immutable.Graph[N, UnDiEdge[N]] + private[graph] type SimplestGraph[N] = immutable.Graph[N, UnDiEdge[N]] - /** Start with an empty graph, and combine by taking union of node and edge sets. */ - def monoidKForSimplestGraphByOuterElements: MonoidK[SimplestGraph] = new: - override def empty[N]: SimplestGraph[N] = immutable.Graph.empty - override def combineK[N](g1: SimplestGraph[N], g2: SimplestGraph[N]): SimplestGraph[N] = - immutable.Graph.from((g1.nodes.toOuter | g2.nodes.toOuter), g1.edges.toOuter | g2.edges.toOuter) + /** Start with an empty graph, and combine by taking union of node and edge sets. */ + def monoidKForSimplestGraphByOuterElements: MonoidK[SimplestGraph] = new: + override def empty[N]: SimplestGraph[N] = immutable.Graph.empty + override def combineK[N](g1: SimplestGraph[N], g2: SimplestGraph[N]): SimplestGraph[N] = + immutable.Graph.from( + (g1.nodes.toOuter | g2.nodes.toOuter), + g1.edges.toOuter | g2.edges.toOuter + ) - private def fromSingleNodeAndNeighbors[N](n: N, neighbors: Set[N]): SimplestGraph[N] = - immutable.Graph.from(neighbors.map(n ~ _)) + private def fromSingleNodeAndNeighbors[N](n: N, neighbors: Set[N]): SimplestGraph[N] = + immutable.Graph.from(neighbors.map(n ~ _)) - /** - * Construct a simple graph from an adjancency list/'matrix'. - * - * @tparam N The node type - * @param adjecency The adjacency list / 'matrix' which encodes the - * edge relationships / node adjacencies - */ - def buildSimpleGraph[N](adjacency: Map[N, Set[N]]): SimplestGraph[N] = - val singleGraphs = adjacency.toList.map(fromSingleNodeAndNeighbors[N].tupled) - monoidKForSimplestGraphByOuterElements.combineAllK(singleGraphs) + /** Construct a simple graph from an adjancency list/'matrix'. + * + * @tparam N + * The node type + * @param adjecency + * The adjacency list / 'matrix' which encodes the edge relationships / node adjacencies + */ + def buildSimpleGraph[N](adjacency: Map[N, Set[N]]): SimplestGraph[N] = + val singleGraphs = adjacency.toList.map(fromSingleNodeAndNeighbors[N].tupled) + monoidKForSimplestGraphByOuterElements.combineAllK(singleGraphs) end graph - diff --git a/modules/graph/src/test/scala/TestGraph.scala b/modules/graph/src/test/scala/TestGraph.scala index c23a66c..7436433 100644 --- a/modules/graph/src/test/scala/TestGraph.scala +++ b/modules/graph/src/test/scala/TestGraph.scala @@ -15,36 +15,40 @@ import org.scalatest.prop.Configuration.PropertyCheckConfiguration import org.scalatestplus.scalacheck.ScalaCheckPropertyChecks /** Test the functionality of the graph module. */ -class TestGraph extends AnyFunSuiteLike, FunSuiteDiscipline, ScalaCheckPropertyChecks, should.Matchers: - +class TestGraph + extends AnyFunSuiteLike, + FunSuiteDiscipline, + ScalaCheckPropertyChecks, + should.Matchers: + private val maxOrder: Int = 20 - - given arbitraryForRandomGraphMetrics[N: Arbitrary]: Arbitrary[GraphGen.Metrics[N]] = - Arbitrary{ - Gen.choose(1, maxOrder).map{ n => // RandomGraph throws exception for order-0. - new GraphGen.Metrics[N]{ + + given arbitraryForRandomGraphMetrics[N: Arbitrary]: Arbitrary[GraphGen.Metrics[N]] = + Arbitrary { + Gen.choose(1, maxOrder).map { n => // RandomGraph throws exception for order-0. + new GraphGen.Metrics[N]: override def order: Int = n - override def nodeDegrees: NodeDegreeRange = - // Don't let graph order approach vertex degreer, else + override def nodeDegrees: NodeDegreeRange = + // Don't let graph order approach vertex degreer, else // too many edge add tries will fail and the generator will stop. NodeDegreeRange(0, n / 2) override def nodeGen: Gen[N] = Arbitrary.arbitrary[N] override def connected: Boolean = false - } } } - given arbitrarySimplestGraph[N: Arbitrary: ClassTag]: Arbitrary[SimplestGraph[N]] = + given arbitrarySimplestGraph[N: Arbitrary: ClassTag]: Arbitrary[SimplestGraph[N]] = def genEmpty: Gen[SimplestGraph[N]] = Graph.empty def genNonEmpty: Gen[SimplestGraph[N]] = Arbitrary .arbitrary[GraphGen.Metrics[N]] - .flatMap{ metrics => - GraphGen.fromMetrics[N, UnDiEdge[N], Graph](Graph, metrics, Set(UnDiEdge)).apply + .flatMap { metrics => + GraphGen.fromMetrics[N, UnDiEdge[N], Graph](Graph, metrics, Set(UnDiEdge)).apply } - Arbitrary{ Gen.frequency(1 -> genEmpty, (maxOrder - 1) -> genNonEmpty) } + Arbitrary { Gen.frequency(1 -> genEmpty, (maxOrder - 1) -> genNonEmpty) } - given eqSimplestGraphByOuter[N: Eq]: Eq[SimplestGraph[N]] = - Eq.by{ g => (g.nodes.toOuter, g.edges.toOuter) } + given eqSimplestGraphByOuter[N: Eq]: Eq[SimplestGraph[N]] = + Eq.by: g => + (g.nodes.toOuter, g.edges.toOuter) // needed since we're in AnyFunSuiteLike land override implicit val generatorDrivenConfig: PropertyCheckConfiguration = @@ -52,7 +56,7 @@ class TestGraph extends AnyFunSuiteLike, FunSuiteDiscipline, ScalaCheckPropertyC // Check the SemigroupK laws for the at-least-2-element refinement of Set. checkAll( - "graph.SimplestGraph.MonoidKLaws", - MonoidKTests[SimplestGraph](using monoidKForSimplestGraphByOuterElements - ).monoidK[Int]) + "graph.SimplestGraph.MonoidKLaws", + MonoidKTests[SimplestGraph](using monoidKForSimplestGraphByOuterElements).monoidK[Int] + ) end TestGraph diff --git a/modules/json/src/main/scala/instances/JsonInstancesForGeometry.scala b/modules/json/src/main/scala/instances/JsonInstancesForGeometry.scala index 4b9c52f..80f5e46 100644 --- a/modules/json/src/main/scala/instances/JsonInstancesForGeometry.scala +++ b/modules/json/src/main/scala/instances/JsonInstancesForGeometry.scala @@ -13,5 +13,4 @@ trait JsonInstancesForGeometry: ): JsonValueWriter[C, O] = new: override def apply(c: C): O = writeRaw(c.value) - end JsonInstancesForGeometry