summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
Diffstat (limited to 'tests')
-rw-r--r--tests/common/bitfield.py30
1 files changed, 29 insertions, 1 deletions
diff --git a/tests/common/bitfield.py b/tests/common/bitfield.py
index ec61291..cb82580 100644
--- a/tests/common/bitfield.py
+++ b/tests/common/bitfield.py
@@ -2,7 +2,7 @@
# -*- coding: utf-8 -*-
-# Tests minimalistes pour valider la construction de chemins relatifs et absolus.
+# Tests pour valider la manipulation des champs de bits.
from chrysacase import ChrysalideTestCase
@@ -21,6 +21,10 @@ class TestBitfields(ChrysalideTestCase):
self.assertEqual(bf, bf2)
+ self.assertEqual(bf.size, bf2.size)
+
+ self.assertEqual(bf.popcount, bf2.popcount)
+
def testBitfieldValues(self):
"""Evaluate bitfields basic values."""
@@ -38,6 +42,8 @@ class TestBitfields(ChrysalideTestCase):
self.assertEqual(bf_a, bf_b)
+ self.assertEqual(bf_a.popcount, bf_b.popcount)
+
bf_a = bitfield(75, 1)
bf_a.reset_all()
@@ -45,6 +51,8 @@ class TestBitfields(ChrysalideTestCase):
self.assertEqual(bf_a, bf_b)
+ self.assertEqual(bf_a.popcount, bf_b.popcount)
+
def testBitfieldLogicalOperations(self):
"""Perform logical operations on bitfields."""
@@ -53,14 +61,20 @@ class TestBitfields(ChrysalideTestCase):
bf_b = bitfield(75, 0)
+ self.assertEqual(bf_a.size, bf_b.size)
+
bf_f = bf_a & bf_b
self.assertEqual(bf_f, bf_b)
+ self.assertEqual(bf_f.popcount, bf_b.popcount)
+
bf_f = bf_a | bf_b
self.assertEqual(bf_f, bf_a)
+ self.assertEqual(bf_f.popcount, bf_a.popcount)
+
def testBitfieldSwitch(self):
"""Switch various bits in bitfields."""
@@ -76,11 +90,15 @@ class TestBitfields(ChrysalideTestCase):
self.assertEqual(bf_t, bf_1)
+ self.assertEqual(bf_t.popcount, bf_1.popcount)
+
for i in range(75):
bf_t.reset(i, 1)
self.assertEqual(bf_t, bf_0)
+ self.assertEqual(bf_t.popcount, bf_0.popcount)
+
def testBitfieldBits(self):
"""Test bits in bitfields."""
@@ -104,3 +122,13 @@ class TestBitfields(ChrysalideTestCase):
self.assertFalse(bf.test_all(0, 54))
self.assertTrue(bf.test_none(0, 54))
+
+
+ def testPopCountForBitfield(self):
+ """Count bits set to 1 in bitfield."""
+
+ bf = bitfield(65, 1)
+
+ self.assertEqual(bf.size, 65)
+
+ self.assertEqual(bf.popcount, 65)