Browse Source

Added identify function which decided based on operand

remotes/origin/feature/feature-logical-operations
fdai7783 11 months ago
parent
commit
07188bba77
  1. 11
      src/main/py/logical_operations.py
  2. 16
      src/test/py/test_logical_operations.py

11
src/main/py/logical_operations.py

@ -1,4 +1,4 @@
def identity_disconjunctive(first_input, operator, second_input):
def identity_disconjunctive(first_input, second_input):
if first_input == 1 and second_input == 1: if first_input == 1 and second_input == 1:
return None return None
elif first_input == 0 and second_input == 0: elif first_input == 0 and second_input == 0:
@ -7,10 +7,17 @@ def identity_disconjunctive(first_input, operator, second_input):
return 1 return 1
def identity_conjunctive(first_input, operator, second_input):
def identity_conjunctive(first_input, second_input):
if first_input == 1 and second_input == 1: if first_input == 1 and second_input == 1:
return 1 return 1
elif first_input == 0 and second_input == 0: elif first_input == 0 and second_input == 0:
return None return None
else: else:
return 0 return 0
def identity(first_input, operator, second_input):
if operator == "+":
return identity_disconjunctive(first_input, second_input)
else:
return identity_conjunctive(first_input, second_input)

16
src/test/py/test_logical_operations.py

@ -10,28 +10,28 @@ class calculationsWithRoots(unittest.TestCase):
pass pass
def test_disconjunctive_identity_1_or_0_equals_x(self): def test_disconjunctive_identity_1_or_0_equals_x(self):
self.assertEqual(identity_disconjunctive(1, "+", 0), 1)
self.assertEqual(identity(1, "+", 0), 1)
def test_disconjunctive_identity_1_or_1_equals_None(self): def test_disconjunctive_identity_1_or_1_equals_None(self):
self.assertEqual(identity_disconjunctive(1, "+", 1), None)
self.assertEqual(identity(1, "+", 1), None)
def test_disconjunctive_identity_0_or_1_equals_None(self): def test_disconjunctive_identity_0_or_1_equals_None(self):
self.assertEqual(identity_disconjunctive(0, "+", 1), 1)
self.assertEqual(identity(0, "+", 1), 1)
def test_disconjunctive_identity_0_or_0_equals_0(self): def test_disconjunctive_identity_0_or_0_equals_0(self):
self.assertEqual(identity_disconjunctive(0, "+", 0), 0)
self.assertEqual(identity(0, "+", 0), 0)
def test_conjunctive_identity_0_and_0_equals_None(self): def test_conjunctive_identity_0_and_0_equals_None(self):
self.assertEqual(identity_conjunctive(0, ".", 0), None)
self.assertEqual(identity(0, ".", 0), None)
def test_conjunctive_identity_1_and_0_equals_None(self): def test_conjunctive_identity_1_and_0_equals_None(self):
self.assertEqual(identity_conjunctive(1, ".", 0), 0)
self.assertEqual(identity(1, ".", 0), 0)
def test_conjunctive_identity_0_and_1_equals_0(self): def test_conjunctive_identity_0_and_1_equals_0(self):
self.assertEqual(identity_conjunctive(0, ".", 1), 0)
self.assertEqual(identity(0, ".", 1), 0)
def test_conjunctive_identity_1_and_1_equals_1(self): def test_conjunctive_identity_1_and_1_equals_1(self):
self.assertEqual(identity_conjunctive(1, ".", 1), 1)
self.assertEqual(identity(1, ".", 1), 1)
if __name__ == "__main__": if __name__ == "__main__":

Loading…
Cancel
Save