Include leftmost bit in elements generation

This commit is contained in:
lash 2022-03-29 11:29:10 +00:00
parent bddf335a53
commit 2b614b00ef
Signed by: lash
GPG Key ID: 21D2E7BB88C2A746
2 changed files with 4 additions and 3 deletions

View File

@ -233,7 +233,7 @@ class State:
if v == None or v == 0:
return self.base_state_name
c = 1
for i in range(1, self.__bits):
for i in range(self.__bits):
if v & c > 0:
r.append(self.name(c))
c <<= 1

View File

@ -117,12 +117,13 @@ class TestState(unittest.TestCase):
states = State(3, check_alias=False)
states.add('foo')
states.add('bar')
states.add('baz')
states.put('abcd')
states.set('abcd', states.FOO)
states.set('abcd', states.BAR)
states.set('abcd', states.BAZ)
v = states.state('abcd')
s = states.name(v)
self.assertEqual(s, '_FOO_BAR')
self.assertEqual(s, '_FOO_BAZ')
def test_peek(self):