1#!/usr/bin/env python 2 3# Copyright Jim Bosch & Ankit Daftery 2010-2012. 4# Distributed under the Boost Software License, Version 1.0. 5# (See accompanying file LICENSE_1_0.txt or copy at 6# http://www.boost.org/LICENSE_1_0.txt) 7 8import unittest 9import numpy 10import indexing_ext 11 12class TestIndexing(unittest.TestCase): 13 14 def testSingle(self): 15 x = numpy.arange(0,10) 16 for i in range(0,10): 17 numpy.testing.assert_equal(indexing_ext.single(x,i), i) 18 for i in range(-10,0): 19 numpy.testing.assert_equal(indexing_ext.single(x,i),10+i) 20 21 def testSlice(self): 22 x = numpy.arange(0,10) 23 sl = slice(3,8) 24 b = [3,4,5,6,7] 25 numpy.testing.assert_equal(indexing_ext.slice(x,sl), b) 26 27 def testStepSlice(self): 28 x = numpy.arange(0,10) 29 sl = slice(3,8,2) 30 b = [3,5,7] 31 numpy.testing.assert_equal(indexing_ext.slice(x,sl), b) 32 33 def testIndex(self): 34 x = numpy.arange(0,10) 35 chk = numpy.array([3,4,5,6]) 36 numpy.testing.assert_equal(indexing_ext.indexarray(x,chk),chk) 37 chk = numpy.array([[0,1],[2,3]]) 38 numpy.testing.assert_equal(indexing_ext.indexarray(x,chk),chk) 39 x = numpy.arange(9).reshape(3,3) 40 y = numpy.array([0,1]) 41 z = numpy.array([0,2]) 42 chk = numpy.array([0,5]) 43 numpy.testing.assert_equal(indexing_ext.indexarray(x,y,z),chk) 44 x = numpy.arange(0,10) 45 b = x>4 46 chk = numpy.array([5,6,7,8,9]) 47 numpy.testing.assert_equal(indexing_ext.indexarray(x,b),chk) 48 x = numpy.arange(9).reshape(3,3) 49 b = numpy.array([0,2]) 50 sl = slice(0,3) 51 chk = numpy.array([[0,1,2],[6,7,8]]) 52 numpy.testing.assert_equal(indexing_ext.indexslice(x,b,sl),chk) 53 54if __name__=="__main__": 55 unittest.main() 56