Skip to content

Commit

Permalink
add test for computed decorator
Browse files Browse the repository at this point in the history
  • Loading branch information
pLeminoq committed Dec 13, 2024
1 parent a714f80 commit 0b6e177
Showing 1 changed file with 19 additions and 0 deletions.
19 changes: 19 additions & 0 deletions tests/test_higher_order_state.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
StringState,
ObjectState,
HigherOrderState,
computed,
)

from .util import MockCallback
Expand Down Expand Up @@ -109,3 +110,21 @@ def test_copy_from(super_state: SuperState) -> None:
assert super_state.name.value == "Test"
assert super_state.count.value == 2
assert super_state.nested.length.value == 2.71


def test_computed() -> None:
class ExampleState(HigherOrderState):
def __init__(self):
super().__init__()

self.a = IntState(0)
self.b = IntState(1)

@computed
def sum(self, a: IntState, b: IntState) -> IntState:
return IntState(a.value + b.value)

ex = ExampleState()
assert ex.sum.value == 1
ex.a.value = 5
assert ex.sum.value == 6

0 comments on commit 0b6e177

Please sign in to comment.