chore(compiler): Add PathFinder test (#872)

This commit is contained in:
InversionSpaces 2023-09-04 13:22:57 +02:00 committed by GitHub
parent 443e65e3d8
commit c1fbea1a49
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 35 additions and 0 deletions

View File

@ -7,6 +7,7 @@ import aqua.raw.value.{LiteralRaw, ValueRaw, VarRaw}
import aqua.raw.ops.{Call, FuncOp, OnTag} import aqua.raw.ops.{Call, FuncOp, OnTag}
import aqua.raw.value.{ValueRaw, VarRaw} import aqua.raw.value.{ValueRaw, VarRaw}
import aqua.types.{ArrayType, ScalarType} import aqua.types.{ArrayType, ScalarType}
import cats.data.{Chain, NonEmptyList} import cats.data.{Chain, NonEmptyList}
import org.scalatest.flatspec.AnyFlatSpec import org.scalatest.flatspec.AnyFlatSpec
import org.scalatest.matchers.should.Matchers import org.scalatest.matchers.should.Matchers

View File

@ -0,0 +1,34 @@
package aqua.model.transform.topology
import aqua.model.*
import aqua.model.transform.ModelBuilder
import aqua.types.ScalarType
import cats.data.Chain
import cats.syntax.show.*
import org.scalatest.flatspec.AnyFlatSpec
import org.scalatest.matchers.should.Matchers
class PathFinderSpec extends AnyFlatSpec with Matchers {
val relay = ValueModel.fromRaw(ModelBuilder.relayV)
val initPeer = ValueModel.fromRaw(ModelBuilder.initPeer)
val relayOn = OnModel(relay, Chain.empty)
val initPeerRelayOn = OnModel(initPeer, Chain.one(relay))
it should "find path from (op, or) -> r -> (i, r) to r -> (i, r)" in {
val otherPeer = VarModel("other-peer", ScalarType.string)
val otherRelay = VarModel("other-relay", ScalarType.string)
val otherPeerRelayOn = OnModel(otherPeer, Chain.one(otherRelay))
val from = TopologyPath(otherPeerRelayOn :: relayOn :: initPeerRelayOn :: Nil)
val to = TopologyPath(relayOn :: initPeerRelayOn :: Nil)
val path = PathFinder.findPath(from, to)
path shouldBe Chain.one(otherRelay)
}
}