-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Do not do a full recalc when creating a new Var.
This is to avoid triggering the calculation of lazy variables in the chain. Method .w renamed to .widget_set as it makes more sense. Added new testcases
- Loading branch information
1 parent
3f9496b
commit a1704a5
Showing
3 changed files
with
81 additions
and
9 deletions.
There are no files selected for viewing
This file contains 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 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,55 @@ | ||
from autocalc.autocalc import Var | ||
|
||
# c depends on b, which depends on a | ||
# a -> b -> c | ||
def double(x): | ||
return 2*x | ||
|
||
class EC(): | ||
def __init__(self): | ||
self.execution_count = 0 | ||
|
||
@property | ||
def executed(self): | ||
v = self.execution_count | ||
self.execution_count = 0 | ||
return v | ||
|
||
def fun(self, x): | ||
self.execution_count += 1 | ||
return 2*x | ||
|
||
|
||
def test_proper_function_triggering(): | ||
ecB = EC() | ||
ecC = EC() | ||
a = Var('A', initial_value=1) | ||
b = Var('B', fun=ecB.fun, inputs=[a]) | ||
assert ecB.executed | ||
c = Var('C', fun=ecC.fun, inputs=[b]) | ||
assert not ecB.executed | ||
assert ecC.executed | ||
|
||
assert c._get_raw() == 4 | ||
assert c.get() == 4 | ||
|
||
assert not ecB.executed | ||
assert not ecC.executed | ||
|
||
b.set(6) | ||
|
||
assert not ecB.executed | ||
assert ecC.executed | ||
|
||
assert c._get_raw() == 12 | ||
assert a._get_raw() == 1 | ||
|
||
a.set(2) | ||
|
||
assert ecB.executed | ||
assert ecC.executed | ||
|
||
assert c.get() == 8 | ||
assert not ecC.executed | ||
|
||
|
This file contains 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