From a0065521240d3577fdcf85878cf87fa7d03d129a Mon Sep 17 00:00:00 2001 From: eir Date: Tue, 19 Nov 2019 15:21:32 -0800 Subject: [PATCH] test: Add SpinValue test --- tests/test_spin_value.py | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) create mode 100644 tests/test_spin_value.py diff --git a/tests/test_spin_value.py b/tests/test_spin_value.py new file mode 100644 index 0000000..ed68f5d --- /dev/null +++ b/tests/test_spin_value.py @@ -0,0 +1,35 @@ +import unittest + +import stspin + +from stspin.constants import ( + SpinValue +) + + +class TestUtility(unittest.TestCase): + + def testSpinValue(self) -> None: + with self.assertRaises(AssertionError): + SpinValue(-1) + + self.assertEqual(SpinValue(1), SpinValue(1)) + self.assertEqual(SpinValue(8), SpinValue(0) | SpinValue(8)) + self.assertEqual(SpinValue(0xFF), SpinValue(0xF0) | SpinValue(0x0F)) + + self.assertEqual(SpinValue(22) == SpinValue(0o26), True) + + self.assertEqual(f'{SpinValue(22)}', '22') + + self.assertEqual(SpinValue(22), 22) + self.assertEqual(SpinValue(16) | 6, 22) + + self.assertEqual(SpinValue(1) == '1', False) + self.assertEqual('1' == SpinValue(1), False) + + self.assertEqual(SpinValue(1) == 1, True) + self.assertEqual(1 == SpinValue(1), True) + + +if __name__ == '__main__': + unittest.main()