[Numpy-svn] r8083 - trunk/numpy/lib/tests
numpy-svn at scipy.org
numpy-svn at scipy.org
Mon Feb 1 23:54:35 EST 2010
Author: cdavid
Date: 2010-02-01 22:54:35 -0600 (Mon, 01 Feb 2010)
New Revision: 8083
Modified:
trunk/numpy/lib/tests/test_function_base.py
Log:
TST: add a couple of simple unit-tests for bincount.
Modified: trunk/numpy/lib/tests/test_function_base.py
===================================================================
--- trunk/numpy/lib/tests/test_function_base.py 2010-02-01 10:56:51 UTC (rev 8082)
+++ trunk/numpy/lib/tests/test_function_base.py 2010-02-02 04:54:35 UTC (rev 8083)
@@ -6,6 +6,8 @@
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 @@
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])
More information about the Numpy-svn
mailing list