def test_inequality(self): name = 'Bias' units = 'V' values = [0, 1, 2, 3] left = dimension.Dimension(name, units, values) right = dimension.Dimension(name, units, [0, 1, 2, 4]) self.assertFalse(left == right) left = dimension.Dimension(name, units, [0, 1, 2]) right = dimension.Dimension(name, units, values) self.assertFalse(left == right) left = dimension.Dimension('name', units, values) right = dimension.Dimension(name, units, values) self.assertFalse(left == right) left = dimension.Dimension(name, 'units', values) right = dimension.Dimension(name, units, values) self.assertFalse(left == right) left = dimension.Dimension(name, units, values, mode=dimension.DimType.DEPENDENT) right = dimension.Dimension(name, units, values) self.assertFalse(left == right)
def test_equality(self): name = 'Bias' units = 'V' dim_1 = dimension.Dimension(name, units, [0, 1, 2, 3, 4]) dim_2 = dimension.Dimension(name, units, np.arange(5, dtype=np.float32)) self.assertEqual(dim_1, dim_2)
def test_illegal_instantiation(self): with self.assertRaises(TypeError): _ = dimension.Dimension('Name', 14, np.arange(4)) with self.assertRaises(TypeError): _ = dimension.Dimension(14, 'nm', np.arange(4)) with self.assertRaises(ValueError): _ = dimension.Dimension('Name', 'unit', 0) with self.assertRaises(TypeError): _ = dimension.Dimension('Name', 'unit', 'invalid')
def test_values_as_array(self): name = 'Bias' units = 'V' values = np.random.rand(5) descriptor = dimension.Dimension(name, units, values) for expected, actual in zip([name, units, values], [descriptor.name, descriptor.units, descriptor.values]): self.assertTrue(np.all([x == y for x, y in zip(expected, actual)]))
def test_values_as_length(self): name = 'Bias' units = 'V' values = np.arange(5) descriptor = dimension.Dimension(name, units, len(values)) for expected, actual in zip([name, units], [descriptor.name, descriptor.units]): self.assertTrue(np.all([x == y for x, y in zip(expected, actual)])) self.assertTrue(np.allclose(values, descriptor.values))
def test_repr(self): name = 'Bias' quantity = 'generic' units = 'V' values = np.arange(5, dtype=np.float) descriptor = dimension.Dimension(name, units, len(values)) print(type(descriptor)) actual = '{}'.format(descriptor) expected = '{}: {} ({}) mode:{} : {}'.format(name, quantity, units, descriptor.mode, values) self.assertEqual(actual, expected)
def test_default_mode(self): dim = dimension.Dimension('Name', 'units', 1) self.assertEqual(dim.mode, dimension.DimType.DEFAULT)
def test_invalid_mode(self): with self.assertRaises(TypeError): _ = dimension.Dimension('Name', 'units', 5, mode='Incomplete')