Rev | Line | |
---|
[1176] | 1 | import unittest
|
---|
| 2 |
|
---|
[1179] | 3 | from tudelft.utilities.tools.enum import enumValues, enumToString,enum
|
---|
[1176] | 4 |
|
---|
[1179] | 5 | class SimpleEnum(enum):
|
---|
[1176] | 6 | def val(self) -> str:
|
---|
| 7 | return "$"
|
---|
| 8 | @staticmethod
|
---|
| 9 | def _static_init_():
|
---|
| 10 | SimpleEnum.P = SimpleEnum()
|
---|
| 11 | SimpleEnum.Q = SimpleEnum()
|
---|
| 12 | SimpleEnum.R = SimpleEnum()
|
---|
| 13 | SimpleEnum._static_init_()
|
---|
| 14 |
|
---|
[1179] | 15 | class MyEnum(enum):
|
---|
[1176] | 16 | def __init__(self, value:int):
|
---|
| 17 | self.__value:int
|
---|
| 18 | self.__value=value
|
---|
| 19 | def getValue(self) -> int:
|
---|
| 20 | return self.__value
|
---|
| 21 | @staticmethod
|
---|
| 22 | def _static_init_():
|
---|
| 23 | MyEnum.A = MyEnum(1)
|
---|
| 24 | MyEnum.B = MyEnum(2)
|
---|
| 25 | MyEnum.C = MyEnum(3)
|
---|
| 26 | MyEnum._static_init_()
|
---|
| 27 |
|
---|
| 28 |
|
---|
| 29 |
|
---|
| 30 | class EnumTest(unittest.TestCase):
|
---|
| 31 |
|
---|
| 32 | def test_enumValues_simple(self):
|
---|
| 33 | self.assertEqual([SimpleEnum.P, SimpleEnum.Q, SimpleEnum.R], enumValues(SimpleEnum))
|
---|
| 34 | self.assertEqual('P', enumToString(SimpleEnum.P))
|
---|
[1179] | 35 | self.assertEqual('P', str(SimpleEnum.P))
|
---|
[1176] | 36 |
|
---|
| 37 | def test_enumValues_myenum(self):
|
---|
| 38 | self.assertEqual([MyEnum.A, MyEnum.B,MyEnum.C], enumValues(MyEnum))
|
---|
| 39 | self.assertEqual('A', enumToString(MyEnum.A))
|
---|
[1179] | 40 | self.assertEqual('A', str(MyEnum.A))
|
---|
Note:
See
TracBrowser
for help on using the repository browser.