{"record":{"id":"157711b140ac8a3c","repo":"apache/beam","slug":"values-below-expected-v","errorCode":null,"errorMessage":"values below expected: %v","messagePattern":"values below expected: (.+?)","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"sdks/go/pkg/beam/testing/passert/floats.go","lineNumber":108,"sourceCode":"\tfor i := 0; i < len(observedValues); i++ {\n\t\tdelta := observedValues[i] - expectedValues[i]\n\t\tif delta > f.Threshold {\n\t\t\ttooHigh = append(tooHigh, fmt.Sprintf(\"%v > %v,\", observedValues[i], expectedValues[i]))\n\t\t} else if delta < f.Threshold*-1 {\n\t\t\ttooLow = append(tooLow, fmt.Sprintf(\"%v < %v,\", observedValues[i], expectedValues[i]))\n\t\t}\n\t}\n\tif len(tooLow)+len(tooHigh) == 0 {\n\t\treturn nil\n\t}\n\terrorStrings := []string{}\n\tif len(tooLow) != 0 {\n\t\terrorStrings = append(errorStrings, fmt.Sprintf(\"values below expected: %v\", tooLow))\n\t}\n\tif len(tooHigh) != 0 {\n\t\terrorStrings = append(errorStrings, fmt.Sprintf(\"values above expected: %v\", tooHigh))\n\t}\n\treturn errors.New(strings.Join(errorStrings, \"\\n\"))\n}\n\n// AllWithinBounds checks that a PCollection of numeric types is within the bounds\n// [lo, high]. Checks for case where bounds are flipped and swaps them so the bounds\n// passed to the doFn are always lo <= hi.\nfunc AllWithinBounds(s beam.Scope, col beam.PCollection, lo, hi float64) {\n\tt := beam.ValidateNonCompositeType(col)\n\tvalidateNonComplexNumber(t.Type())\n\tif lo > hi {\n\t\tlo, hi = hi, lo\n\t}\n\ts = s.Scope(fmt.Sprintf(\"passert.AllWithinBounds([%v, %v])\", lo, hi))\n\tbeam.ParDo0(s, &boundsFn{Lo: lo, Hi: hi}, beam.Impulse(s), beam.SideInput{Input: col})\n}\n\ntype boundsFn struct {\n\tLo, Hi float64\n}","sourceCodeStart":90,"sourceCodeEnd":126,"githubUrl":"https://github.com/apache/beam/blob/12126d8942aaf848030c478b4c6a28c6af861c66/sdks/go/pkg/beam/testing/passert/floats.go#L90-L126","documentation":"Inside EqualsFloat's thresholdFn.ProcessElement, each observed value is compared against expected ± threshold. Values smaller than the allowed lower bound are collected into `tooLow` and reported as 'values below expected: %v'. The joined error strings fail the assertion, listing which observed values fell short of expected-threshold.","triggerScenarios":"EqualsFloat assertion where one or more observed numeric values are less than (expected - threshold); e.g. float precision drift larger than the threshold, or genuinely wrong computation output.","commonSituations":"Floating-point unit tests with too tight a threshold; pipelines whose math differs from the expected golden values; aggregation order changing float results.","solutions":["Widen the threshold parameter to accommodate legitimate floating-point drift","Inspect the listed values to determine which pipeline stage produced wrong results","Compare sorted/deterministic aggregation if order-dependent float accumulation is the cause","Use exact-value types (int64) or AllWithinBounds if tolerance semantics are unclear"],"exampleFix":"// before\npassert.EqualsFloat(s, averages, 1.0, 1e-12) // 0.9999999995 reported below expected\n// after\npassert.EqualsFloat(s, averages, 1.0, 1e-6) // widen threshold to absorb float drift","handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"if err := passert.EqualsFloat(s, col, expected, threshold); err != nil {\n\t// error lists exact values below/above expected; widen threshold or fix pipeline\n\tt.Fatalf(\"bounds assertion failed: %v\", err)\n}","preventionTips":["Choose thresholds based on known floating-point precision limits","Sort or make aggregation deterministic when accumulating floats","Prefer int64 math where exactness matters","Read listed offending values to locate the failing stage"],"tags":["go","beam","testing","passert","floats"],"backgroundTag":"value-out-of-range","analyzedSha":"12126d8942aaf848030c478b4c6a28c6af861c66","analyzedAt":"2026-09-13T01:50:10.254Z","contentChangedAt":"2026-09-13T01:50:10.254Z","schemaVersion":2},"datasetVersion":"2026-09-14T16:17:12.679Z"}