Skip to content

Commit

Permalink
Merge pull request #788 from ScorexFoundation/v5.0-test-nested-loops
Browse files Browse the repository at this point in the history
v5.0-test-nested-loops: Test for map inside fold
  • Loading branch information
aslesarenko authored Apr 4, 2022
2 parents a3b0645 + 53ea2a4 commit 77b96b1
Showing 1 changed file with 77 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7680,6 +7680,83 @@ class SigmaDslSpecification extends SigmaDslTesting
}
}

// related issue https://github.com/ScorexFoundation/sigmastate-interpreter/issues/464
property("nested loops: map inside fold") {
val keys = Colls.fromArray(Array(Coll[Byte](1, 2, 3, 4, 5)))
val initial = Coll[Byte](0, 0, 0, 0, 0)
val cases = Seq(
(keys, initial) -> Expected(Success(Coll[Byte](1, 2, 3, 4, 5)), cost = 46522, expectedDetails = CostDetails.ZeroCost, 1821)
)
val scalaFunc = { (x: (Coll[Coll[Byte]], Coll[Byte])) =>
x._1.foldLeft(x._2, { (a: (Coll[Byte], Coll[Byte])) =>
a._1.zip(a._2).map({ (c: (Byte, Byte)) => (c._1 + c._2).toByte })
})
}
val script =
"""{
| (x: (Coll[Coll[Byte]], Coll[Byte])) =>
| x._1.fold(x._2, { (a: Coll[Byte], b: Coll[Byte]) =>
| a.zip(b).map({ (c: (Byte, Byte)) => (c._1 + c._2).toByte })
| })
|}""".stripMargin
if (lowerMethodCallsInTests) {
verifyCases(cases,
existingFeature(scalaFunc, script,
FuncValue(
Array((1, SPair(SByteArray2, SByteArray))),
Fold(
SelectField.typed[Value[SCollection[SCollection[SByte.type]]]](
ValUse(1, SPair(SByteArray2, SByteArray)),
1.toByte
),
SelectField.typed[Value[SCollection[SByte.type]]](
ValUse(1, SPair(SByteArray2, SByteArray)),
2.toByte
),
FuncValue(
Array((3, SPair(SByteArray, SByteArray))),
MapCollection(
MethodCall.typed[Value[SCollection[STuple]]](
SelectField.typed[Value[SCollection[SByte.type]]](
ValUse(3, SPair(SByteArray, SByteArray)),
1.toByte
),
SCollection.getMethodByName("zip").withConcreteTypes(
Map(STypeVar("IV") -> SByte, STypeVar("OV") -> SByte)
),
Vector(
SelectField.typed[Value[SCollection[SByte.type]]](
ValUse(3, SPair(SByteArray, SByteArray)),
2.toByte
)
),
Map()
),
FuncValue(
Array((5, SPair(SByte, SByte))),
ArithOp(
SelectField.typed[Value[SByte.type]](ValUse(5, SPair(SByte, SByte)), 1.toByte),
SelectField.typed[Value[SByte.type]](ValUse(5, SPair(SByte, SByte)), 2.toByte),
OpCode @@ (-102.toByte)
)
)
)
)
)
)
),
preGeneratedSamples = Some(Seq.empty)
)
} else {
assertExceptionThrown(
verifyCases(cases,
existingFeature(scalaFunc, script)
),
rootCauseLike[CosterException]("Don't know how to evalNode(Lambda(List(),Vector((a,Coll[SByte$]), ")
)
}
}

override protected def afterAll(): Unit = {
println(ErgoTreeEvaluator.DefaultProfiler.generateReport)
println("==========================================================")
Expand Down

0 comments on commit 77b96b1

Please sign in to comment.