From 925e1140ee4036b337fb5d9ae0a6d8ab8af87580 Mon Sep 17 00:00:00 2001 From: henriquejsza Date: Sat, 22 Aug 2026 04:55:47 -0300 Subject: [PATCH] tests: support 32-bit architectures --- .github/workflows/ci.yml | 4 +++ collections_example_test.go | 61 +++++++++++++++++++------------------ combinators_example_test.go | 11 ++++--- integers_external_test.go | 11 ++++--- make_example_test.go | 16 +++++----- 5 files changed, 56 insertions(+), 47 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index a4eb8a0..f34c646 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -28,5 +28,9 @@ jobs: - name: Test run: go test -race + - name: Test 32-bit + if: runner.os == 'Linux' + run: GOARCH=386 go test + - name: Bench run: go test -run=Benchmark -bench=. diff --git a/collections_example_test.go b/collections_example_test.go index 874982e..dce4c6c 100644 --- a/collections_example_test.go +++ b/collections_example_test.go @@ -8,40 +8,41 @@ package rapid_test import ( "fmt" + "math" "pgregory.net/rapid" ) func ExampleSliceOf() { - gen := rapid.SliceOf(rapid.Int()) + gen := rapid.SliceOf(rapid.IntRange(math.MinInt32, math.MaxInt32)) for i := 0; i < 5; i++ { fmt.Println(gen.Example(i)) } // Output: - // [1 -1902 7 -236 14 -433 -1572631 -1 4219826 -50 1414 -3890044391133 -9223372036854775808 5755498240 -10 680558 10 -80458281 0 -27] - // [-3 -2 -1 -3 -2172865589 -5 -2 -2503553836720] - // [4 308 -2 21 -5843 3 1 78 6129321692 -59] - // [590 -131 -15 -769 16 -1 14668 14 -1 -58784] + // [1 -366 7 -236 14 -49 -65303 -1 25522 -2 134 -951504605 -2147483648 17690368 -2 8814 10 -4960809 0 -11] + // [-3 -2 -1 -3 -25381941 -1 -2 -661644976] + // [0 308 -2 5 -211 3 1 14 22415068 -11] + // [78 -3 -15 -1 0 -1 332 6 -1 -1440] // [] } func ExampleSliceOfN() { - gen := rapid.SliceOfN(rapid.Int(), 5, 5) + gen := rapid.SliceOfN(rapid.IntRange(math.MinInt32, math.MaxInt32), 5, 5) for i := 0; i < 5; i++ { fmt.Println(gen.Example(i)) } // Output: - // [1 -1902 7 -236 14] - // [-3 -2 -1 -3 -2172865589] - // [4 308 -2 21 -5843] - // [590 -131 -15 -769 16] - // [4629136912 270 141395 -129322425838843911 -7] + // [1 -366 7 -236 14] + // [-3 -2 -1 -3 -25381941] + // [0 308 -2 5 -211] + // [78 -3 -15 -1 0] + // [15402512 14 2131 -631093255 -3] } func ExampleSliceOfDistinct() { - gen := rapid.SliceOfDistinct(rapid.IntMin(0), func(i int) int { return i % 2 }) + gen := rapid.SliceOfDistinct(rapid.IntRange(0, math.MaxInt32), func(i int) int { return i % 2 }) for i := 0; i < 5; i++ { fmt.Println(gen.Example(i)) @@ -49,51 +50,51 @@ func ExampleSliceOfDistinct() { // Output: // [1] // [2 1] - // [4 1] - // [590] + // [0 1] + // [78] // [] } func ExampleSliceOfNDistinct() { - gen := rapid.SliceOfNDistinct(rapid.IntMin(0), 2, 2, func(i int) int { return i % 2 }) + gen := rapid.SliceOfNDistinct(rapid.IntRange(0, math.MaxInt32), 2, 2, func(i int) int { return i % 2 }) for i := 0; i < 5; i++ { fmt.Println(gen.Example(i)) } // Output: - // [4219826 49] + // [25522 1] // [2 1] - // [4 1] - // [0 58783] - // [4629136912 141395] + // [0 1] + // [0 1439] + // [15402512 2131] } func ExampleMapOf() { - gen := rapid.MapOf(rapid.Int(), rapid.StringMatching(`[a-z]+`)) + gen := rapid.MapOf(rapid.IntRange(math.MinInt32, math.MaxInt32), rapid.StringMatching(`[a-z]+`)) for i := 0; i < 5; i++ { fmt.Println(gen.Example(i)) } // Output: - // map[1:nhlgqwasbggbaociac 561860:r] - // map[-3752:pizpv -3:bacuabp 0:bi] - // map[-33086515648293:gewf -264276:b -1313:a -258:v -4:b -2:fdhbzcz 4:ubfsdbowrja 1775:tcozav 8334:lvcprss 376914:braigey] - // map[-350:h 590:coaaamcasnapgaad] + // map[1:nhlgqwasbggbaociac 4804:r] + // map[-168:pizpv -3:bacuabp 0:bi] + // map[-235083557:gewf -2132:b -33:a -4:b -2:v 0:ubfsdbowrja 82:braigey 142:lvcprss 239:tcozav] + // map[-30:h 78:coaaamcasnapgaad] // map[] } func ExampleMapOfN() { - gen := rapid.MapOfN(rapid.Int(), rapid.StringMatching(`[a-z]+`), 5, 5) + gen := rapid.MapOfN(rapid.IntRange(math.MinInt32, math.MaxInt32), rapid.StringMatching(`[a-z]+`), 5, 5) for i := 0; i < 5; i++ { fmt.Println(gen.Example(i)) } // Output: - // map[-130450326583:bd -2983:bbdbcs 1:nhlgqwasbggbaociac 31:kmdnpmcbuagzr 561860:r] - // map[-82024404:d -3752:pizpv -3:bacuabp 0:bi 179745:rzkneb] - // map[-33086515648293:gewf -258:v 4:ubfsdbowrja 1775:tcozav 8334:lvcprss] - // map[-4280678227:j -25651:aafmd -3308:o -350:h 590:coaaamcasnapgaad] - // map[-9614404661322:gsb -378:y 2:paai 4629136912:otg 1476419818092:qign] + // map[-124912695:bd -423:bbdbcs 1:nhlgqwasbggbaociac 15:kmdnpmcbuagzr 4804:r] + // map[-235476:d -168:pizpv -3:bacuabp 0:bi 7713:rzkneb] + // map[-235083557:gewf -2:v 0:ubfsdbowrja 142:lvcprss 239:tcozav] + // map[-2488147:j -9267:aafmd -236:o -30:h 78:coaaamcasnapgaad] + // map[-378:y 0:paai 2:b 15402512:otg 24810092:qign] } func ExampleMapOfValues() { diff --git a/combinators_example_test.go b/combinators_example_test.go index 2478bdf..708a300 100644 --- a/combinators_example_test.go +++ b/combinators_example_test.go @@ -8,6 +8,7 @@ package rapid_test import ( "fmt" + "math" "strconv" "pgregory.net/rapid" @@ -58,16 +59,16 @@ func ExampleDeferred() { } func ExampleMap() { - gen := rapid.Map(rapid.Int(), strconv.Itoa) + gen := rapid.Map(rapid.IntRange(math.MinInt32, math.MaxInt32), strconv.Itoa) for i := 0; i < 5; i++ { fmt.Printf("%#v\n", gen.Example(i)) } // Output: // "-3" - // "-186981" + // "-23141" // "4" // "-2" - // "43" + // "11" } func ExampleJust() { @@ -127,7 +128,7 @@ func ExampleOneOf() { } func ExamplePtr() { - gen := rapid.Ptr(rapid.Int(), true) + gen := rapid.Ptr(rapid.IntRange(math.MinInt32, math.MaxInt32), true) for i := 0; i < 5; i++ { v := gen.Example(i) @@ -141,6 +142,6 @@ func ExamplePtr() { // (*int) 1 // (*int) -3 // - // (*int) 590 + // (*int) 78 // } diff --git a/integers_external_test.go b/integers_external_test.go index 2fd8dad..da1e0c8 100644 --- a/integers_external_test.go +++ b/integers_external_test.go @@ -34,7 +34,10 @@ func TestIntExamples(t *testing.T) { IntRange(10, 100).AsAny(), IntRange(100, 10000).AsAny(), IntRange(100, 1000000).AsAny(), - IntRange(100, 1<<60-1).AsAny(), + } + if bits.UintSize == 64 { + max := int64(1<<60 - 1) + gens = append(gens, IntRange(100, int(max)).AsAny()) } for _, g := range gens { @@ -258,8 +261,8 @@ func TestIntCoverage(t *testing.T) { } if bits.UintSize == 64 { - filters = append(filters, func(i int) bool { return i > 1<<62 }) - filters = append(filters, func(i int) bool { return i < -(1 << 62) }) + filters = append(filters, func(i int) bool { return int64(i) > int64(1<<62) }) + filters = append(filters, func(i int) bool { return int64(i) < int64(-(1 << 62)) }) } for i, fn := range filters { @@ -285,7 +288,7 @@ func TestUintCoverage(t *testing.T) { } if bits.UintSize == 64 { - filters = append(filters, func(i uint) bool { return i > 1<<63 }) + filters = append(filters, func(i uint) bool { return uint64(i) > uint64(1<<63) }) } for i, fn := range filters { diff --git a/make_example_test.go b/make_example_test.go index 6741790..cb4b5dc 100644 --- a/make_example_test.go +++ b/make_example_test.go @@ -13,20 +13,20 @@ import ( ) func ExampleMake() { - gen := rapid.Make[map[int]bool]() + gen := rapid.Make[map[int32]bool]() for i := 0; i < 5; i++ { fmt.Println(gen.Example(i)) } // Output: - // map[-433:true -261:false -53:false -23:false 1:true 184:false] + // map[-53:false -49:true -23:false -5:false 1:true 56:false] // map[-3:true 0:true] - // map[4:true] - // map[-359:true -154:true -71:true -17:false -1:false 590:false 22973756520:true] + // map[0:true] + // map[-103:true -26:true -7:true -1:false 78:false 22525032:true] // map[] } -type nodeValue int +type nodeValue int32 type tree struct { Value nodeValue @@ -47,9 +47,9 @@ func ExampleMake_tree() { fmt.Println(gen.Example(i)) } // Output: - // (nil 1 (nil 184 nil)) - // (((nil -1 (((((nil -485 ((nil -2 ((((nil -5 nil) -9898554875447 nil) -34709387 ((nil 50440 nil) 113 (((((nil -442 nil) -66090341586 nil) 179745 nil) 494 (((nil -2 nil) 543360606020 nil) 15261837 nil)) -1778 nil))) -21034573818 nil)) -5 nil)) 15606609 nil) 882666 (nil 3 nil)) -12 (nil -2 ((nil 1 nil) -2 (((nil 11 nil) -187307 ((nil -198 (nil -6895 nil)) 12027 (nil -539313 nil))) 1532 (nil 6 nil))))) 1745354 nil)) -2 nil) -3 nil) + // (nil 1 (nil 56 nil)) + // (((nil -1 (((((nil -101 ((nil -2 ((((nil -1 nil) -802741815 nil) -106379 ((nil 1288 nil) 17 (((((nil -58 nil) -55219410 nil) 7713 nil) 238 (((nil -2 nil) 47243076 nil) 57485 nil)) -242 nil))) -29499386 nil)) -5 nil)) 926545 nil) 14314 (nil 3 nil)) -12 (nil -2 ((nil 1 nil) -2 (((nil 3 nil) -7083 ((nil -70 (nil -2799 nil)) 1787 (nil -15025 nil))) 508 (nil 6 nil))))) 41418 nil)) -2 nil) -3 nil) // nil - // (((nil -15 (nil 6598 nil)) -131 (nil 317121006373596 ((nil 14 ((nil -9223372036854775808 nil) 1 nil)) 14668 nil))) 590 nil) + // (((nil -15 (nil 454 nil)) -3 (nil 2096073436 ((nil 6 ((nil -2147483648 nil) 1 nil)) 332 nil))) 78 nil) // nil }