<commit_before>#! /usr/bin/env python

import numpy as np
from numpy.testing import assert_array_equal
from nose.tools import assert_equal

from cmt.grids.map import RectilinearMap as Rectilinear
from cmt.mappers import find_mapper, NearestVal, CellToPoint, PointToCell

from cmt.grids.map import (UniformRectilinearMap as UniformRectilinear)
from cmt.grids.map import (UnstructuredPointsMap as UnstructuredPoints)


def test_point_to_point():
    src = Rectilinear([0, 1, 2], [0, 2])
    dst = Rectilinear([.5, 1.5, 2.5], [.25, 1.25])

    src_vals = np.arange(src.get_point_count ())

    mapper = NearestVal()
    mapper.initialize(dst, src)
    dst_vals = mapper.run(src_vals)

    assert_array_equal(dst_vals, np.array([0., 1., 2., 3., 4., 5.]))

    mappers = find_mapper(dst, src)
    assert_equal(len(mappers), 3)
    assert_equal(mappers[0].name(), 'PointToPoint')

    src_vals[2] = -999
    dst_vals = np.zeros(dst.get_point_count()) - 1
    _ = mapper.run(src_vals, dst_vals)

    assert_array_equal(dst_vals, np.array([0., 1., -1., 3., 4., 5.]))


def test_cell_to_point():
    # The source grid looks like,
    #
    #    (0) ------ (1)
    #     |          |
    #     |          |
    #    (2) ------ (3)
    #     |          |
    #     |          |
    #    (4) ------ (5)
    #     |          |
    #     |          |
    #    (7) ------ (7)
    #

    (dst_x, dst_y) = (np.array([.45, 1.25, 3.5]),
                      np.array([.75, 2.25, 3.25]))

    src = UniformRectilinear((2,4), (2, 1), (0, 0))<commit_msg>Moved NearestVal tests into a separate module.<commit_after>#! /usr/bin/env python

import numpy as np
from numpy.testing import assert_array_equal

from cmt.mappers import CellToPoint, PointToCell

from cmt.grids.map import (UniformRectilinearMap as UniformRectilinear)
from cmt.grids.map import (UnstructuredPointsMap as UnstructuredPoints)


def test_cell_to_point():
    # The source grid looks like,
    #
    #    (0) ------ (1)
    #     |          |
    #     |          |
    #    (2) ------ (3)
    #     |          |
    #     |          |
    #    (4) ------ (5)
    #     |          |
    #     |          |
    #    (7) ------ (7)
    #

    (dst_x, dst_y) = (np.array([.45, 1.25, 3.5]),
                      np.array([.75, 2.25, 3.25]))

    src = UniformRectilinear((2,4), (2, 1), (0, 0))
{'fraction_non_alphanumeric': 0.16552609067579127, 'fraction_numerical': 0.03934987168520103, 'mean_word_length': 1.9495586380832282, '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': 1, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5302424', 'n_tokens_mistral': 941, 'n_tokens_neox': 846, 'n_words': 181}