]> Cypherpunks repositories - keks.git/commitdiff
More symmetric tests
authorSergey Matveev <stargrave@stargrave.org>
Sat, 30 Nov 2024 18:24:02 +0000 (21:24 +0300)
committerSergey Matveev <stargrave@stargrave.org>
Sat, 30 Nov 2024 19:38:56 +0000 (22:38 +0300)
pyac/tests/test_int.py
pyac/tests/test_str.py
pyac/tests/test_uuid.py

index 93f047d5ead06cd4e8664bbab39d6bb87d95b5e8afc03045b2875e763e767073..8aa6583adbf3992ff80fb130eb5d8476dedb4f6ec603637cdf5239b6b2b94408 100644 (file)
@@ -1,6 +1,7 @@
 from unittest import TestCase
 
 from hypothesis import given
+from hypothesis.strategies import integers
 
 from pyac import DecodeError
 from pyac import dumps
@@ -99,3 +100,8 @@ class TestInt(TestCase):
             encoded: bytes = b"\x0c\x01\x7b"
             loads(encoded)
         self.assertEqual(str(err.exception), "non-BIN in INT")
+
+    @given(integers())
+    def test_symmetric(self, i: int) -> None:
+        decoded, _ = loads(dumps(i))
+        self.assertEqual(decoded, i)
index 37504d71493b3dd4c56686f18effd587ebf8dde7e7cbdb16e081ee9373180952..25d6287f24d200af4154681cd9c6fdc948ecfd55b139a196cebbf80291f05628 100644 (file)
@@ -1,6 +1,7 @@
 from unittest import TestCase
 
 from hypothesis import given
+from hypothesis.strategies import binary
 from hypothesis.strategies import integers
 
 from pyac import DecodeError
@@ -8,6 +9,7 @@ from pyac import dumps
 from pyac import loads
 from pyac import NotEnoughData
 from tests.strategies import junk_st
+from tests.strategies import unicode_allowed
 
 
 TagStr: int = 0x80
@@ -110,6 +112,11 @@ class TestStr(TestCase):
             loads(encoded)
         self.assertEqual(err.exception.n, 3)
 
+    @given(unicode_allowed)
+    def test_symmetric(self, s: str):
+        decoded, _ = loads(dumps(s))
+        self.assertEqual(decoded, s)
+
 
 class TestBin(TestCase):
     @given(junk_st)
@@ -167,3 +174,8 @@ class TestBin(TestCase):
         with self.assertRaises(NotEnoughData) as err:
             loads(encoded)
         self.assertEqual(err.exception.n, 3)
+
+    @given(binary())
+    def test_symmetric(self, s: bytes):
+        decoded, _ = loads(dumps(s))
+        self.assertEqual(decoded, s)
index 0673a12f00b85eaab825f052d59e30bc6a3260593ec0a7c3d2eac9ec3c65d68d..7722d95975dbf54933d49d8809c260d82114d235b6756e1e669619771b5c7f94 100644 (file)
@@ -2,6 +2,7 @@ from unittest import TestCase
 from uuid import UUID
 
 from hypothesis import given
+from hypothesis.strategies import uuids
 
 from pyac import dumps
 from pyac import loads
@@ -33,3 +34,8 @@ class TestUUID(TestCase):
         with self.assertRaises(NotEnoughData) as err:
             loads(encoded[:-4])
         self.assertEqual(err.exception.n, 1+16)
+
+    @given(uuids())
+    def test_symmetric(self, u: UUID) -> None:
+        decoded, _ = loads(dumps(u))
+        self.assertEqual(decoded, u)