-
Notifications
You must be signed in to change notification settings - Fork 699
Optimize Some Statement Evaluation and Fix Correctness Mismatches #3083
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 1 commit
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 |
|---|---|---|
|
|
@@ -105,6 +105,25 @@ def test_some(): | |
| assert bool(Some(0, [Number(1)]).evaluate({Number(0): {ADDR1}})) is True | ||
| assert bool(Some(1, [Number(1)]).evaluate({Number(0): {ADDR1}})) is False | ||
|
|
||
| # Test Some(0, []) correctness (should evaluate to True in both short-circuit modes) | ||
|
Collaborator
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. imho this isn't a reasonable structure for a rule, so this test is noise. |
||
| assert Some(0, []).evaluate({Number(0): {ADDR1}}, short_circuit=True).success is True | ||
| assert Some(0, []).evaluate({Number(0): {ADDR1}}, short_circuit=False).success is True | ||
|
|
||
| # Test Some(0, [Child]) optimization (child must not be evaluated when short-circuit is True) | ||
| class TrackingFeature(Number): | ||
|
Collaborator
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. i find this to be an overly clever way to test the behavior. i'm not sure that the behavior is worth the code maintenance investment for this test. i don't think the the behavior will likely regress. therefore i'd propose to remove these tests, too, but i'm open to discussion. thoughts? |
||
| def __init__(self, value): | ||
| super().__init__(value) | ||
| self.evaluated = False | ||
|
|
||
| def evaluate(self, features, short_circuit=True): | ||
| self.evaluated = True | ||
| return super().evaluate(features, short_circuit) | ||
|
|
||
| tracker = TrackingFeature(1) | ||
| res = Some(0, [tracker]).evaluate({Number(0): {ADDR1}}, short_circuit=True) | ||
| assert res.success is True | ||
| assert tracker.evaluated is False # Must not be evaluated! | ||
|
|
||
| assert bool(Some(2, [Number(1), Number(2), Number(3)]).evaluate({Number(0): {ADDR1}})) is False | ||
| assert bool(Some(2, [Number(1), Number(2), Number(3)]).evaluate({Number(0): {ADDR1}, Number(1): {ADDR1}})) is False | ||
| assert ( | ||
|
|
||
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.
it doesn't make sense for count to be less than 0, so this condition is better expressed as
if self.count == 0. if we don't have validation that count is at least 0, then we should add that in the rule loading code, not try to handle the case here.