Skip to content

Conversation

@kkweon
Copy link
Member

@kkweon kkweon commented Oct 2, 2025

Summary

  • Replace exact equality checks with tolerance-based comparisons for floating-point values
  • Update example test to use formatted output instead of raw float printing
  • Add go-cmp library with custom comparers for float32/float64 types

Problem

Floating-point values can have slight precision differences across different architectures, compilers, and optimization levels. This causes tests to fail intermittently on different systems (ARM vs x86, different Go versions, etc.), making the test suite unreliable for contributors and CI/CD pipelines.

Solution

  • Tolerance-based comparisons: Use github.com/google/go-cmp with 0.001 delta for float comparisons
  • Formatted output: Change example test from fmt.Println(results) to fmt.Printf("Tokens: %v, Score: %.2f\n", ...)
  • Consistent behavior: Ensure tests pass reliably regardless of floating-point representation differences

Test plan

  • All existing tests pass with new comparison logic
  • Example test produces consistent output across platforms
  • Float comparison tolerance is appropriate (0.001 delta)
  • No regression in test coverage or accuracy

Floating-point values can have slight precision differences across
different architectures, compilers, and optimization levels, causing
tests to fail intermittently on different systems.

- Replace exact equality checks with tolerance-based comparisons using
  go-cmp library with 0.001 delta for float32/float64 values
- Update example test to use formatted output (%.2f) instead of raw
  float printing to ensure consistent behavior across platforms
- Maintain test accuracy while eliminating architecture-dependent
  test failures

This ensures tests pass reliably on ARM, x86, and other architectures
regardless of floating-point representation differences.
@kkweon kkweon marked this pull request as draft October 2, 2025 07:07
kkweon added 5 commits October 2, 2025 00:14
- Add proper error handling to RewindScanner.Rewind() method
- Update CI workflow to use Go 1.23 instead of outdated 1.17
- Fix golangci-lint errcheck violations for better code quality
- Update GitHub Actions to v4 for security and performance

The error handling improvements ensure that seek failures are properly
propagated instead of being silently ignored, making the code more
robust and compliant with Go best practices.
Add explicit checks with clear error messages to identify why the
Kiwi C library installation is failing in CI. The script now:

- Verifies headers exist at /usr/local/include/kiwi/
- Verifies libraries exist at /usr/local/lib/libkiwi*
- Fails fast with descriptive error messages if verification fails
- Shows success confirmation when installation works properly

This will help identify whether the issue is with sudo permissions,
path differences between local and CI environments, or other
installation problems specific to GitHub Actions runners.
The macOS runners don't have /usr/local/lib and /usr/local/include
directories by default, causing the installation script to fail with
'mv: /usr/local/lib/ is not a directory'.

Add 'sudo mkdir -p /usr/local/lib /usr/local/include' before attempting
to move libraries and copy headers to ensure the target directories
exist on all platforms.
GitHub Actions macOS runners use ARM64 architecture but the install
script was hardcoded to download x86_64 binaries, causing linker
errors with 'found architecture x86_64, required architecture arm64'.

The script now:
- Detects the architecture using 'uname -m'
- Downloads the correct ARM64 binaries for Apple Silicon
- Downloads x86_64 binaries for Intel Macs and Linux
- Shows architecture in debug output for troubleshooting

This ensures the downloaded Kiwi libraries match the target architecture.
Kiwi v0.10.3 doesn't have native ARM64 builds for macOS, only Intel
x86_64 builds are available. The script now:

- Always uses x86_64 binaries for macOS (both Intel and ARM64)
- ARM64 Macs will run x86_64 binaries via Rosetta translation
- Validated that the download URL exists and contains correct libraries

This resolves the 'found architecture x86_64, required architecture arm64'
linker error by ensuring we only download builds that actually exist.
@kkweon kkweon closed this Oct 2, 2025
@kkweon kkweon deleted the improve-float-test-comparisons branch October 2, 2025 07:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants