#!/usr/bin/env python3
# -*- coding: utf-8 -*-
#
# Copyright 2020-2025 Félix Chénier

# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at

#     http://www.apache.org/licenses/LICENSE-2.0

# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.


"""Unit tests, to be run using pytest."""


__author__ = "Félix Chénier"
__copyright__ = "Copyright (C) 2020-2025 Félix Chénier"
__email__ = "chenier.felix@uqam.ca"
__license__ = "Apache 2.0"


import kineticstoolkit_extensions.n3d as n3d
import numpy as np
import os


this_folder = os.path.dirname(__file__)


def test_read_n3d():
    """
    Non-regression test.

    A non-regression test is a test where the data generated by the function
    has been validated manually at a given time, and that from now on, the
    function always generate the same data. It is an easy way to ensure that
    future versions of Kinetics Toolkit, Python or other dependencies do not
    break this function.

    """
    markers = n3d.read_n3d(this_folder + "/data/n3d_sample_optotrak.n3d")

    assert np.allclose(np.sum(markers.data["Marker0"]), 172.3365)
    assert np.allclose(np.sum(markers.data["Marker40"]), -45.3753)
    assert markers.time_info["Unit"] == "s"
    assert markers.data_info["Marker40"]["Unit"] == "m"

    labels = [
        "Probe1",
        "Probe2",
        "Probe3",
        "Probe4",
        "Probe5",
        "Probe6",
        "FRArrD",
        "FRArrG",
        "FRav",
        "ScapulaG1",
        "ScapulaG2",
        "ScapulaG3",
        "ScapulaD1",
        "ScapulaD2",
        "ScapulaD3",
        "Tete1",
        "Tete2",
        "Tete3",
        "Sternum",
        "BrasG1",
        "BrasG2",
        "BrasG3",
        "EpicondyleLatG",
        "AvBrasG1",
        "AvBrasG2",
        "AvBrasG3",
        "NAG",
        "GantG1",
        "GantG2",
        "GantG3",
        "BrasD1",
        "BrasD2",
        "BrasD3",
        "EpicondyleLatD",
        "AvBrasD1",
        "AvBrasD2",
        "AvBrasD3",
        "NAD",
        "GantD1",
        "GantD2",
        "GantD3",
    ]

    markers = n3d.read_n3d(
        this_folder + "/data/n3d_sample_optotrak.n3d",
        labels=labels,
    )

    assert np.allclose(np.sum(markers.data["Probe1"]), 172.3365)
    assert np.allclose(np.sum(markers.data["GantD3"]), -45.3753)
    assert markers.time_info["Unit"] == "s"
    assert markers.data_info["GantD3"]["Unit"] == "m"


if __name__ == "__main__":
    import pytest

    pytest.main([__file__])
