<commit_before>import qctests.EN_background_check
from util import main
import util.testingProfile
import numpy

##### EN_background_check ---------------------------------------------------

def test_EN_background_check_temperature():
    '''
    Make sure EN_background_check is flagging temperature excursions
    '''

    kwargs = {}
    main.readENBackgroundCheckAux(['EN_background_check'], kwargs)

    p = util.testingProfile.fakeProfile([1.8, 1.8, 1.8, 7.1], [0.0, 2.5, 5.0, 7.5], latitude=55.6, longitude=12.9, date=[1900, 01, 15, 0], probe_type=7) 
    qc = qctests.EN_background_check.test(p, **kwargs)
    expected = [False, False, False, True]
    assert numpy.array_equal(qc, expected), 'mismatch between qc results and expected values'


def test_EN_background_check_findGridCell():
    '''
    check behavior of grid cell identifier:
    wrap around to the beginning of the list after exceeding the end by more than one cell;
    same idea at the beginning.
    '''

    gridLat  = [10,20,30,40]
    gridLong = [10,20,30,40]
    p = util.testingProfile.fakeProfile([0], [0], latitude=9, longitude=51) 

    ilon, ilat = qctests.EN_background_check.findGridCell(p, gridLong, gridLat)
    assert ilon == 0
    assert ilat == 3

def test_EN_background_check_findGridCell_even_spacing():
    '''
    findGridCell will silently fail if grid spacings are not even;
    check that asserts are raised checking for this.
    '''

    gridLat  = [10,21,28,40]
    gridLong = [10,20,30,40]
    p = util.testingProfile.fakeProfile([0], [0], latitude=29, longitude=51) 

    try:
        ilon, ilat = qctests.EN_background_check.findGridCell(p, gridLong, gridLat)
    except AssertionError:
        assert True
        return

    try:
        ilon, ilat = qctests.EN_background_check.findGridCell(p, gridLat, gridLong)
    except AssertionError:
        assert True
        return

    assert False, "findGridCell failed to raise an exception for unevenly spaced grid points"

def test_EN_background_check_estimatePGE():
    '''
    check the basic behavior of the probable gross error prior estimator
    '''

    assert qctests.EN_background_check.estimatePGE(1, False) == 0.05, 'incorrect non-suspect bathythermograph pge'
    assert qctests.EN_background_check.estimatePGE(16, True) == 0.525, 'incorrect suspect bathythermograph pge'
    assert qctests.EN_background_check.estimatePGE(4, False) == 0.01, 'incorrect non-suspect non-bathythermograph pge'

<commit_msg>fixing merge issues<commit_after>import qctests.EN_background_check
from util import main
import util.testingProfile
import numpy

##### EN_background_check ---------------------------------------------------

def test_EN_background_check_temperature():
    '''
    Make sure EN_background_check is flagging temperature excursions
    '''

    kwargs = {}
    main.readENBackgroundCheckAux(['EN_background_check'], kwargs)

    p = util.testingProfile.fakeProfile([1.8, 1.8, 1.8, 7.1], [0.0, 2.5, 5.0, 7.5], latitude=55.6, longitude=12.9, date=[1900, 01, 15, 0], probe_type=7) 
    qc = qctests.EN_background_check.test(p, **kwargs)
    expected = [False, False, False, True]
    assert numpy.array_equal(qc, expected), 'mismatch between qc results and expected values'

def test_EN_background_check_findGridCell():
    '''
    check behavior of grid cell identifier:
    wrap around to the beginning of the list after exceeding the end by more than one cell;
    same idea at the beginning.
    '''

    gridLat  = [10,20,30,40]
    gridLong = [10,20,30,40]
    p = util.testingProfile.fakeProfile([0], [0], latitude=9, longitude=51) 

    ilon, ilat = qctests.EN_background_check.findGridCell(p, gridLong, gridLat)
    assert ilon == 0
    assert ilat == 3

def test_EN_background_check_findGridCell_even_spacing():
    '''
    findGridCell will silently fail if grid spacings are not even;
    check that asserts are raised checking for this.
    '''

    gridLat  = [10,21,28,40]
    gridLong = [10,20,30,40]
    p = util.testingProfile.fakeProfile([0], [0], latitude=29, longitude=51) 

    try:
        ilon, ilat = qctests.EN_background_check.findGridCell(p, gridLong, gridLat)
    except AssertionError:
        assert True
        return

    try:
        ilon, ilat = qctests.EN_background_check.findGridCell(p, gridLat, gridLong)
    except AssertionError:
        assert True
        return

    assert False, "findGridCell failed to raise an exception for unevenly spaced grid points"

def test_EN_background_check_estimatePGE():
    '''
    check the basic behavior of the probable gross error prior estimator
    '''

    assert qctests.EN_background_check.estimatePGE(1, False) == 0.05, 'incorrect non-suspect bathythermograph pge'
    assert qctests.EN_background_check.estimatePGE(16, True) == 0.525, 'incorrect suspect bathythermograph pge'
    assert qctests.EN_background_check.estimatePGE(4, False) == 0.01, 'incorrect non-suspect non-bathythermograph pge'
{'fraction_non_alphanumeric': 0.11952352109832425, 'fraction_numerical': 0.03674540682414698, 'mean_word_length': 3.49546279491833, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, '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': '4612759', 'n_tokens_mistral': 1709, 'n_tokens_neox': 1547, 'n_words': 418}