Пример #1
0
    def test_json(self):
        lattice = Lattice([16, 8], 2)
        subsystem = SimpleSubsystem([4, 4], lattice)
        assert json.dumps(subsystem.to_json()) == '{"type": "SimpleSubsystem", "dimensions": [4, 4]}'

        assert Subsystem.from_json(subsystem.to_json(), lattice) == subsystem
        assert SimpleSubsystem.from_json(subsystem.to_json(), lattice) == subsystem
Пример #2
0
    def test_simple_subsystem(self):
        lattice = Lattice([8, 8], 2)
        subsystem = SimpleSubsystem([4, 6], lattice)

        inside = set()
        for site in lattice:
            if site in subsystem:
                inside.add(site)
            else:
                with pytest.raises(ValueError):
                    subsystem.index(site)

        assert len(inside) == len(subsystem)

        for i, site in enumerate(subsystem):
            assert subsystem[i] == site
            assert subsystem.index(site) == i
            inside.remove(site)

        assert len(inside) == 0