Standard library / testing/quick
testing/quick.CheckEqual()
Compare two functions with compatible signatures on generated inputs; unequal results yield a CheckEqualError. Expected stdout: 'true\n'.
Formal Syntax & Structure
go syntaxgo
func CheckEqual(f, g any, config *Config) errorParameters & Attributes
| Name | Type | Description |
|---|---|---|
| f | any | Function under test or callback to run. |
| g | any | Comparison function with the same signature. |
| config | *Config | Optional property-test settings; nil uses defaults. |
Return Value
error
Result of the operation described above.
Working Example
Example Snippetgo
package main
import ( "fmt" "math/rand" "testing/quick")
func main() { err := quick.CheckEqual(func(x uint8) uint8 { return x + x }, func(x uint8) uint8 { return x * 2 }, &quick.Config{MaxCount: 20, Rand: rand.New(rand.NewSource(42))}) fmt.Println(err == nil)}