-
-
Notifications
You must be signed in to change notification settings - Fork 62
Add focused unit tests for Sheet class #581
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add focused unit tests for Sheet class #581
Conversation
|
Important Review skippedBot user detected. To trigger a single review, invoke the You can disable this status message by setting the Note Other AI code review bot(s) detectedCodeRabbit has detected other AI code review bot(s) in this pull request and will avoid duplicating their findings in the review comments. This may lead to a less comprehensive review. WalkthroughChanges add defensive guard conditions to Sheet scroll methods (scrollUp/scrollDown) to validate scroll delta and bounds before execution. A comprehensive GoogleTest suite for the Sheet class is introduced in test/testSheet.cc, the build configuration is updated to include the new test, and minor corrections are made to testMinsky.cc. Changes
Estimated code review effort🎯 2 (Simple) | ⏱️ ~12 minutes
Poem
Pre-merge checks and finishing touches✅ Passed checks (3 passed)
Comment |
Co-authored-by: highperformancecoder <3075825+highperformancecoder@users.noreply.github.com>
Co-authored-by: highperformancecoder <3075825+highperformancecoder@users.noreply.github.com>
highperformancecoder
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@copilot please address review comments.
…s with rank 3 tensors, use unique temp files Co-authored-by: highperformancecoder <3075825+highperformancecoder@users.noreply.github.com>
|
@CodeRabbit review |
✅ Actions performedReview triggered.
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 0
🧹 Nitpick comments (1)
test/testSheet.cc (1)
122-137: Good coverage of scrolling behavior with rank-3 tensors.These tests effectively verify scrolling functionality and slice indicators with multi-dimensional data, addressing the requirements from previous review feedback. The tests correctly interact with the Sheet API and validate expected behavior.
Consider adding test cleanup to improve test isolation:
void TearDown() override { minsky::minsky().model->clear(); minsky::minsky().clearAllMaps(); }This would prevent potential test interdependencies when tests modify the global minsky state.
Also applies to: 139-164, 173-186
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (4)
model/sheet.cc(2 hunks)test/Makefile(1 hunks)test/testMinsky.cc(3 hunks)test/testSheet.cc(1 hunks)
🧰 Additional context used
🧠 Learnings (1)
📚 Learning: 2025-10-03T23:24:29.823Z
Learnt from: highperformancecoder
Repo: highperformancecoder/minsky PR: 566
File: test/testCSVParser.cc:154-156
Timestamp: 2025-10-03T23:24:29.823Z
Learning: The Minsky project's test suite is built with C++20 (`-std=c++20` in test/Makefile), so C++20 features like `std::string::starts_with`, `std::format`, ranges, concepts, etc., can be used in test code without compatibility concerns.
Applied to files:
test/testMinsky.cc
🧬 Code graph analysis (1)
test/testSheet.cc (1)
model/sheet.cc (14)
onResizeHandle(66-73)onResizeHandle(66-66)inItem(104-109)inItem(104-104)clickType(111-120)clickType(111-111)contains(128-131)contains(128-128)scrollUp(133-142)scrollUp(133-133)scrollDown(144-153)scrollDown(144-144)exportAsCSV(522-528)exportAsCSV(522-522)
🪛 Clang (14.0.6)
test/testSheet.cc
[error] 19-19: 'sheet.h' file not found
(clang-diagnostic-error)
[error] 33-33: method 'SetUp' can be made static
(readability-convert-member-functions-to-static,-warnings-as-errors)
[error] 36-36: 200 is a magic number; consider replacing it with a named constant
(cppcoreguidelines-avoid-magic-numbers,readability-magic-numbers,-warnings-as-errors)
[error] 37-37: 150 is a magic number; consider replacing it with a named constant
(cppcoreguidelines-avoid-magic-numbers,readability-magic-numbers,-warnings-as-errors)
[error] 38-38: 100 is a magic number; consider replacing it with a named constant
(cppcoreguidelines-avoid-magic-numbers,readability-magic-numbers,-warnings-as-errors)
[error] 38-38: 100 is a magic number; consider replacing it with a named constant
(cppcoreguidelines-avoid-magic-numbers,readability-magic-numbers,-warnings-as-errors)
[error] 42-42: all parameters should be named in a function
(readability-named-parameter,-warnings-as-errors)
[error] 44-44: variable 'sheet' is not initialized
(cppcoreguidelines-init-variables,-warnings-as-errors)
[error] 50-50: all parameters should be named in a function
(readability-named-parameter,-warnings-as-errors)
[error] 52-52: 100 is a magic number; consider replacing it with a named constant
(cppcoreguidelines-avoid-magic-numbers,readability-magic-numbers,-warnings-as-errors)
[error] 52-52: 100 is a magic number; consider replacing it with a named constant
(cppcoreguidelines-avoid-magic-numbers,readability-magic-numbers,-warnings-as-errors)
[error] 53-53: 200 is a magic number; consider replacing it with a named constant
(cppcoreguidelines-avoid-magic-numbers,readability-magic-numbers,-warnings-as-errors)
[error] 54-54: 150 is a magic number; consider replacing it with a named constant
(cppcoreguidelines-avoid-magic-numbers,readability-magic-numbers,-warnings-as-errors)
[error] 55-55: variable name 'z' is too short, expected at least 3 characters
(readability-identifier-length,-warnings-as-errors)
[error] 56-56: variable name 'w' is too short, expected at least 3 characters
(readability-identifier-length,-warnings-as-errors)
[error] 56-56: 0.5 is a magic number; consider replacing it with a named constant
(cppcoreguidelines-avoid-magic-numbers,readability-magic-numbers,-warnings-as-errors)
[error] 56-56: 200 is a magic number; consider replacing it with a named constant
(cppcoreguidelines-avoid-magic-numbers,readability-magic-numbers,-warnings-as-errors)
[error] 57-57: variable name 'h' is too short, expected at least 3 characters
(readability-identifier-length,-warnings-as-errors)
[error] 57-57: 0.5 is a magic number; consider replacing it with a named constant
(cppcoreguidelines-avoid-magic-numbers,readability-magic-numbers,-warnings-as-errors)
[error] 57-57: 150 is a magic number; consider replacing it with a named constant
(cppcoreguidelines-avoid-magic-numbers,readability-magic-numbers,-warnings-as-errors)
[error] 60-60: 100 is a magic number; consider replacing it with a named constant
(cppcoreguidelines-avoid-magic-numbers,readability-magic-numbers,-warnings-as-errors)
[error] 60-60: 100 is a magic number; consider replacing it with a named constant
(cppcoreguidelines-avoid-magic-numbers,readability-magic-numbers,-warnings-as-errors)
[error] 63-63: 100 is a magic number; consider replacing it with a named constant
(cppcoreguidelines-avoid-magic-numbers,readability-magic-numbers,-warnings-as-errors)
[error] 63-63: 100 is a magic number; consider replacing it with a named constant
(cppcoreguidelines-avoid-magic-numbers,readability-magic-numbers,-warnings-as-errors)
[error] 67-67: 100 is a magic number; consider replacing it with a named constant
(cppcoreguidelines-avoid-magic-numbers,readability-magic-numbers,-warnings-as-errors)
[error] 67-67: 100 is a magic number; consider replacing it with a named constant
(cppcoreguidelines-avoid-magic-numbers,readability-magic-numbers,-warnings-as-errors)
[error] 70-70: 100 is a magic number; consider replacing it with a named constant
(cppcoreguidelines-avoid-magic-numbers,readability-magic-numbers,-warnings-as-errors)
[error] 70-70: 100 is a magic number; consider replacing it with a named constant
(cppcoreguidelines-avoid-magic-numbers,readability-magic-numbers,-warnings-as-errors)
[error] 73-73: all parameters should be named in a function
(readability-named-parameter,-warnings-as-errors)
[error] 75-75: 100 is a magic number; consider replacing it with a named constant
(cppcoreguidelines-avoid-magic-numbers,readability-magic-numbers,-warnings-as-errors)
[error] 75-75: 100 is a magic number; consider replacing it with a named constant
(cppcoreguidelines-avoid-magic-numbers,readability-magic-numbers,-warnings-as-errors)
[error] 76-76: 200 is a magic number; consider replacing it with a named constant
(cppcoreguidelines-avoid-magic-numbers,readability-magic-numbers,-warnings-as-errors)
[error] 77-77: 150 is a magic number; consider replacing it with a named constant
(cppcoreguidelines-avoid-magic-numbers,readability-magic-numbers,-warnings-as-errors)
[error] 80-80: 100 is a magic number; consider replacing it with a named constant
(cppcoreguidelines-avoid-magic-numbers,readability-magic-numbers,-warnings-as-errors)
[error] 80-80: 100 is a magic number; consider replacing it with a named constant
(cppcoreguidelines-avoid-magic-numbers,readability-magic-numbers,-warnings-as-errors)
[error] 84-84: 300 is a magic number; consider replacing it with a named constant
(cppcoreguidelines-avoid-magic-numbers,readability-magic-numbers,-warnings-as-errors)
[error] 84-84: 300 is a magic number; consider replacing it with a named constant
(cppcoreguidelines-avoid-magic-numbers,readability-magic-numbers,-warnings-as-errors)
[error] 87-87: all parameters should be named in a function
(readability-named-parameter,-warnings-as-errors)
[error] 89-89: 100 is a magic number; consider replacing it with a named constant
(cppcoreguidelines-avoid-magic-numbers,readability-magic-numbers,-warnings-as-errors)
[error] 89-89: 100 is a magic number; consider replacing it with a named constant
(cppcoreguidelines-avoid-magic-numbers,readability-magic-numbers,-warnings-as-errors)
[error] 90-90: 200 is a magic number; consider replacing it with a named constant
(cppcoreguidelines-avoid-magic-numbers,readability-magic-numbers,-warnings-as-errors)
[error] 91-91: 150 is a magic number; consider replacing it with a named constant
(cppcoreguidelines-avoid-magic-numbers,readability-magic-numbers,-warnings-as-errors)
[error] 92-92: variable name 'z' is too short, expected at least 3 characters
(readability-identifier-length,-warnings-as-errors)
[error] 93-93: variable name 'w' is too short, expected at least 3 characters
(readability-identifier-length,-warnings-as-errors)
[error] 93-93: 0.5 is a magic number; consider replacing it with a named constant
(cppcoreguidelines-avoid-magic-numbers,readability-magic-numbers,-warnings-as-errors)
[error] 93-93: 200 is a magic number; consider replacing it with a named constant
(cppcoreguidelines-avoid-magic-numbers,readability-magic-numbers,-warnings-as-errors)
[error] 94-94: variable name 'h' is too short, expected at least 3 characters
(readability-identifier-length,-warnings-as-errors)
[error] 94-94: 0.5 is a magic number; consider replacing it with a named constant
(cppcoreguidelines-avoid-magic-numbers,readability-magic-numbers,-warnings-as-errors)
[error] 94-94: 150 is a magic number; consider replacing it with a named constant
(cppcoreguidelines-avoid-magic-numbers,readability-magic-numbers,-warnings-as-errors)
[error] 109-109: all parameters should be named in a function
(readability-named-parameter,-warnings-as-errors)
[error] 111-111: 100 is a magic number; consider replacing it with a named constant
(cppcoreguidelines-avoid-magic-numbers,readability-magic-numbers,-warnings-as-errors)
[error] 111-111: 100 is a magic number; consider replacing it with a named constant
(cppcoreguidelines-avoid-magic-numbers,readability-magic-numbers,-warnings-as-errors)
[error] 112-112: 200 is a magic number; consider replacing it with a named constant
(cppcoreguidelines-avoid-magic-numbers,readability-magic-numbers,-warnings-as-errors)
[error] 113-113: 150 is a magic number; consider replacing it with a named constant
(cppcoreguidelines-avoid-magic-numbers,readability-magic-numbers,-warnings-as-errors)
[error] 116-116: 100 is a magic number; consider replacing it with a named constant
(cppcoreguidelines-avoid-magic-numbers,readability-magic-numbers,-warnings-as-errors)
[error] 116-116: 100 is a magic number; consider replacing it with a named constant
(cppcoreguidelines-avoid-magic-numbers,readability-magic-numbers,-warnings-as-errors)
[error] 122-122: all parameters should be named in a function
(readability-named-parameter,-warnings-as-errors)
[error] 139-139: all parameters should be named in a function
(readability-named-parameter,-warnings-as-errors)
[error] 166-166: all parameters should be named in a function
(readability-named-parameter,-warnings-as-errors)
[error] 169-169: variable 'tmpFile' is not initialized
(cppcoreguidelines-init-variables,-warnings-as-errors)
[error] 173-173: all parameters should be named in a function
(readability-named-parameter,-warnings-as-errors)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (6)
- GitHub Check: ubuntu-20.04
- GitHub Check: ubuntu-20.04
- GitHub Check: ubuntu-20.04
- GitHub Check: ubuntu-20.04
- GitHub Check: ubuntu-20.04
- GitHub Check: ubuntu-20.04
🔇 Additional comments (6)
test/testMinsky.cc (1)
1755-1755: LGTM! Correct variable assignment.The assignment
eqSz=equations.size()properly captures the equations array size for later verification in the garbage collection test. This ensures the test correctly validates that garbage entries added to the equations array are properly cleaned up.test/Makefile (1)
14-14: LGTM! Test object properly added to build.The addition of
testSheet.otoGTESTOBJScorrectly integrates the new Sheet test suite into the build system.model/sheet.cc (1)
135-136: LGTM! Improved bounds checking.The added guards ensure scrolling only occurs when
scrollDeltais non-zero and the resulting offset remains within valid bounds. This prevents edge cases where scrolling might occur with invalid state or produce out-of-bounds offsets.Also applies to: 146-147
test/testSheet.cc (3)
42-120: LGTM! Well-structured basic functionality tests.The construction and hit-testing tests provide good coverage of the Sheet class's geometric operations. The test fixture properly sets up consistent dimensions and positions, and each test validates expected behavior for coordinate-based operations.
166-171: LGTM! Error handling properly validated.The test correctly verifies that
exportAsCSVthrows an exception when attempting to export without a value. The use ofunique_path()follows the requested pattern from previous reviews.
28-40: LGTM! Well-designed test fixture.The
SheetTestfixture appropriately inherits from bothSheetand::testing::Test, allowing tests to directly access Sheet members while integrating with GoogleTest. TheSetUp()override properly initializes consistent test state.
|
@copilot - please add TearDown methods suggested by coderabbit. Calling clearAllMaps should suffice, as the first line of clearAllMaps calls model->clear() anyway. |
Co-authored-by: highperformancecoder <3075825+highperformancecoder@users.noreply.github.com>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull request overview
This PR adds comprehensive unit test coverage for the Sheet class, which previously had minimal testing. The changes include a new test file with 9 focused test cases, fixes for scroll boundary validation bugs, and minor corrections to existing test comments.
- New test file
test/testSheet.ccwith 9 test cases covering hit testing, scrolling, keyboard input, data operations, and construction - Fixed scroll boundary validation bugs preventing proper scrolling when
scrollDeltais zero - Enhanced
setSliceIndicator()to return the slice indicator string - Corrected test fixture variable tracking in existing tests
Reviewed changes
Copilot reviewed 5 out of 5 changed files in this pull request and generated no comments.
Show a summary per file
| File | Description |
|---|---|
| test/testSheet.cc | New comprehensive test suite for Sheet class covering public API methods with proper setup/teardown and tensor data |
| test/Makefile | Added testSheet.o to GTESTOBJS for building the new test file |
| model/sheet.h | Enhanced setSliceIndicator() signature to return const std::string& for testability |
| model/sheet.cc | Fixed scrollUp/scrollDown boundary checks to prevent scrolling when scrollDelta is zero; updated setSliceIndicator() to return value |
| test/testMinsky.cc | Corrected test fixture variable tracking (eqSz should use equations.size()) and improved comment clarity |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
The Sheet class (
model/sheet.h) had minimal test coverage - only a single instantiation intestTensorOps.cc. This PR adds focused unit tests covering meaningful functionality of the class's public API.Changes
New test file:
test/testSheet.ccwith 9 focused test cases covering:onResizeHandle,inItem,clickType,contains)scrollUpDownwith actual tensor data)onKeyPressverifying scrolling behavior)exportAsCSVerror handling with unique temp files,setSliceIndicatorwith rank 3 tensor verification)Updated:
test/Makefileto includetestSheet.oinGTESTOBJSTest Infrastructure
minsky::minsky().clearAllMaps()to clean up global state after each test, ensuring proper test isolationTest Enhancements
Tests use rank 3 tensor data where appropriate to verify actual functionality:
scrollUpDownandonKeyPresstests create rank 3 tensors and verify scrolling behaviorsetSliceIndicatortest creates rank 3 tensor and verifies the slice indicator is populatedexportAsCSVtest usesboost::filesystem::unique_path()for safe temporary file handlingNot covered
ravelSize,ravelX,ravelY) - should not be tested directlydraw,drawResizeHandles) - require Cairo contextcomputeValue- requires complex port/tensor setup, appropriate for integration testsExample test coverage
Original prompt
💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.
This change is
Summary by CodeRabbit
Bug Fixes
Tests
✏️ Tip: You can customize this high-level summary in your review settings.