Return match as separate complex and simple value array

This commit is contained in:
lash 2022-01-31 10:06:20 +00:00
parent 508ae2397f
commit d2bca51342
Signed by: lash
GPG Key ID: 21D2E7BB88C2A746
4 changed files with 15 additions and 11 deletions

View File

@ -1,3 +1,5 @@
- 0.0.3
* Split match to 2-element tuple, returning complex value and simple values separately
- 0.0.2 - 0.0.2
* Fix rename module name errors * Fix rename module name errors
* Add listing and matcher * Add listing and matcher

View File

@ -1,6 +1,6 @@
[metadata] [metadata]
name = shep name = shep
version = 0.0.2 version = 0.0.3
description = Multi-state key value stores using bitmaskings description = Multi-state key value stores using bitmaskings
author = Louis Holbrook author = Louis Holbrook
author_email = dev@holbrook.no author_email = dev@holbrook.no

View File

@ -95,11 +95,11 @@ class State:
def match(self, v, pure=False): def match(self, v, pure=False):
r = [] alias = None
if not pure: if not pure:
m = self.__reverse.get(v) alias = self.__reverse.get(v)
if m != None:
r.append(m) r = []
c = 1 c = 1
for i in range(self.__bits): for i in range(self.__bits):
if v & c > 0: if v & c > 0:
@ -110,4 +110,4 @@ class State:
pass pass
c <<= 1 c <<= 1
return r return (alias, r,)

View File

@ -37,17 +37,19 @@ class TestStateReport(unittest.TestCase):
def test_match_alias(self): def test_match_alias(self):
self.states.alias('xyzzy', self.states.FOO | self.states.BAZ) self.states.alias('xyzzy', self.states.FOO | self.states.BAZ)
r = self.states.match(self.states.XYZZY) r = self.states.match(self.states.XYZZY)
for k in ['FOO', 'BAZ', 'XYZZY']: for k in ['FOO', 'BAZ']:
self.assertIn(k, r) self.assertIn(k, r[1])
self.assertNotIn('BAR', r) self.assertNotIn('BAR', r[1])
self.assertEqual('XYZZY', r[0])
def test_match_alias_pure(self): def test_match_alias_pure(self):
self.states.alias('xyzzy', self.states.FOO | self.states.BAZ) self.states.alias('xyzzy', self.states.FOO | self.states.BAZ)
r = self.states.match(self.states.XYZZY, pure=True) r = self.states.match(self.states.XYZZY, pure=True)
for k in ['FOO', 'BAZ']: for k in ['FOO', 'BAZ']:
self.assertIn(k, r) self.assertIn(k, r[1])
self.assertNotIn('XYZZY', r) self.assertNotIn('XYZZY', r[1])
self.assertIsNone(r[0])
if __name__ == '__main__': if __name__ == '__main__':