def test_convert_time_units_single_value(self): """Assert in utilities - converting single time units value""" self.assertEqual( 5, Utilities.convert_time_units(data=5, from_units='s', to_units='s')) self.assertAlmostEqual(4.5e-3, Utilities.convert_time_units( data=4500., from_units='micros', to_units='s'), delta=0.000000001)
def test_load_ascii_with_space_separator(self): """Assert in Utilities - testing load_ascii - space separated file read correctly""" input_file = self.get_full_path('good_tof.txt') _array = Utilities.load_ascii(filename=input_file, sep=' ')[0] expected_start_of_array = np.array([[1., 20.], [2., 21.]])[0] returned_array = _array[0:2] self.assertTrue(all(expected_start_of_array == returned_array))
def test_array_minus_array_works(self): """Assert in Utilities - array1 minus array2 works returns correct array""" _array1 = np.array([2, 4, 6]) _array2 = np.array([2, 3, 4]) _array_returned = Utilities.array_minus_array(_array1, _array2) _array_expected = np.array([0, 1, 2]) self.assertTrue(all(_array_expected == _array_returned))
def test_array_add_coeff(self): """Assert in utilities - adding coeff to array""" _data = np.array([1., 2., 3., 4., 5.]) _coeff = 5. _new_data = Utilities.array_add_coeff(data=_data, coeff=_coeff) _expected_data = np.array([6., 7., 8., 9., 10.]) self.assertTrue(all(_expected_data == _new_data))
def test_array_multiply_coeff(self): """Assert in utilities - multiply array by coeff value""" _data = np.array([1., 2., 3., 4., 5.]) _coeff = 2.5 _new_data = Utilities.array_multiply_coeff(data=_data, coeff=_coeff) _expected_data = np.array([2.5, 5., 7.5, 10, 12.5]) self.assertTrue(all(_expected_data == _new_data))
def test_array_divide_array_works(self): """Assert in Utilities - Ratio of arrays works""" _numerator = np.array([10, 20, 30, 40, 50]) _denominator = np.array([1, 2, 3, 4, 5]) _ratio_expected = np.array([10, 10, 10, 10, 10]) _ratio_returned = Utilities.array_divide_array( numerator=_numerator, denominator=_denominator) self.assertTrue(all(_ratio_expected == _ratio_returned))
def test_get_time_conversion_coeff(self): """Assert in utilities - correct time coefficient are returned""" self.assertEqual( 1, Utilities.get_time_conversion_coeff(from_units='s', to_units='s')) self.assertEqual( 1.e3, Utilities.get_time_conversion_coeff(from_units='s', to_units='ms')) self.assertEqual( 1.e6, Utilities.get_time_conversion_coeff(from_units='s', to_units='micros')) self.assertEqual( 1.e9, Utilities.get_time_conversion_coeff(from_units='s', to_units='ns')) self.assertEqual( 1.e-3, Utilities.get_time_conversion_coeff(from_units='ms', to_units='s')) self.assertEqual( 1, Utilities.get_time_conversion_coeff(from_units='ms', to_units='ms')) self.assertEqual( 1e3, Utilities.get_time_conversion_coeff(from_units='ms', to_units='micros')) self.assertEqual( 1e6, Utilities.get_time_conversion_coeff(from_units='ms', to_units='ns')) self.assertEqual( 1.e-6, Utilities.get_time_conversion_coeff(from_units='micros', to_units='s')) self.assertEqual( 1.e-3, Utilities.get_time_conversion_coeff(from_units='micros', to_units='ms')) self.assertEqual( 1, Utilities.get_time_conversion_coeff(from_units='micros', to_units='micros')) self.assertEqual( 1e3, Utilities.get_time_conversion_coeff(from_units='micros', to_units='ns')) self.assertEqual( 1e-9, Utilities.get_time_conversion_coeff(from_units='ns', to_units='s')) self.assertEqual( 1e-6, Utilities.get_time_conversion_coeff(from_units='ns', to_units='ms')) self.assertEqual( 1e-3, Utilities.get_time_conversion_coeff(from_units='ns', to_units='micros')) self.assertEqual( 1, Utilities.get_time_conversion_coeff(from_units='ns', to_units='ns'))
def tets_convert_time_units_numpy_array(self): """Assert in utilities - converting numpy array time units value""" _data = np.array([1., 2., 3., 4., 5.]) self.assertTrue( all(_data == Utilities.convert_time_units( data=_data, from_units='s', to_units='s')))
def test_convert_time_units_list_array(self): """Assert in utilities - converting list time units value""" _data = [1, 2, 3, 4, 5] self.assertTrue( all(_data == Utilities.convert_time_units( data=_data, from_units='s', to_units='s')))