import numpy as np

from warp_md.analysis.dssp import dssp


class _DummySelection:
    def __init__(self, indices):
        self.indices = indices


class _DummySystem:
    def __init__(self):
        self._atoms = {
            "name": ["N", "CA", "C", "N", "CA", "C"],
            "resname": ["ALA", "ALA", "ALA", "GLY", "GLY", "GLY"],
            "resid": [1, 1, 1, 2, 2, 2],
            "chain_id": [0, 0, 0, 0, 0, 0],
        }

    def atom_table(self):
        return self._atoms

    def select(self, _mask):
        return _DummySelection(range(len(self._atoms["name"])))


class _DummyTraj:
    def __init__(self, coords):
        self._coords = coords
        self._used = False

    def read_chunk(self, _max_frames=128):
        if self._used:
            return None
        self._used = True
        return {"coords": self._coords}


def test_dssp_shapes():
    coords = np.zeros((1, 6, 3), dtype=np.float64)
    traj = _DummyTraj(coords)
    system = _DummySystem()
    labels, ss, avg = dssp(traj, system, mask="protein")
    assert labels.shape == (2,)
    assert ss.shape == (1, 2)
    assert set(np.unique(ss)) <= {"C"}
    assert avg.get("C", 0.0) == 2.0
