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 templates_ext 9import unittest 10import numpy 11 12class TestTemplates(unittest.TestCase): 13 14 def testTemplates(self): 15 for dtype in (numpy.int16, numpy.int32, numpy.float32, numpy.complex128): 16 v = numpy.arange(12, dtype=dtype) 17 for shape in ((12,), (4, 3), (2, 6)): 18 a1 = numpy.zeros(shape, dtype=dtype) 19 a2 = v.reshape(a1.shape) 20 templates_ext.fill(a1) 21 self.assert_((a1 == a2).all()) 22 a1 = numpy.zeros((12,), dtype=numpy.float64) 23 self.assertRaises(TypeError, templates_ext.fill, a1) 24 a1 = numpy.zeros((12,2,3), dtype=numpy.float32) 25 self.assertRaises(TypeError, templates_ext.fill, a1) 26 27if __name__=="__main__": 28 unittest.main() 29