Esempio n. 1
0
    def test_init(self):
        """Enumeration init should work from any sequence"""
        a = Enumeration('abc')
        self.assertEqual(a.index('a'), 0)
        self.assertEqual(a.index('b'), 1)
        self.assertEqual(a.index('c'), 2)
        self.assertEqual(a[0], 'a')
        self.assertEqual(a[1], 'b')
        self.assertEqual(a[2], 'c')
        self.assertEqual(a.ArrayType, uint8)

        a = Enumeration('bca')
        self.assertEqual(a.index('b'), 0)
        self.assertEqual(a.index('c'), 1)
        self.assertEqual(a.index('a'), 2)
        self.assertEqual(a[0], 'b')
        self.assertEqual(a[1], 'c')
        self.assertEqual(a[2], 'a')

        a = Enumeration([1,'2'])
        self.assertEqual(a.index(1), 0)
        self.assertEqual(a.index('2'), 1)
        self.assertRaises(KeyError, a.index, '1')

        #check that it works with gaps
        a = Enumeration('ab-', '-')
        self.assertEqual(a.Gap, '-')
        self.assertEqual(a.GapIndex, 2)

        a = Enumeration(range(257))    #too big to fit in uint8
        self.assertEqual(a.ArrayType, uint16)
Esempio n. 2
0
    def test_init(self):
        """Enumeration init should work from any sequence"""
        a = Enumeration('abc')
        self.assertEqual(a.index('a'), 0)
        self.assertEqual(a.index('b'), 1)
        self.assertEqual(a.index('c'), 2)
        self.assertEqual(a[0], 'a')
        self.assertEqual(a[1], 'b')
        self.assertEqual(a[2], 'c')
        self.assertEqual(a.ArrayType, uint8)

        a = Enumeration('bca')
        self.assertEqual(a.index('b'), 0)
        self.assertEqual(a.index('c'), 1)
        self.assertEqual(a.index('a'), 2)
        self.assertEqual(a[0], 'b')
        self.assertEqual(a[1], 'c')
        self.assertEqual(a[2], 'a')

        a = Enumeration([1,'2'])
        self.assertEqual(a.index(1), 0)
        self.assertEqual(a.index('2'), 1)
        self.assertRaises(KeyError, a.index, '1')

        #check that it works with gaps
        a = Enumeration('ab-', '-')
        self.assertEqual(a.Gap, '-')
        self.assertEqual(a.GapIndex, 2)

        a = Enumeration(range(257))    #too big to fit in uint8
        self.assertEqual(a.ArrayType, uint16)
Esempio n. 3
0
 def test_index(self):
     """Enumeration index should return first index of item"""
     a = Enumeration('bca')
     self.assertEqual(a.index('b'), 0)
     self.assertEqual(a.index('c'), 1)
     self.assertEqual(a.index('a'), 2)
Esempio n. 4
0
 def test_index(self):
     """Enumeration index should return first index of item"""
     a = Enumeration('bca')
     self.assertEqual(a.index('b'), 0)
     self.assertEqual(a.index('c'), 1)
     self.assertEqual(a.index('a'), 2)