Skip to content

Commit

Permalink
fix: tests to pass with latest pgregory.net/rapid generics syntax
Browse files Browse the repository at this point in the history
  • Loading branch information
stefano-bd committed Nov 10, 2023
1 parent a635ee7 commit e03e852
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 13 deletions.
2 changes: 1 addition & 1 deletion hooks_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ func (s *hooksSuite) IOpenAResource(step Step) {

func (s *hooksSuite) IOpenAnyResources(t *rapid.T) {
longRun = true
s.numOpenForScenario = rapid.Int64Range(1, 100).Draw(t, "numResources").(int64)
s.numOpenForScenario = rapid.Int64Range(1, 100).AsAny().Draw(t, "numResources").(int64)
open += s.numOpenForScenario
}

Expand Down
25 changes: 13 additions & 12 deletions value_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,13 @@ package gocuke

import (
"fmt"
"math/big"
"testing"

"github.com/cockroachdb/apd/v3"
"github.com/google/go-cmp/cmp"
"gotest.tools/v3/assert"
"math/big"
"pgregory.net/rapid"
"testing"
)

func TestValues(t *testing.T) {
Expand Down Expand Up @@ -37,54 +38,54 @@ var bigIntComparer = cmp.Comparer(func(x, y *big.Int) bool {
})

func (s *valuesSuite) AnyInt64String(t *rapid.T) {
s.AnInt64(rapid.Int64().Draw(t, "orig").(int64))
s.AnInt64(rapid.Int64().AsAny().Draw(t, "orig").(int64))
}

func (s *valuesSuite) WhenIConvertItToAnInt64() {
s.parsed = toInt64(s, s.str)
}

var decGen = rapid.Custom(func(t *rapid.T) *apd.Decimal {
nBytes := rapid.IntRange(1, 16).Draw(t, "nBytes").(int)
nBytes := rapid.IntRange(1, 16).AsAny().Draw(t, "nBytes").(int)
bytes := make([]byte, nBytes)
for i := 0; i < nBytes; i++ {
bytes[i] = rapid.Byte().Draw(t, fmt.Sprintf("byte%d", i)).(byte)
bytes[i] = rapid.Byte().AsAny().Draw(t, fmt.Sprintf("byte%d", i)).(byte)
}
coeff := &apd.BigInt{}
coeff.SetBytes(bytes)
neg := rapid.Bool().Draw(t, "neg").(bool)
neg := rapid.Bool().AsAny().Draw(t, "neg").(bool)
if neg {
coeff = coeff.Neg(coeff)
}
exp := rapid.Int32Range(-5000, 5000).Draw(t, "exp").(int32)
exp := rapid.Int32Range(-5000, 5000).AsAny().Draw(t, "exp").(int32)
return apd.NewWithBigInt(coeff, exp)
})

func (s *valuesSuite) AnyDecimalString(t *rapid.T) {
s.ADecimal(decGen.Draw(t, "x").(*apd.Decimal))
s.ADecimal(decGen.AsAny().Draw(t, "x").(*apd.Decimal))
}

func (s *valuesSuite) WhenIConvertItToADecimal() {
s.parsed = toDecimal(s, s.str)
}

var bigIntGen = rapid.Custom(func(t *rapid.T) *big.Int {
nBytes := rapid.IntRange(1, 16).Draw(t, "nBytes").(int)
nBytes := rapid.IntRange(1, 16).AsAny().Draw(t, "nBytes").(int)
bytes := make([]byte, nBytes)
for i := 0; i < nBytes; i++ {
bytes[i] = rapid.Byte().Draw(t, fmt.Sprintf("byte%d", i)).(byte)
bytes[i] = rapid.Byte().AsAny().Draw(t, fmt.Sprintf("byte%d", i)).(byte)
}
x := &big.Int{}
x.SetBytes(bytes)
neg := rapid.Bool().Draw(t, "neg").(bool)
neg := rapid.Bool().AsAny().Draw(t, "neg").(bool)
if neg {
x = x.Neg(x)
}
return x
})

func (s *valuesSuite) AnyBigIntegerString(t *rapid.T) {
s.ABigInteger(bigIntGen.Draw(t, "x").(*big.Int))
s.ABigInteger(bigIntGen.AsAny().Draw(t, "x").(*big.Int))
}

func (s *valuesSuite) WhenIConvertItToABigInteger() {
Expand Down

0 comments on commit e03e852

Please sign in to comment.