import qctests.ICDC_aqc_01_level_order as ICDC
import qctests.ICDC_aqc_02_crude_range as ICDC_crude_range

import util.testingProfile
import util.main as main
import numpy as np

##### ICDC crude range check.
##### --------------------------------------------------

class TestClass():

    parameters = {}

    def setUp(self):
        # refresh this table every test
        ICDC.loadParameters(self.parameters)

    def tearDown(self):
        main.dbinteract('DROP TABLE icdclevelorder;')

    def test_ICDC_crude_range(self):
        '''Make sure code processes data supplied by Viktor Gouretski
           correctly.
        '''

        examples = [example1, example2, example3, 
                    example4, example5, example6]

        for i, example in enumerate(examples):
            z = example[:, 0]
            t = example[:, 1]
            f = example[:, 2]

            qctruth = f > 0
            p = util.testingProfile.fakeProfile(t, z, uid=i)
            qc = ICDC_crude_range.test(p, self.parameters)

            assert np.array_equal(qc, qctruth), 'Example %i failed' % (i + 1)

# Data provided by Viktor Gouretski, ICDC, University of Hamburg.
example1 = np.array([
[     .0,    28.600,  0],
[   10.0,    28.600,  0],
[   25.0,    28.520,  0],
[   50.0,    27.410,  0],
[   73.0,    25.120,  0],
[   98.0,    24.390,  0],
[  122.0,    23.320,  0],
[  147.0,    22.790,  0],
[  197.0,    22.040,  0],
[  247.0,    21.880,  0],
[  297.0,    21.860,  0],
[  396.0,    21.780,  0],
[  496.0,    21.760,  0],
[  595.0,    21.740,  0],
[  795.0,    21.810,  0],
[  994.0,    21.840,  0],
[ 1193.0,    21.860,  0],
[ 1492.0,    21.930,  0],
[ 1888.0,    21.960,  0],
[ 1937.0,    22.330,  0],
[ 1987.0,    24.560,  2],
[ 2008.0,    38.150,  1],
[ 2027.0,    48.800,  1]])
example2 = np.array([
[     .0,    30.310,  0],
[    5.0,    30.310,  0],
[   18.0,    29.260,  0],
[   30.0,    29.170,  0],