-
-
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
Merged
highperformancecoder
merged 9 commits into
master
from
copilot/improve-code-coverage-sheet-class
Nov 24, 2025
Merged
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
aaf8c05
Initial plan
Copilot 52005a1
Add comprehensive unit tests for Sheet class
Copilot 11779f6
Remove tests for private methods (ravelSize, ravelX, ravelY)
Copilot 19b3142
Merge branch 'master' into copilot/improve-code-coverage-sheet-class
highperformancecoder ff5103e
Fix unit tests.
highperformancecoder bd56431
Address minor code review coments fro Copilot.
highperformancecoder 62c71f8
Address review comments: remove useless tests, enhance remaining test…
Copilot f0da861
Add TearDown method to clean up global minsky state after each test
Copilot 8735b5b
Fix unit tests.
highperformancecoder File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
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
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,193 @@ | ||
| /* | ||
| @copyright Steve Keen 2024 | ||
| @author Russell Standish | ||
| This file is part of Minsky. | ||
|
|
||
| Minsky is free software: you can redistribute it and/or modify it | ||
| under the terms of the GNU General Public License as published by | ||
| the Free Software Foundation, either version 3 of the License, or | ||
| (at your option) any later version. | ||
|
|
||
| Minsky is distributed in the hope that it will be useful, | ||
| but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
| GNU General Public License for more details. | ||
|
|
||
| You should have received a copy of the GNU General Public License | ||
| along with Minsky. If not, see <http://www.gnu.org/licenses/>. | ||
| */ | ||
| #include "sheet.h" | ||
| #include "minsky.h" | ||
| #include "minsky_epilogue.h" | ||
| #include <gtest/gtest.h> | ||
| #include <boost/filesystem.hpp> | ||
|
|
||
| using namespace minsky; | ||
| using namespace std; | ||
|
|
||
| namespace | ||
| { | ||
| class SheetTest : public Sheet, public ::testing::Test | ||
| { | ||
| protected: | ||
| void SetUp() override | ||
| { | ||
| // Set default dimensions for tests | ||
| iWidth(200); | ||
| iHeight(150); | ||
| moveTo(100, 100); | ||
| } | ||
|
|
||
| void TearDown() override | ||
| { | ||
| // Clean up global minsky state after each test | ||
| minsky::minsky().clearAllMaps(); | ||
| } | ||
| }; | ||
|
|
||
| TEST_F(SheetTest, construction) | ||
| { | ||
| Sheet sheet; | ||
| EXPECT_EQ(1, sheet.portsSize()); | ||
| EXPECT_EQ(100, sheet.iWidth()); | ||
| EXPECT_EQ(100, sheet.iHeight()); | ||
| } | ||
|
|
||
| TEST_F(SheetTest, onResizeHandle) | ||
| { | ||
| moveTo(100, 100); | ||
| iWidth(200); | ||
| iHeight(150); | ||
| double z = zoomFactor(); | ||
| double w = 0.5 * 200 * z; | ||
| double h = 0.5 * 150 * z; | ||
|
|
||
| // Test bottom-right resize handle | ||
| EXPECT_TRUE(onResizeHandle(100 + w, 100 + h)); | ||
|
|
||
| // Test top-right resize handle | ||
| EXPECT_TRUE(onResizeHandle(100 + w, 100 - h)); | ||
|
|
||
| // Test bottom-left resize handle (when showRavel is false) | ||
| showRavel = false; | ||
| EXPECT_TRUE(onResizeHandle(100 - w, 100 + h)); | ||
|
|
||
| // Test points not on resize handle | ||
| EXPECT_FALSE(onResizeHandle(100, 100)); | ||
| } | ||
|
|
||
| TEST_F(SheetTest, inItem) | ||
| { | ||
| moveTo(100, 100); | ||
| iWidth(200); | ||
| iHeight(150); | ||
|
|
||
| // Test point inside item | ||
| EXPECT_TRUE(inItem(100, 100)); | ||
|
|
||
| // Test point outside item | ||
| EXPECT_FALSE(inItem(0, 0)); | ||
| EXPECT_FALSE(inItem(300, 300)); | ||
| } | ||
|
|
||
| TEST_F(SheetTest, clickType) | ||
| { | ||
| moveTo(100, 100); | ||
| iWidth(200); | ||
| iHeight(150); | ||
| double z = zoomFactor(); | ||
| double w = 0.5 * 200 * z; | ||
| double h = 0.5 * 150 * z; | ||
|
|
||
| // Test resize handle | ||
| EXPECT_EQ(ClickType::onResize, clickType(100 + w, 100 + h)); | ||
|
|
||
| // Test inside item | ||
| EXPECT_EQ(ClickType::inItem, clickType(100, 100)); | ||
|
|
||
| // Test on item border | ||
| EXPECT_EQ(ClickType::onItem, clickType(100 + w * 0.9, 100 + h * 0.9)); | ||
|
|
||
| // Test outside item | ||
| EXPECT_EQ(ClickType::outside, clickType(0, 0)); | ||
| } | ||
|
|
||
| TEST_F(SheetTest, contains) | ||
| { | ||
| moveTo(100, 100); | ||
| iWidth(200); | ||
| iHeight(150); | ||
|
|
||
| // Test point inside item | ||
| EXPECT_TRUE(contains(100, 100)); | ||
|
|
||
| // Test point outside item | ||
| EXPECT_FALSE(contains(0, 0)); | ||
| } | ||
|
|
||
| TEST_F(SheetTest, scrollUpDown) | ||
| { | ||
| // Initial state - no scrolling possible without data | ||
| EXPECT_FALSE(scrollUp()); | ||
| EXPECT_FALSE(scrollDown()); | ||
| // add a rank 3 tensor, which is "scrollable" | ||
| minsky::minsky().canvas.addVariable("3dTensor",VariableType::parameter); | ||
| auto& param=*minsky::minsky().canvas.itemFocus->variableCast(); | ||
| param.init("rand(3,3,3)"); | ||
| minsky::minsky().canvas.addSheet(); | ||
| auto& sheet=dynamic_cast<Sheet&>(*minsky::minsky().canvas.itemFocus); | ||
| minsky::minsky().model->addWire(param, sheet, 0); | ||
| minsky::minsky().reset(); | ||
| EXPECT_TRUE(sheet.scrollUp()); | ||
| EXPECT_TRUE(sheet.scrollDown()); | ||
| } | ||
|
|
||
| TEST_F(SheetTest, onKeyPress) | ||
| { | ||
| // Test arrow key handling with rank 3 tensor | ||
| minsky::minsky().canvas.addVariable("3dTensor",VariableType::parameter); | ||
| auto& param=*minsky::minsky().canvas.itemFocus->variableCast(); | ||
| param.init("rand(3,3,3)"); | ||
| minsky::minsky().canvas.addSheet(); | ||
| auto& sheet=dynamic_cast<Sheet&>(*minsky::minsky().canvas.itemFocus); | ||
| minsky::minsky().model->addWire(param, sheet, 0); | ||
| minsky::minsky().reset(); | ||
|
|
||
| // Up arrow (0xff52) - should scroll up | ||
| EXPECT_TRUE(sheet.onKeyPress(0xff52, "", 0)); | ||
|
|
||
| // Down arrow (0xff54) - should scroll down | ||
| EXPECT_TRUE(sheet.onKeyPress(0xff54, "", 0)); | ||
|
|
||
| // Right arrow (0xff53) - should scroll up | ||
| EXPECT_TRUE(sheet.onKeyPress(0xff53, "", 0)); | ||
|
|
||
| // Left arrow (0xff51) - should scroll down | ||
| EXPECT_TRUE(sheet.onKeyPress(0xff51, "", 0)); | ||
|
|
||
| // Other key - should return false | ||
| EXPECT_FALSE(sheet.onKeyPress(0x0041, "A", 0)); | ||
| } | ||
|
|
||
| TEST_F(SheetTest, exportAsCSVWithoutValue) | ||
| { | ||
| // Attempting to export without a value should throw an error | ||
| string tmpFile = boost::filesystem::unique_path().string(); | ||
| EXPECT_THROW(exportAsCSV(tmpFile, false), std::exception); | ||
| } | ||
|
|
||
| TEST_F(SheetTest, setSliceIndicator) | ||
| { | ||
| // Add a rank 3 tensor to test slice indicator | ||
| minsky::minsky().canvas.addVariable("3dTensor",VariableType::parameter); | ||
| auto& param=*minsky::minsky().canvas.itemFocus->variableCast(); | ||
| param.init("rand(3,3,3)"); | ||
| minsky::minsky().canvas.addSheet(); | ||
| auto& sheet=dynamic_cast<Sheet&>(*minsky::minsky().canvas.itemFocus); | ||
| minsky::minsky().model->addWire(param, sheet, 0); | ||
| minsky::minsky().reset(); | ||
|
|
||
| // Check that sliceIndicator is set to something useful | ||
| EXPECT_FALSE(sheet.setSliceIndicator().empty()); | ||
| } | ||
| } | ||
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.