Beispiel #1
0
def test_atom_copy():
    atom = Atom("A", energy=1.0)

    copy = atom.copy()
    assert copy.name == atom.name
    assert copy.energy == atom.energy
    atom.energy = 2.0
    assert copy.energy != atom.energy
Beispiel #2
0
def test_atoms_equal():
    atom1 = Atom("A", energy=1.0)
    atom2 = Atom("B")
    atom3 = Atom("B", energy=1.0)
    assert atom1 != atom2
    assert atom2 == atom3
    assert atom1 == "A"
    assert atom1 != "B"
    assert atom2 == "B"
    assert atom3 == "B"
Beispiel #3
0
def test_atom_params():
    atom = Atom("A", color="r", energy=1)

    assert atom.color == "r"
    assert atom["color"] == "r"

    assert atom.energy == 1
    assert atom["energy"] == 1

    atom["spin"] = 1
    assert atom.spin == 1
    assert atom["spin"] == 1

    atom.spin = 1
    assert atom.spin == 1
    assert atom["spin"] == 1

    assert atom.get("spin") == 1

    del atom["spin"]

    assert atom.get("spin", None) is None
Beispiel #4
0
def test_atom_iter():
    atom = Atom("A", energy=1.0)
    assert list(atom) == ["color", "radius", "energy"]
Beispiel #5
0
def test_atom_param_length():
    atom = Atom("A", energy=1.0)
    assert len(atom) == 3
Beispiel #6
0
def test_atom_to_dict():
    atom = Atom("A", energy=1.0)
    expected = {"name": "A", "color": None, "radius": 0.2, "energy": 1.0}
    actual = atom.dict()
    actual.pop("index")
    assert actual == expected
Beispiel #7
0
def test_atom_uniqueness():
    atom1 = Atom("A")
    atom2 = Atom("A")
    assert atom1 == atom2
    assert atom1.__hash__() == atom2.__hash__()

    atom1 = Atom("A")
    atom2 = Atom("B")
    assert atom1 != atom2
    assert atom1.__hash__() != atom2.__hash__()