Daily Test Coverage Improver: Add comprehensive TorchExtensions tests#53
Merged
Daily Test Coverage Improver: Add comprehensive TorchExtensions tests#53
Conversation
This PR adds comprehensive test coverage for the TorchExtensions module, which provides essential tensor conversion utilities between Furnace and PyTorch. ## Coverage Impact **Target Area:** - **TorchExtensions module**: Increased from **0%** to **75%** line coverage **Overall Impact:** - **Total project coverage**: ~73.4% → ~73.7% (0.3% improvement) - **Torch backend coverage**: 83.38% → 84.22% (+0.84%) - **Torch Utils coverage**: 58.5% → 68.2% (+9.7%) ## Tests Added (7 test methods) ### Core Functionality Tests 1. **TestTorchExtensionsFromTorchTensor()** - Tests basic 1D tensor round-trip conversion 2. **TestTorchExtensionsFromTorchTensor2D()** - Tests 2D tensor conversion with proper shape preservation 3. **TestTorchExtensionsFromTorchScalar()** - Tests scalar tensor conversion 4. **TestTorchExtensionsRoundTripLargerTensor()** - Tests 3D tensor conversion with random data ### Data Type & Backend Tests 5. **TestTorchExtensionsToTorchWithDifferentDtypes()** - Tests Float32, Float64, Int32 dtype preservation 6. **TestTorchExtensionsToTorchWithNonTorchBackend()** - Tests proper exception handling for non-Torch tensors 7. **TestTorchExtensionsBoolTensorRoundTrip()** - Tests boolean tensor conversion ## Functions Covered - `FurnaceImage.fromTorch(torch.Tensor)` - Creates Furnace tensor from PyTorch tensor - `tensor.toTorch()` - Converts Furnace tensor to PyTorch tensor (with backend validation) ## Test Design Features - **Comprehensive data types**: Float32, Float64, Int32, Bool tensors - **Multiple tensor shapes**: Scalars, 1D, 2D, 3D tensors - **Error handling**: Tests exception throwing for invalid backend conversions - **Value preservation**: Verifies numerical accuracy with floating-point tolerance - **Shape preservation**: Ensures tensor dimensions are maintained through conversions - **Backend compatibility**: Tests both Torch and Reference backend interactions 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
dsyme
approved these changes
Aug 30, 2025
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
This PR adds comprehensive test coverage for the TorchExtensions module, which provides essential tensor conversion utilities between Furnace and PyTorch. The module previously had 0% test coverage and is now at 75% line coverage.
Problems Found
fromTorch,toTorch) were completely untestedActions Taken
Added 7 comprehensive test methods covering:
Core Functionality Tests:
TestTorchExtensionsFromTorchTensor()- Basic 1D tensor round-trip conversionTestTorchExtensionsFromTorchTensor2D()- 2D tensor conversion with shape preservationTestTorchExtensionsFromTorchScalar()- Scalar tensor conversionTestTorchExtensionsRoundTripLargerTensor()- 3D tensor conversion with random dataData Type & Backend Tests:
TestTorchExtensionsToTorchWithDifferentDtypes()- Float32, Float64, Int32 dtype preservationTestTorchExtensionsToTorchWithNonTorchBackend()- Exception handling for non-Torch tensorsTestTorchExtensionsBoolTensorRoundTrip()- Boolean tensor conversionFunctions Covered:
FurnaceImage.fromTorch(torch.Tensor)- Creates Furnace tensor from PyTorch tensortensor.toTorch()- Converts Furnace tensor to PyTorch tensor (with backend validation)Coverage Changes
Before:
After:
Test Design Features
Future Recommendations
Additional areas identified for potential coverage improvements:
Validation Commands
To verify coverage improvements:
Commands Executed
Bash Commands:
dotnet --version- Check .NET versiondotnet restore- Install dependenciesdotnet build --configuration Release --no-restore --verbosity normal- Build projectdotnet test tests/Furnace.Tests --configuration Release --no-build --filter TestTorchExtensions- Run specific testsdotnet test tests/Furnace.Tests --configuration Release --no-build /p:CollectCoverage=true /p:CoverletOutputFormat=opencover /p:CoverletOutput="coverage.opencover.xml" --logger trx- Full coverage analysisreportgenerator -reports:"coverage.opencover.xml" -targetdir:"coverage" -reporttypes:"Html;TextSummary;Badges"- Generate coverage reportsdotnet format- Apply code formattingMCP Function/Tool Calls:
mcp__github__search_issues- Found existing research issue Daily Test Coverage Improver: Research and Plan #46mcp__github__get_issue_comments- Read previous work commentsmcp__github__search_pull_requests- Checked for existing Daily Test Coverage Improver PRsRead- Analyzed TorchExtensions source code structureWrite- Created TestTorchExtensions.fs test fileEdit- Updated project file and fixed test compilation issuesGrep- Searched codebase for patterns and existing test structures