1
0
mirror of https://github.com/myhdl/myhdl.git synced 2024-12-14 07:44:38 +08:00

Solved issue #9 by introducing rich comparions in the Signal class

This commit is contained in:
Jan Decaluwe 2014-08-03 09:20:27 +02:00
parent 8fa8387cf1
commit 17eae3d75b
2 changed files with 28 additions and 3 deletions

View File

@ -474,9 +474,20 @@ class _Signal(object):
return int(self._val)
# comparison
def __cmp__(self, other):
return cmp(self._val, other)
# comparisons
def __eq__(self, other):
return self.val == other
def __ne__(self, other):
return self.val != other
def __lt__(self, other):
return self.val < other
def __le__(self, other):
return self.val <= other
def __gt__(self, other):
return self.val > other
def __ge__(self, other):
return self.val >= other
# method lookup delegation
def __getattr__(self, attr):

View File

@ -0,0 +1,14 @@
from myhdl import *
def issue_9():
t_State = enum('foo', 'bar')
assert (Signal(t_State.foo) == Signal(t_State.bar)) == False
assert (Signal(t_State.foo) != Signal(t_State.bar)) == True
assert (Signal(t_State.foo) == Signal(t_State.foo)) == True
assert (Signal(t_State.foo) != Signal(t_State.foo)) == False
def test_issue_9():
issue_9()