def test_output_type(self): array = np.ones((2)) tests_map = { 'int_int': (1, 1, float), 'float_float': (1., 1., float), 'float_int': (1., 1, float), 'int_float': (1, 1., float), 'list_list': ([1, 1], [1, 1], np.ndarray), 'list_array': ([1, 1], array, np.ndarray), 'array_list': (array, [1, 1], np.ndarray), 'array_array': (array, array, np.ndarray) } for name, (num, den, out_type) in tests_map.items(): with self.subTest(name=name): self.assertIsInstance(mathbox.safe_db(num, den), out_type)
def test_den_and_num_null(self): self.assertEqual(mathbox.safe_db(0, 0), -np.Inf)
def test_den_null(self): self.assertEqual(mathbox.safe_db(1, 0), np.Inf)
def test_num_null(self): self.assertEqual(mathbox.safe_db(0, 1), -np.Inf)
def test_computation(self): for i in range(-5, 6): with self.subTest(i=i): self.assertEqual(mathbox.safe_db(10**i, 1.), 20 * i)