gen/common/Reduce: Add ADD support.
This commit is contained in:
parent
5106fd43fc
commit
a10b1fd1e6
|
@ -26,7 +26,7 @@ def reverse_bytes(s):
|
||||||
# Reduction ----------------------------------------------------------------------------------------
|
# Reduction ----------------------------------------------------------------------------------------
|
||||||
|
|
||||||
from functools import reduce
|
from functools import reduce
|
||||||
from operator import and_, or_, not_, xor
|
from operator import and_, or_, not_, xor, add
|
||||||
|
|
||||||
def Reduce(operator, value):
|
def Reduce(operator, value):
|
||||||
# List of supported Operators.
|
# List of supported Operators.
|
||||||
|
@ -35,6 +35,7 @@ def Reduce(operator, value):
|
||||||
"OR" : or_,
|
"OR" : or_,
|
||||||
"NOR" : not_,
|
"NOR" : not_,
|
||||||
"XOR" : xor,
|
"XOR" : xor,
|
||||||
|
"ADD" : add,
|
||||||
}
|
}
|
||||||
|
|
||||||
# Switch to upper-case.
|
# Switch to upper-case.
|
||||||
|
|
|
@ -50,3 +50,12 @@ class TestReduce(unittest.TestCase):
|
||||||
self.reduce_test(operator="XOR", value=Constant(0b01, 2), reduced=0b1)
|
self.reduce_test(operator="XOR", value=Constant(0b01, 2), reduced=0b1)
|
||||||
self.reduce_test(operator="XOR", value=Constant(0b10, 2), reduced=0b1)
|
self.reduce_test(operator="XOR", value=Constant(0b10, 2), reduced=0b1)
|
||||||
self.reduce_test(operator="XOR", value=Constant(0b11, 2), reduced=0b0)
|
self.reduce_test(operator="XOR", value=Constant(0b11, 2), reduced=0b0)
|
||||||
|
|
||||||
|
def test_reduced_add(self):
|
||||||
|
self.reduce_test(operator="ADD", value=Constant(0b000, 3), reduced=0)
|
||||||
|
self.reduce_test(operator="ADD", value=Constant(0b001, 3), reduced=1)
|
||||||
|
self.reduce_test(operator="ADD", value=Constant(0b010, 3), reduced=1)
|
||||||
|
self.reduce_test(operator="ADD", value=Constant(0b100, 3), reduced=1)
|
||||||
|
self.reduce_test(operator="ADD", value=Constant(0b011, 3), reduced=2)
|
||||||
|
self.reduce_test(operator="ADD", value=Constant(0b110, 3), reduced=2)
|
||||||
|
self.reduce_test(operator="ADD", value=Constant(0b111, 3), reduced=3)
|
||||||
|
|
Loading…
Reference in New Issue