<commit_before>import unittest
from mock import patch
from TSatPy import State, StateOperators, Estimator
from TSatPy.Clock import Metronome
import numpy as np


class TestPID(unittest.TestCase):

    def test_str(self):
        k = 3
        c = Metronome()
        Kq = StateOperators.QuaternionGain(k)
        Kw = StateOperators.BodyRateGain([[k,0,0],[0,k,0],[0,0,k]])
        Kp = StateOperators.StateGain(Kq, Kw)

        pid = Estimator.PID(c)
        pid.set_Kp(Kp)

        str_expected = [
            'PID',
            ' x_hat <Quaternion [0 0 0], 1>, <BodyRate [0 0 0]>',
            ' Ki None',
            ' Kp <StateGain <Kq 3>, <Kw = [[3 0 0] [0 3 0] [0 0 3]]>>',
            ' Kd None',
        ]
        self.assertEquals('\n'.join(str_expected), str(pid))

    def test_p_estimator(self):
        c = Metronome()
        k = 0.2
        Kq = StateOperators.QuaternionGain(k)
        Kw = StateOperators.BodyRateGain([[k,0,0],[0,k,0],[0,0,k]])
        Kp = StateOperators.StateGain(Kq, Kw)

        pid = Estimator.PID(c)
        pid.set_Kp(Kp)

        x = State.State(
            State.Quaternion([0,0,1],radians=np.pi/15),
            State.BodyRate([0.1,2,3])
        )
        x_hat = pid.update(x)

        x_expected = State.State(
            State.Quaternion([0,0,1],radians=np.pi/75),
            State.BodyRate([0.02,0.4,0.6]))

        self.assertEquals(x_hat, x_expected)

    def test_p_estimator_with_ic(self):
        c = Metronome()
        k = 0.2
        Kq = StateOperators.QuaternionGain(k)
        Kw = StateOperators.BodyRateGain([[k,0,0],[0,k,0],[0,0,k]])
        Kp = StateOperators.StateGain(Kq, Kw)
        ic = State.State(
            State.Quaternion([0,0,1],radians=np.pi/10),
            State.BodyRate([0,0,1])
        )

        pid = Estimator.PID(c, ic=ic)
        pid.set_Kp(Kp)

        x = State.State(
            State.Quaternion([0,0,1],radians=6*np.pi/10),
            State.BodyRate([0.1,2,3])
        )
        x_hat = pid.update(x)

        x_expected = State.State(
            State.Quaternion([0,0,1],radians=2*np.pi/10),
            State.BodyRate([0.02,0.4,1.4]))

        self.assertEquals(x_hat, x_expected)

    @patch('time.time')
    def test_i_estimator(self, mock_time):

        mock_time.return_value = 1234

        c = Metronome()
        k = 0.5
        Kq = StateOperators.QuaternionGain(k)
        Kw = StateOperators.BodyRateGain([[k,0,0],[0,k,0],[0,0,k]])
        Ki = StateOperators.StateGain(Kq, Kw)

        pid = Estimator.PID(c)
        pid.set_Ki(Ki)

        mock_time.return_value = 1235

        x = State.State(
            State.Quaternion([0,0,1],radians=0.1),
            State.BodyRate([0.1,2,3])
        )

        # No state adjustment off ic on first update
        x_hat = pid.update(x)
        self.assertEquals(x_hat, State.State())
<commit_msg>easier test numbers<commit_after>import unittest
from mock import patch
from TSatPy import State, StateOperators, Estimator
from TSatPy.Clock import Metronome
import numpy as np


class TestPID(unittest.TestCase):

    def test_str(self):
        k = 3
        c = Metronome()
        Kq = StateOperators.QuaternionGain(k)
        Kw = StateOperators.BodyRateGain([[k,0,0],[0,k,0],[0,0,k]])
        Kp = StateOperators.StateGain(Kq, Kw)

        pid = Estimator.PID(c)
        pid.set_Kp(Kp)

        str_expected = [
            'PID',
            ' x_hat <Quaternion [0 0 0], 1>, <BodyRate [0 0 0]>',
            ' Ki None',
            ' Kp <StateGain <Kq 3>, <Kw = [[3 0 0] [0 3 0] [0 0 3]]>>',
            ' Kd None',
        ]
        self.assertEquals('\n'.join(str_expected), str(pid))

    def test_p_estimator(self):
        c = Metronome()
        k = 0.2
        Kq = StateOperators.QuaternionGain(k)
        Kw = StateOperators.BodyRateGain([[k,0,0],[0,k,0],[0,0,k]])
        Kp = StateOperators.StateGain(Kq, Kw)

        pid = Estimator.PID(c)
        pid.set_Kp(Kp)

        x = State.State(
            State.Quaternion([0,0,1],radians=np.pi/15),
            State.BodyRate([0.1,2,3])
        )
        x_hat = pid.update(x)

        x_expected = State.State(
            State.Quaternion([0,0,1],radians=np.pi/75),
            State.BodyRate([0.02,0.4,0.6]))

        self.assertEquals(x_hat, x_expected)

    def test_p_estimator_with_ic(self):
        c = Metronome()
        k = 0.2
        Kq = StateOperators.QuaternionGain(k)
        Kw = StateOperators.BodyRateGain([[k,0,0],[0,k,0],[0,0,k]])
        Kp = StateOperators.StateGain(Kq, Kw)
        ic = State.State(
            State.Quaternion([0,0,1],radians=0.1),
            State.BodyRate([0,0,1])
        )

        pid = Estimator.PID(c, ic=ic)
        pid.set_Kp(Kp)

        x = State.State(
            State.Quaternion([0,0,1],radians=0.6),
            State.BodyRate([0.1,2,3])
        )
        x_hat = pid.update(x)

        x_expected = State.State(
            State.Quaternion([0,0,1],radians=0.2),
            State.BodyRate([0.02,0.4,1.4]))

        self.assertEquals(x_hat, x_expected)

    @patch('time.time')
    def test_i_estimator(self, mock_time):

        mock_time.return_value = 1234

        c = Metronome()
        k = 0.5
        Kq = StateOperators.QuaternionGain(k)
        Kw = StateOperators.BodyRateGain([[k,0,0],[0,k,0],[0,0,k]])
        Ki = StateOperators.StateGain(Kq, Kw)

        pid = Estimator.PID(c)
        pid.set_Ki(Ki)

        mock_time.return_value = 1235

        x = State.State(
            State.Quaternion([0,0,1],radians=0.1),
            State.BodyRate([0.1,2,3])
        )

        # No state adjustment off ic on first update
        x_hat = pid.update(x)
        self.assertEquals(x_hat, State.State())

{'fraction_non_alphanumeric': 0.15023721665788087, 'fraction_numerical': 0.040766121946933756, 'mean_word_length': 2.0308839190628327, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 13, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7365916', 'n_tokens_mistral': 2280, 'n_tokens_neox': 2145, 'n_words': 340}