diff options
author | David Cournapeau <cournape@gmail.com> | 2010-02-02 04:54:35 +0000 |
---|---|---|
committer | David Cournapeau <cournape@gmail.com> | 2010-02-02 04:54:35 +0000 |
commit | 60e53321fbb0a5e3ae630100eff32aec939a4434 (patch) | |
tree | 051623ec31bcf624b61882a074e2c856b6b719e1 /numpy/lib/tests/test_function_base.py | |
parent | 41ba0740639e9fbb11f98f017e3afdd26a30782c (diff) | |
download | numpy-60e53321fbb0a5e3ae630100eff32aec939a4434.tar.gz |
TST: add a couple of simple unit-tests for bincount.
Diffstat (limited to 'numpy/lib/tests/test_function_base.py')
-rw-r--r-- | numpy/lib/tests/test_function_base.py | 23 |
1 files changed, 23 insertions, 0 deletions
diff --git a/numpy/lib/tests/test_function_base.py b/numpy/lib/tests/test_function_base.py index 8595c6b5c..178237c33 100644 --- a/numpy/lib/tests/test_function_base.py +++ b/numpy/lib/tests/test_function_base.py @@ -6,6 +6,8 @@ from numpy.lib import * from numpy.core import * from numpy import matrix, asmatrix +import numpy as np + class TestAny(TestCase): def test_basic(self): y1 = [0,0,1,0] @@ -852,6 +854,27 @@ class TestPiecewise(TestCase): assert y.ndim == 0 assert y == 0 +class TestBincount(TestCase): + def test_simple(self): + y = np.bincount(np.arange(4)) + assert_array_equal(y, np.ones(4)) + + def test_simple2(self): + y = np.bincount(np.array([1, 5, 2, 4, 1])) + assert_array_equal(y, np.array([0, 2, 1, 0, 1, 1])) + + def test_simple_weight(self): + x = np.arange(4) + w = np.array([0.2, 0.3, 0.5, 0.1]) + y = np.bincount(x, w) + assert_array_equal(y, w) + + def test_simple_weight2(self): + x = np.array([1, 2, 4, 5, 2]) + w = np.array([0.2, 0.3, 0.5, 0.1, 0.2]) + y = np.bincount(x, w) + assert_array_equal(y, np.array([0, 0.2, 0.5, 0, 0.5, 0.1])) + def compare_results(res,desired): for i in range(len(desired)): assert_array_equal(res[i],desired[i]) |