Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

v5.0-test-nested-loops: Test for map inside fold #788

Merged
merged 5 commits into from
Apr 4, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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