From 0b6e17749da9a4509965e57d479f6ec332ea7b7e Mon Sep 17 00:00:00 2001 From: Tamino Huxohl Date: Fri, 13 Dec 2024 14:00:25 +0100 Subject: [PATCH] add test for computed decorator --- tests/test_higher_order_state.py | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/tests/test_higher_order_state.py b/tests/test_higher_order_state.py index 02d2619..ee4c51a 100644 --- a/tests/test_higher_order_state.py +++ b/tests/test_higher_order_state.py @@ -11,6 +11,7 @@ StringState, ObjectState, HigherOrderState, + computed, ) from .util import MockCallback @@ -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