<commit_before># -*- coding: utf-8 -*-
# vim: tabstop=4 shiftwidth=4 softtabstop=4

import os
import unittest
from opengem import shapes
from opengem.parser import exposure

TEST_FILE = 'LossRatioCurves-test.xml'

data_dir = os.path.join(os.path.dirname(__file__), 'data')

class LossRatioCurveFileTestCase(unittest.TestCase):

    def test_filter_region_constraint_known_to_fail(self):

        # set region in which no site is found in input file
        region_constraint = shapes.RegionConstraint.from_simple((40.0, 10.0),
                                                                (42.0, 14.0))
        ep = loss_ratio_curve.LossRatioCurveFile(
            os.path.join(data_dir, TEST_FILE))

        ctr = None

        # this loop is not expected to be entered - generator should
        # not yield any item
        for ctr, loss_ratio_item in enumerate(ep.filter(
            region_constraint)):
            pass

        # ensure that generator didn't yield an item
        self.assertTrue(ctr is None, 
            "filter yielded item(s) although no items were expected")

    def test_filter_region_constraint_one_site(self):

        # look for sites within specified rectangle
        # constraint is met by one and only one site in the example file 
        # 9.15333 45.12200
        region_constraint = shapes.RegionConstraint.from_simple(
            (9.15332, 45.12201), (9.15334, 45.12199))
        ep = loss_ratio_curve.LossRatioCurveFile(
            os.path.join(data_dir, TEST_FILE))

        expected_result = [
            (shapes.Point(41.0, 12.0),
            {'CurvePointPE': [0.0, 1280.0, 2560.0, 3840.0, 5120.0, 6400.0, 
            8320.0, 10240.0, 12160.0, 14080.0, 16000.0, 21120.0, 26240.0, 
            31360.0, 36480.0, 41600.0, 49280.0, 56960.0, 64640.0, 72320.0, 
            80000.0, 90240.0, 100480.0, 110720.0, 120960.0, 131200.0, 
            140160.0, 149120.0, 158080.0, 167040.0, 176000.0, 189440.0, 
            202880.0, 216320.0, 229760.0, 243200.0],
            'CurvePointLoss': [0.241053927419, 0.234871039103, 0.22617525424,
            0.214873509183, 0.201308289741, 0.186256995833, 0.163216429503, 
            0.142564936604, 0.126054023695, 0.113487409083, 0.103636128779, <commit_msg>loss-ratio-map is merged with risk-engine-port branch<commit_after># -*- coding: utf-8 -*-
# vim: tabstop=4 shiftwidth=4 softtabstop=4

import os
import unittest
from opengem import shapes
from opengem.parser import exposure

TEST_FILE = 'LossRatioCurves-test.xml'

data_dir = os.path.join(os.path.dirname(__file__), 'data')

class LossRatioCurveFileTestCase(unittest.TestCase):

    def test_filter_region_constraint_known_to_fail(self):

        # set region in which no site is found in input file
        region_constraint = shapes.RegionConstraint.from_simple((40.0, 10.0),
                                                                (42.0, 14.0))
        ep = loss_ratio_curve.LossRatioCurveFile(
            os.path.join(data_dir, TEST_FILE))

        ctr = None

        # this loop is not expected to be entered - generator should
        # not yield any item
        for ctr, loss_ratio_item in enumerate(ep.filter(
            region_constraint)):
            pass

        # ensure that generator didn't yield an item
        self.assertTrue(ctr is None, 
            "filter yielded item(s) although no items were expected")

    def test_filter_region_constraint_one_site(self):

        # look for sites within specified rectangle
        # constraint is met by one and only one site in the example file 
        # 9.15333 45.12200
        region_constraint = shapes.RegionConstraint.from_simple(
            (9.15332, 45.12201), (9.15334, 45.12199))
        ep = loss_ratio_curve.LossRatioCurveFile(
            os.path.join(data_dir, TEST_FILE))


        expected_result = [
            (shapes.Point(41.0, 12.0),
            {'CurvePointPE': [0.0, 1280.0, 2560.0, 3840.0, 5120.0, 6400.0, 
            8320.0, 10240.0, 12160.0, 14080.0, 16000.0, 21120.0, 26240.0, 
            31360.0, 36480.0, 41600.0, 49280.0, 56960.0, 64640.0, 72320.0, 
            80000.0, 90240.0, 100480.0, 110720.0, 120960.0, 131200.0, 
            140160.0, 149120.0, 158080.0, 167040.0, 176000.0, 189440.0, 
            202880.0, 216320.0, 229760.0, 243200.0],
            'CurvePointLoss': [0.241053927419, 0.234871039103, 0.22617525424,
            0.214873509183, 0.201308289741, 0.186256995833, 0.163216429503, 
            0.142564936604, 0.126054023695, 0.113487409083, 0.103636128779, 
{'fraction_non_alphanumeric': 0.10482272627174631, 'fraction_numerical': 0.1863025765249945, 'mean_word_length': 2.2936910804931108, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 2}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 4, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3301197', 'n_tokens_mistral': 2072, 'n_tokens_neox': 1528, 'n_words': 353}