test_mio_utils.py :  » Math » SciPy » scipy » scipy » io » matlab » tests » Python Open Source

Home
Python Open Source
1.3.1.2 Python
2.Ajax
3.Aspect Oriented
4.Blog
5.Build
6.Business Application
7.Chart Report
8.Content Management Systems
9.Cryptographic
10.Database
11.Development
12.Editor
13.Email
14.ERP
15.Game 2D 3D
16.GIS
17.GUI
18.IDE
19.Installer
20.IRC
21.Issue Tracker
22.Language Interface
23.Log
24.Math
25.Media Sound Audio
26.Mobile
27.Network
28.Parser
29.PDF
30.Project Management
31.RSS
32.Search
33.Security
34.Template Engines
35.Test
36.UML
37.USB Serial
38.Web Frameworks
39.Web Server
40.Web Services
41.Web Unit
42.Wiki
43.Windows
44.XML
Python Open Source » Math » SciPy 
SciPy » scipy » scipy » io » matlab » tests » test_mio_utils.py
""" Testing 

"""

import numpy as np

from nose.tools import assert_true,assert_false,\
     assert_equal, assert_raises

from numpy.testing import assert_array_equal,assert_array_almost_equal

from scipy.io.matlab.mio_utils import cproduct,squeeze_element,\
    chars_to_strings


def test_cproduct():
    yield assert_equal, cproduct(()), 1
    yield assert_equal, cproduct((1,)), 1
    yield assert_equal, cproduct((1,3)), 3
    yield assert_equal, cproduct([1,3]), 3


def test_squeeze_element():
    a = np.zeros((1,3))
    yield (assert_array_equal,
           np.squeeze(a),
           squeeze_element(a))
    # 0d output from squeeze gives scalar
    sq_int = squeeze_element(np.zeros((1,1), dtype=np.float))
    yield assert_true, isinstance(sq_int, float)
    # Unless it's a structured array
    sq_sa = squeeze_element(np.zeros((1,1),dtype=[('f1', 'f')]))
    yield assert_true, isinstance(sq_sa, np.ndarray)
                                      
    
def test_chars_strings():
    # chars as strings
    strings = ['learn ', 'python', 'fast  ', 'here  ']
    str_arr = np.array(strings, dtype='U6') # shape (4,)
    chars = [list(s) for s in strings]
    char_arr = np.array(chars, dtype='U1') # shape (4,6)
    yield assert_array_equal, chars_to_strings(char_arr), str_arr
    ca2d = char_arr.reshape((2,2,6))
    sa2d = str_arr.reshape((2,2))
    yield assert_array_equal, chars_to_strings(ca2d), sa2d
    ca3d = char_arr.reshape((1,2,2,6))
    sa3d = str_arr.reshape((1,2,2))
    yield assert_array_equal, chars_to_strings(ca3d), sa3d
    # Fortran ordered arrays
    char_arrf = np.array(chars, dtype='U1', order='F') # shape (4,6)
    yield assert_array_equal, chars_to_strings(char_arrf), str_arr
    # empty array
    arr = np.array([['']], dtype='U1')
    out_arr = np.array([''], dtype='U1')
    yield assert_array_equal, chars_to_strings(arr), out_arr
    
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.