예제 #1
0
    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)
예제 #2
0
    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)
예제 #3
0
    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')
예제 #4
0
    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)]))
예제 #5
0
    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))
예제 #6
0
    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)
예제 #7
0
 def test_default_mode(self):
     dim = dimension.Dimension('Name', 'units', 1)
     self.assertEqual(dim.mode, dimension.DimType.DEFAULT)
예제 #8
0
 def test_invalid_mode(self):
     with self.assertRaises(TypeError):
         _ = dimension.Dimension('Name', 'units', 5, mode='Incomplete')