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) error

Parameters & Attributes

NameTypeDescription
fanyFunction under test or callback to run.
ganyComparison function with the same signature.
config*ConfigOptional 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)}
Go Reference