import unittest
import numpy as np
import helperFunctions as hF
import matplotlib.pyplot as plt


class HelperFunctionsTester(unittest.TestCase):

    noise_levels = [0, 0.05, 0.1, 0.2]
    frequencies = [0, 1, 5, 30, 100, 500, 750, 1000]

    def setUp(self):
        pass

    def tearDown(self):
        pass

    def test__vector_strength__is_1(self):
        length = 2000
        rel_spike_times = np.full(length, 0.3)
        eod_durations = np.full(length, 0.14)

        self.assertEqual(1, round(hF.__vector_strength__(rel_spike_times,eod_durations), 2))

    def test__vector_strength__is_0(self):
        length = 2000
        period = 0.14
        rel_spike_times = np.arange(0, period, period/length)
        eod_durations = np.full(length, period)

        self.assertEqual(0, round(hF.__vector_strength__(rel_spike_times, eod_durations), 5))

    # def test_eods_around_spikes(self):
    #
    #     time = np.arange(0, 3, 0.01)
    #     eod = np.sin(2*np.pi * 2 * time)
    #
    #     spikes = [0.2, 0.5, 0.6]
    #     indices = np.searchsorted(time, spikes)
    #
    #     rel_spike_time, eod_duration = hF.eods_around_spikes(time, eod, indices)
    #
    #     print("meep")


    # todo
    #  search_eod_start_and_end_times ? (not used anymore ?)
    #  eods_around_spikes
    #  calculate_phases

    # def test(self):
    #    test_distribution()