-
Notifications
You must be signed in to change notification settings - Fork 0
Update test.py #3
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
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -13,3 +13,41 @@ def test_set_background_successfully(self): | |
| background_image = cv2.imread('background.jpg') | ||
| detector.setBackground(background_image) | ||
| assert detector.getBackground() is not None | ||
|
|
||
| # Tests that a binary image is returned successfully after the detection process | ||
| def test_return_binary_image_successfully(self): | ||
| detector = DiffMotionDetector() | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Consider refactoring the repeated setup code for initializing |
||
| background_image = cv2.imread('background.jpg') | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Consider optimizing the image loading in tests by loading the images once and reusing them, instead of loading them in each test. This will reduce the I/O operations and make the tests run faster. [important] |
||
| foreground_image = cv2.imread('foreground.jpg') | ||
| detector.setBackground(background_image) | ||
| binary_image = detector.returnMask(foreground_image) | ||
| assert binary_image is not None | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Consider adding assertions to check the actual content of the binary image, not just its existence. This would ensure that the binary image is correctly processed and meets expected conditions. [important] |
||
|
|
||
| # Tests that a background image is set and a binary image is returned successfully after the detection process | ||
| def test_set_background_and_return_binary_image_successfully(self): | ||
| detector = DiffMotionDetector() | ||
| background_image = cv2.imread('background.jpg') | ||
| foreground_image = cv2.imread('foreground.jpg') | ||
| detector.setBackground(background_image) | ||
| binary_image = detector.returnMask(foreground_image) | ||
| assert detector.getBackground() is not None and binary_image is not None | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It might be beneficial to add a cleanup step in your tests to release resources or reset the detector state after each test. This can prevent state leakage between tests and ensure that each test runs in a clean state. [medium] |
||
|
|
||
| # Tests that setting a None background image returns None | ||
| def test_set_none_background_image_and_return_none(self): | ||
| detector = DiffMotionDetector() | ||
| detector.setBackground(None) | ||
| assert detector.getBackground() is None | ||
|
|
||
| # Tests that setting a None foreground image returns None | ||
| def test_set_none_foreground_image_and_return_none(self): | ||
| detector = DiffMotionDetector() | ||
| background_image = cv2.imread('background.jpg') | ||
| detector.setBackground(background_image) | ||
| binary_image = detector.returnMask(None) | ||
| assert binary_image is None | ||
|
|
||
| # Tests that setting a None background image returns None after the detection process | ||
| def test_set_none_background_image_and_return_none_after_detection_process(self): | ||
| detector = DiffMotionDetector() | ||
| detector.setBackground(None) | ||
| assert detector.getBackground() is None | ||
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.
Combine the tests
test_return_binary_image_successfullyandtest_set_background_and_return_binary_image_successfullyto optimize test execution and avoid redundancy. You can check both conditions in a single test since they are closely related. [important]