def test_env_add(): skx = SymbolicKeyInstance("x", 1) sky = SymbolicKeyInstance("y", 2) ex = newenv.set(skx, 10) ey = newenv.set(sky, 20) exy = newenv.set(skx, 7).set(sky, 8) new = ex.add(ey) assert new.get(skx, 0) == 10 assert new.get(sky, 0) == 20 new = ey.add(ex) assert new.get(skx, 0) == 10 assert new.get(sky, 0) == 20 new = exy.add(ex) assert new.get(skx, 0) == 17 assert new.get(sky, 0) == 8
def test_env(): sk1 = SymbolicKeyInstance('x', {}) sk1b = SymbolicKeyInstance('x', {}) assert sk1 == sk1b sk2 = SymbolicKeyInstance('y', {}) e = newenv.set(sk1, 100) assert e is not newenv assert len(newenv) == 0 assert len(e) == 1 assert e.get(sk1, 0) == 100 assert e.get(sk2, 0) == 0 e = e.set(sk1b, 200) assert len(e) == 1 assert e.get(sk1, 0) == 200 assert e.get(sk2, 0) == 0 e = e.set(sk2, 300) assert len(e) == 2 assert e.get(sk1, 0) == 200 assert e.get(sk2, 0) == 300