def test_add(self): a = Leaf(3.0) b = Leaf(4.0) c = a + b self.assertEqual(c.value, 7.0) a.value = 5.0 c.invalidate() self.assertEqual(c.value, 9.0)
def test_nested(self): a, b = Leaf(3.0), Leaf(2.0) c = [ a * b, (a * b, a * b), {a * b, a * b, a * b}, ([a * b, a * b], (a * b, a * b)) ] c = SaltArray(c) vc = c.value ref = [6.0, [6.0, 6.0], [6.0, 6.0, 6.0], [[6.0, 6.0], [6.0, 6.0]]] self.assertListEqual(ref, vc) c.invalidate() a.value = 4.0 ref = [8.0, [8.0, 8.0], [8.0, 8.0, 8.0], [[8.0, 8.0], [8.0, 8.0]]] vc = c.value self.assertListEqual(ref, vc) a.value = 5.0 vc = c.recalc() ref = [ 10.0, [10.0, 10.0], [10.0, 10.0, 10.0], [[10.0, 10.0], [10.0, 10.0]] ] self.assertListEqual(ref, vc)