summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorCyrille Bagard <nocbos@gmail.com>2017-05-10 20:21:56 (GMT)
committerCyrille Bagard <nocbos@gmail.com>2017-05-10 20:21:56 (GMT)
commit8e76324b01e5b4979f346f0bc8c84372477a3d38 (patch)
tree3db4057e113aa9f664f5b217dd349bb1e9288009 /tests
parentb0c6ffacf5c6c45c047172e348c737cb85fb5b36 (diff)
Rewritten the whole bitfield management.
Diffstat (limited to 'tests')
-rw-r--r--tests/common/bitfield.py106
-rw-r--r--tests/common/pathname.py4
2 files changed, 108 insertions, 2 deletions
diff --git a/tests/common/bitfield.py b/tests/common/bitfield.py
new file mode 100644
index 0000000..ec61291
--- /dev/null
+++ b/tests/common/bitfield.py
@@ -0,0 +1,106 @@
+#!/usr/bin/python3-dbg
+# -*- coding: utf-8 -*-
+
+
+# Tests minimalistes pour valider la construction de chemins relatifs et absolus.
+
+
+from chrysacase import ChrysalideTestCase
+from pychrysalide.common import bitfield
+
+
+class TestBitfields(ChrysalideTestCase):
+ """TestCase for common.bitfield*"""
+
+ def testDuplicateBitfield(self):
+ """Check duplicated bitfield value."""
+
+ bf = bitfield(10, 0)
+
+ bf2 = bf.dup()
+
+ self.assertEqual(bf, bf2)
+
+
+ def testBitfieldValues(self):
+ """Evaluate bitfields basic values."""
+
+ bf_a = bitfield(75, 1)
+
+ bf_b = bitfield(75, 0)
+
+ self.assertNotEqual(bf_a, bf_b)
+
+ bf_a = bitfield(75, 1)
+
+ bf_b = bitfield(75, 0)
+ bf_b.set_all()
+
+ self.assertEqual(bf_a, bf_b)
+
+ bf_a = bitfield(75, 1)
+ bf_a.reset_all()
+
+ bf_b = bitfield(75, 0)
+
+ self.assertEqual(bf_a, bf_b)
+
+
+ def testBitfieldLogicalOperations(self):
+ """Perform logical operations on bitfields."""
+
+ bf_a = bitfield(75, 1)
+
+ bf_b = bitfield(75, 0)
+
+ bf_f = bf_a & bf_b
+
+ self.assertEqual(bf_f, bf_b)
+
+ bf_f = bf_a | bf_b
+
+ self.assertEqual(bf_f, bf_a)
+
+
+ def testBitfieldSwitch(self):
+ """Switch various bits in bitfields."""
+
+ bf_1 = bitfield(75, 1)
+
+ bf_0 = bitfield(75, 0)
+
+ bf_t = bitfield(75, 0)
+
+ for i in range(75):
+ bf_t.set(i, 1)
+
+ self.assertEqual(bf_t, bf_1)
+
+ for i in range(75):
+ bf_t.reset(i, 1)
+
+ self.assertEqual(bf_t, bf_0)
+
+
+ def testBitfieldBits(self):
+ """Test bits in bitfields."""
+
+ bf = bitfield(54, 1)
+
+ self.assertTrue(bf.test(0))
+
+ self.assertTrue(bf.test(53))
+
+ self.assertTrue(bf.test_all(0, 54))
+
+ self.assertFalse(bf.test_none(0, 54))
+
+ bf = bitfield(54, 0)
+
+ self.assertFalse(bf.test(0))
+
+ self.assertFalse(bf.test(53))
+
+ self.assertFalse(bf.test_all(0, 54))
+
+ self.assertTrue(bf.test_none(0, 54))
diff --git a/tests/common/pathname.py b/tests/common/pathname.py
index 5cd238c..3692434 100644
--- a/tests/common/pathname.py
+++ b/tests/common/pathname.py
@@ -9,13 +9,13 @@ from chrysacase import ChrysalideTestCase
from pychrysalide.common import pathname
-class TestRestrictedContent(ChrysalideTestCase):
+class TestPathNames(ChrysalideTestCase):
"""TestCase for common.pathname.build*"""
@classmethod
def setUpClass(cls):
- super(TestRestrictedContent, cls).setUpClass()
+ super(TestPathNames, cls).setUpClass()
cls._tests = [
{