Thanks to visit codestin.com
Credit goes to github.com

Skip to content

BigInt unit tests refactoring #3763

@hilltracer

Description

@hilltracer

Overview

The Issue was created according to this @tgrospic's message.

There is many duplicated values in BigInt unit tests. In all of these table definitions, values are duplicated in the clue and in the input. It's easy to go out of sync. We can improve this with helper functions to only mention values once.

it should "sort so that smaller BigInt values come first" in {
val parGround =
Par(
exprs = List(
GBigInt(2),
GBigInt(BigInt("9999999999999999999999999999999999999999999999")),
GBigInt(BigInt("-9999999999999999999999999999999999999999999999")),
GBigInt(-2),
GBigInt(0)
)
)
val sortedParGround: Par =
Par(
exprs = List(
GBigInt(BigInt("-9999999999999999999999999999999999999999999999")),
GBigInt(-2),
GBigInt(0),
GBigInt(2),
GBigInt(BigInt("9999999999999999999999999999999999999999999999"))
)
)
val result = sort(parGround)
result.term should be(sortedParGround)
}

it should "convert Rholang String to BigInt" in {
val termWithNull =
s"""
# @"$outcomeCh"!("0".toBigInt())
# """.stripMargin('#')
val termWithPositiveBigValue =
s"""
# @"$outcomeCh"!("9999999999999999999999999999999999999999999999".toBigInt())
# """.stripMargin('#')
val termWithNegativeBigValue =
s"""
# @"$outcomeCh"!("-9999999999999999999999999999999999999999999999".toBigInt())
# """.stripMargin('#')
for {
r1 <- execute[Task](termWithNull)
r2 <- execute[Task](termWithPositiveBigValue)
r3 <- execute[Task](termWithNegativeBigValue)
} yield {
r1 should equal(Right(BigInt("0")))
r2 should equal(Right(BigInt("9999999999999999999999999999999999999999999999")))
r3 should equal(Right(BigInt("-9999999999999999999999999999999999999999999999")))
}
}

"reducer" when {
"it works with BigInt" should {
val table = Table(
("left", "right"),
(gBigInt("225"), gBigInt("25")),
(
gBigInt("9999999999999999999999999999999999999999"),
gBigInt("-9999999999999999999999999999999999999999")
),
(
gBigInt("0"),
gBigInt("9999999999999999999999999999999999999999")
),
(
gBigInt("123"),
gBigInt("-9999999999999999999999999999999999999999")
)
)

"reducer" should "perform arithmetic operations with BigInt" in {
val table = Table(
("clue", "input", "output"),
(
"""-(BigInt(9999999999999999999999999999999999999999)) =>
| -BigInt(9999999999999999999999999999999999999999999999)""".stripMargin,
ENegBody(ENeg(GBigInt(BigInt("9999999999999999999999999999999999999999")))),
GBigInt(BigInt("-9999999999999999999999999999999999999999"))
),
(
"""BigInt(9999999999999999999999999999999999999999) *
| (-BigInt(9999999999999999999999999999999999999999)) =>
| -BigInt(99999999999999999999999999999999999999980000000000000000000000000000000000000001)""".stripMargin,
EMultBody(
EMult(
GBigInt(BigInt("9999999999999999999999999999999999999999")),
GBigInt(BigInt("-9999999999999999999999999999999999999999"))
)
),
GBigInt(
BigInt(
"-99999999999999999999999999999999999999980000000000000000000000000000000000000001"
)
)
),

"Matching BigInt" should "work" in {
val successTarget: Par = GBigInt(BigInt("-9999999999999999999999999999999999999999999999"))
val failTarget: Par = GInt(12)
val pattern: Connective = Connective(ConnBigInt(true))
assertSpatialMatch(successTarget, pattern, Some(Map.empty))
assertSpatialMatch(failTarget, pattern, None)
}

Metadata

Metadata

Labels

GoodToHavea good-to-have feature

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions