/usr/lib/python2.7/dist-packages/PySPH-1.0a4.dev0-py2.7-linux-x86_64.egg/pysph/base/tests/test_reduce_array.py is in python-pysph 0~20160514.git91867dc-4build1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 | import numpy as np
from unittest import TestCase, main
from pysph.base.reduce_array import serial_reduce_array, dummy_reduce_array
class TestSerialReduceArray(TestCase):
def test_reduce_sum_works(self):
x = np.linspace(0, 10, 100)
expect = np.sum(x)
result = serial_reduce_array(x, 'sum')
self.assertAlmostEqual(result, expect)
def test_reduce_prod_works(self):
x = np.linspace(0, 10, 100)
expect = np.prod(x)
result = serial_reduce_array(x, 'prod')
self.assertAlmostEqual(result, expect)
def test_reduce_max_works(self):
x = np.linspace(0, 10, 100)
expect = np.max(x)
result = serial_reduce_array(x, 'max')
self.assertAlmostEqual(result, expect)
def test_reduce_min_works(self):
x = np.linspace(0, 10, 100)
expect = np.min(x)
result = serial_reduce_array(x, 'min')
self.assertAlmostEqual(result, expect)
def test_reduce_raises_error_for_wrong_op(self):
x = np.linspace(0, 10, 100)
self.assertRaises(RuntimeError, serial_reduce_array, x, 'foo')
def test_dummy_reduce_array_does_nothing(self):
x = np.array([1.0, 2.0])
expect = x
result = dummy_reduce_array(x, 'min')
self.assertTrue(np.alltrue(result == expect))
if __name__ == '__main__':
main()
|