-
Notifications
You must be signed in to change notification settings - Fork 215
Description
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.
rchain/models/src/test/scala/coop/rchain/models/rholang/SortTest.scala
Lines 241 to 264 in fb3c1f6
| 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) | |
| } |
rchain/rholang/src/test/scala/coop/rchain/rholang/interpreter/BigIntNormalizerSpec.scala
Lines 66 to 88 in fb3c1f6
| 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"))) | |
| } | |
| } |
Lines 769 to 786 in fb3c1f6
| "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") | |
| ) | |
| ) |
rchain/rholang/src/test/scala/coop/rchain/rholang/interpreter/ReduceSpec.scala
Lines 2347 to 2371 in fb3c1f6
| "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" | |
| ) | |
| ) | |
| ), |
rchain/rholang/src/test/scala/coop/rchain/rholang/interpreter/matcher/MatchTest.scala
Lines 893 to 900 in fb3c1f6
| "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) | |
| } |