Skip to content

Add hardcoded unit tests for bitflip operations#58

Draft
Copilot wants to merge 4 commits intodevfrom
copilot/add-hardcoded-unit-tests-again
Draft

Add hardcoded unit tests for bitflip operations#58
Copilot wants to merge 4 commits intodevfrom
copilot/add-hardcoded-unit-tests-again

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented Dec 9, 2025

The bitflip test suite relied primarily on reversibility checks and probabilistic tests. This PR adds deterministic tests with predetermined input-output pairs to verify bitflips occur at correct positions with correct transformations.

Changes

  • New test file: tests/unit_tests/test_bitflip_hardcoded.py with 19 test methods covering:

    • Sign bit flips (bit 0): 1.0 → -1.0, -5.0 → 5.0
    • Exponent bit flips: bitflip(1.0, 1) → inf (exponent becomes all 1s)
    • Mantissa LSB flips: minimal float32 precision changes
    • Matrix position-specific flips: [[0,1],[2,3]] with bit 0 at [1,1][[0,1],[2,-3]]
    • Implementation consistency across bitflip_float32, bitflip_float32_optimized, and bitflip_float32_fast
  • Documentation: MSB-first indexing convention explicitly documented (bit 0 = sign, bits 1-8 = exponent, bits 9-31 = mantissa)

Example

# Test sign bit flip with known outcome
assert bitflip_float32(3.0, 0) == -3.0

# Test matrix operation from issue
matrix = np.array([[0.0, 1.0], [2.0, 3.0]], dtype=np.float32)
matrix[1, 1] = bitflip_float32(matrix[1, 1], 0)  # 3.0 → -3.0
assert matrix[1, 1] == -3.0

All 111 unit tests pass with 96% coverage.

Original prompt

This section details on the original issue you should resolve

<issue_title>[FEATURE] Add better hardcoded unit tests</issue_title>
<issue_description>### Feature Summary

I want some stronger checks that the bitflips are being performed in the correct location and in the correct way.

Feature Category

Testing/Quality Assurance

Problem Statement

I want some stronger checks that the bitflips are being performed in the correct location and in the correct way.

Proposed Solution

Have some hardcoded tests. i.e. take a matrix [[0,1],[2,3]] and do a bit_i=0 at [1,1] to be [[0,1],[2,-3]]

Proposed API (if applicable)

Priority Level

None

Research Impact

No response

Alternatives Considered

No response

Implementation Considerations

  • This feature requires new dependencies
  • This feature affects performance-critical paths
  • This feature requires GPU/CUDA support
  • This feature needs extensive testing
  • This feature affects the public API
  • I would be interested in implementing this feature

Additional Context

No response

Pre-submission Checklist

  • I have searched existing issues for similar requests
  • I have provided sufficient detail about the use case
  • I have considered the impact on existing users
  • I have thought about backward compatibility</issue_description>

Comments on the Issue (you are @copilot in this section)


💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.

Copilot AI and others added 2 commits December 9, 2025 23:35
Co-authored-by: Will-D-AER <197624355+Will-D-AER@users.noreply.github.com>
Co-authored-by: Will-D-AER <197624355+Will-D-AER@users.noreply.github.com>
Copilot AI changed the title [WIP] Add better hardcoded unit tests for bitflip correctness Add hardcoded unit tests for bitflip operations Dec 9, 2025
Copilot AI requested a review from Will-D-AER December 9, 2025 23:40
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