Source

bubble-economy / test_mi.py

#!/usr/bin/env python
# encoding: utf-8
"""
tests_mi.py

Created by dan mackinlay on 2010-12-01.
Copyright (c) 2010 __MyCompanyName__. All rights reserved.
"""
import sys
sys.path.insert(0,'.') #why do i need this?

import numpy as np
import scipy as sp
import mi
from nose.tools import *
from numpy.testing import *
import nose

def test_binning_linearness():
    """linear lists should have the expected nicely interpolated binning"""
    some_floats = np.linspace(-1, 1, 11)
    for i in xrange(2, 6):
        wanted_binning = np.linspace(-1, 1, i, endpoint=False)
        wanted_binning[0] -= 1
        yield assert_array_almost_equal, mi.binning(some_floats, i),\
           wanted_binning

def test_closed_binning():
    some_floats = np.linspace(-1, 1, 11)
    for i in xrange(2, 6):
        wanted_closed_binning = np.linspace(-1, 1, i+1, endpoint=True)
        wanted_closed_binning[-1] = 2
        wanted_closed_binning[0] -= 1
        
        got_closed_binning = mi.closed_binning(some_floats, i)
        yield assert_array_almost_equal,\
            got_closed_binning,\
            wanted_closed_binning

if __name__ == '__main__':
    nose.main()