<s> """<STR_LIT>""" <EOL> from __future__ import division , print_function , absolute_import <EOL> import unittest <EOL> from numpy import arange , allclose , ones , isnan <EOL> import numpy as np <EOL> from scipy . interpolate . interpolate_wrapper import ( linear , logarithmic , <EOL> block_average_above , nearest ) <EOL> class Test ( unittest . TestCase ) : <EOL> def assertAllclose ( self , x , y , rtol = <NUM_LIT> ) : <EOL> for i , xi in enumerate ( x ) : <EOL> self . assertTrue ( allclose ( xi , y [ i ] , rtol ) or ( isnan ( xi ) and isnan ( y [ i ] ) ) ) <EOL> def test_nearest ( self ) : <EOL> N = <NUM_LIT:5> <EOL> x = arange ( N ) <EOL> y = arange ( N ) <EOL> self . assertAllclose ( y , nearest ( x , y , x + <NUM_LIT> ) ) <EOL> self . assertAllclose ( y , nearest ( x , y , x - <NUM_LIT> ) ) <EOL> def test_linear ( self ) : <EOL> N = <NUM_LIT> <EOL> x = arange ( N ) <EOL> y = arange ( N ) <EOL> new_x = arange ( N ) + <NUM_LIT:0.5> <EOL> new_y = linear ( x , y , new_x ) <EOL> self . assertAllclose ( new_y [ : <NUM_LIT:5> ] , [ <NUM_LIT:0.5> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> ] ) <EOL> def test_block_average_above ( self ) : <EOL> N = <NUM_LIT> <EOL> x = arange ( N , dtype = float ) <EOL> y = arange ( N , dtype = float ) <EOL> new_x = arange ( N // <NUM_LIT:2> ) * <NUM_LIT:2> <EOL> new_y = block_average_above ( x , y , new_x ) <EOL> self . assertAllclose ( new_y [ : <NUM_LIT:5> ] , [ <NUM_LIT:0.0> , <NUM_LIT:0.5> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> ] ) <EOL> def test_linear2 ( self ) : <EOL> N = <NUM_LIT> <EOL> x = arange ( N , dtype = float ) <EOL> y = ones ( ( <NUM_LIT:100> , N ) ) * arange ( N ) <EOL> new_x = arange ( N ) + <NUM_LIT:0.5> <EOL> new_y = linear ( x , y , new_x ) <EOL> self . assertAllclose ( new_y [ : <NUM_LIT:5> , : <NUM_LIT:5> ] , <EOL> [ [ <NUM_LIT:0.5> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> ] , <EOL> [ <NUM_LIT:0.5> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> ] , <EOL> [ <NUM_LIT:0.5> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> ] , <EOL> [ <NUM_LIT:0.5> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> ] , <EOL> [ <NUM_LIT:0.5> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> ] ] ) <EOL> def test_logarithmic ( self ) : <EOL> N = <NUM_LIT> <EOL> x = arange ( N ) <EOL> y = arange ( N ) <EOL> new_x = arange ( N ) + <NUM_LIT:0.5> <EOL> new_y = logarithmic ( x , y , new_x ) <EOL> correct_y = [ np . NaN , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> ] <EOL> self . assertAllclose ( new_y [ : <NUM_LIT:5> ] , correct_y ) <EOL> def runTest ( self ) : <EOL> test_list = [ name for name in dir ( self ) if name . find ( '<STR_LIT>' ) == <NUM_LIT:0> ] <EOL> for test_name in test_list : <EOL> exec ( "<STR_LIT>" % test_name ) <EOL> if __name__ == '<STR_LIT:__main__>' : <EOL> unittest . main ( ) </s>
