Here are the examples of the python api numpy.testing.assert_ taken from open source projects. By voting up you can indicate which examples are most useful and appropriate.
145 Examples
3
View Complete Implementation : test_regression.py
Copyright MIT License
Author : alvarob96
Copyright MIT License
Author : alvarob96
def test_hypergeometric_range(self):
# Test for ticket #921
astert_(np.all(np.random.hypergeometric(3, 18, 11, size=10) < 4))
astert_(np.all(np.random.hypergeometric(18, 3, 11, size=10) > 0))
# Test for ticket #5623
args = [
(2**20 - 2, 2**20 - 2, 2**20 - 2), # Check for 32-bit systems
]
is_64bits = sys.maxsize > 2**32
if is_64bits and sys.platform != 'win32':
args.append((2**40 - 2, 2**40 - 2, 2**40 - 2)) # Check for 64-bit systems
for arg in args:
astert_(np.random.hypergeometric(*arg) > 0)
3
View Complete Implementation : test_regression.py
Copyright MIT License
Author : alvarob96
Copyright MIT License
Author : alvarob96
def test_polydiv_type(self):
# Make polydiv work for complex types
msg = "Wrong type, should be complex"
x = np.ones(3, dtype=complex)
q, r = np.polydiv(x, x)
astert_(q.dtype == complex, msg)
msg = "Wrong type, should be float"
x = np.ones(3, dtype=int)
q, r = np.polydiv(x, x)
astert_(q.dtype == float, msg)
3
View Complete Implementation : test_recfunctions.py
Copyright MIT License
Author : alvarob96
Copyright MIT License
Author : alvarob96
def test_padded_dtype(self):
dt = np.dtype('i1,f4', align=True)
dt.names = ('k', 'v')
astert_(len(dt.descr), 3) # padding field is inserted
a = np.array([(1, 3), (3, 2)], dt)
b = np.array([(1, 1), (2, 2)], dt)
res = join_by('k', a, b)
# no padding fields remain
expected_dtype = np.dtype([
('k', 'i1'), ('v1', 'f4'), ('v2', 'f4')
])
astert_equal(res.dtype, expected_dtype)
3
View Complete Implementation : test_defchararray.py
Copyright MIT License
Author : alvarob96
Copyright MIT License
Author : alvarob96
def test_from_string_array(self):
A = np.array([[b'abc', b'foo'],
[b'long ', b'0123456789']])
astert_equal(A.dtype.type, np.string_)
B = np.char.array(A)
astert_array_equal(B, A)
astert_equal(B.dtype, A.dtype)
astert_equal(B.shape, A.shape)
B[0, 0] = 'changed'
astert_(B[0, 0] != A[0, 0])
C = np.char.asarray(A)
astert_array_equal(C, A)
astert_equal(C.dtype, A.dtype)
C[0, 0] = 'changed again'
astert_(C[0, 0] != B[0, 0])
astert_(C[0, 0] == A[0, 0])
3
View Complete Implementation : test_type_check.py
Copyright MIT License
Author : alvarob96
Copyright MIT License
Author : alvarob96
def test_cmplx(self):
y = np.random.rand(10,)+1j*np.random.rand(10,)
astert_array_equal(y.imag, np.imag(y))
y = np.array(1 + 1j)
out = np.imag(y)
astert_array_equal(y.imag, out)
astert_(isinstance(out, np.ndarray))
y = 1 + 1j
out = np.imag(y)
astert_equal(1.0, out)
astert_(not isinstance(out, np.ndarray))
3
View Complete Implementation : test_npy_pkg_config.py
Copyright MIT License
Author : alvarob96
Copyright MIT License
Author : alvarob96
def test_simple_variable(self):
with temppath('foo.ini') as path:
with open(path, 'w') as f:
f.write(simple_variable)
pkg = os.path.splitext(path)[0]
out = read_config(pkg)
astert_(out.cflags() == simple_variable_d['cflags'])
astert_(out.libs() == simple_variable_d['libflags'])
astert_(out.name == simple_variable_d['name'])
astert_(out.version == simple_variable_d['version'])
out.vars['prefix'] = '/Users/david'
astert_(out.cflags() == '-I/Users/david/include')
3
View Complete Implementation : test_old_ma.py
Copyright MIT License
Author : alvarob96
Copyright MIT License
Author : alvarob96
def test_testScalarArithmetic(self):
xm = array(0, mask=1)
#TODO FIXME: Find out what the following raises a warning in r8247
with np.errstate(divide='ignore'):
astert_((1 / array(0)).mask)
astert_((1 + xm).mask)
astert_((-xm).mask)
astert_((-xm).mask)
astert_(maximum(xm, xm).mask)
astert_(minimum(xm, xm).mask)
astert_(xm.filled().dtype is xm._data.dtype)
x = array(0, mask=0)
astert_(x.filled() == x._data)
astert_equal(str(xm), str(masked_print_option))
3
View Complete Implementation : test_legendre.py
Copyright MIT License
Author : alvarob96
Copyright MIT License
Author : alvarob96
def test_legvander3d(self):
# also tests polyval3d for non-square coefficient array
x1, x2, x3 = self.x
c = np.random.random((2, 3, 4))
van = leg.legvander3d(x1, x2, x3, [1, 2, 3])
tgt = leg.legval3d(x1, x2, x3, c)
res = np.dot(van, c.flat)
astert_almost_equal(res, tgt)
# check shape
van = leg.legvander3d([x1], [x2], [x3], [1, 2, 3])
astert_(van.shape == (1, 5, 24))
3
View Complete Implementation : test_defchararray.py
Copyright MIT License
Author : alvarob96
Copyright MIT License
Author : alvarob96
def test_capitalize(self):
tgt = [[b' abc ', b''],
[b'12345', b'Mixedcase'],
[b'123 \t 345 \0 ', b'Upper']]
astert_(issubclast(self.A.capitalize().dtype.type, np.string_))
astert_array_equal(self.A.capitalize(), tgt)
tgt = [[u' \u03c3 ', ''],
['12345', 'Mixedcase'],
['123 \t 345 \0 ', 'Upper']]
astert_(issubclast(self.B.capitalize().dtype.type, np.unicode_))
astert_array_equal(self.B.capitalize(), tgt)
3
View Complete Implementation : test_laguerre.py
Copyright MIT License
Author : alvarob96
Copyright MIT License
Author : alvarob96
def test_lagvander3d(self):
# also tests lagval3d for non-square coefficient array
x1, x2, x3 = self.x
c = np.random.random((2, 3, 4))
van = lag.lagvander3d(x1, x2, x3, [1, 2, 3])
tgt = lag.lagval3d(x1, x2, x3, c)
res = np.dot(van, c.flat)
astert_almost_equal(res, tgt)
# check shape
van = lag.lagvander3d([x1], [x2], [x3], [1, 2, 3])
astert_(van.shape == (1, 5, 24))