diff --git a/equivalence-relation/projeto-logica-unifacisa/BinaryRelationTests.py b/equivalence-relation/projeto-logica-unifacisa/BinaryRelationTests.py new file mode 100644 index 0000000..67ee689 --- /dev/null +++ b/equivalence-relation/projeto-logica-unifacisa/BinaryRelationTests.py @@ -0,0 +1,83 @@ +import unittest + +from BinaryRelationUtils import BinaryRelationUtils +from SameFirstLetterBinaryRelation import SameFirstLetterBinaryRelation +from SameParityBinaryRelation import SameParityBinaryRelation +from GreaterThanBinaryRelation import GreaterThanBinaryRelation + + +class BinaryRelationTest(unittest.TestCase): + + def setUp(self): + self.integers_set = set(range(300)) + self.names_set = {"Alice", "Andre", "Bob", "Bruno", + "Charles", "Carlos", "Camila", "Rodolfo", "Zeus"} + self.utils = BinaryRelationUtils() + self.parity_relation = SameParityBinaryRelation() + self.first_letter_relation = SameFirstLetterBinaryRelation() + self.greater_than_relation = GreaterThanBinaryRelation() + + def testReflexivityVerification(self): + self.assertTrue(self.utils.verify_reflexivity( + self.parity_relation, self.integers_set)) + self.assertTrue(self.utils.verify_reflexivity( + self.first_letter_relation, self.names_set)) + self.assertFalse(self.utils.verify_reflexivity( + self.greater_than_relation, self.integers_set)) + + def testSymmetryVerification(self): + self.assertTrue(self.utils.verify_symmetry( + self.parity_relation, self.integers_set)) + self.assertTrue(self.utils.verify_symmetry( + self.first_letter_relation, self.names_set)) + self.assertFalse(self.utils.verify_symmetry( + self.greater_than_relation, self.integers_set)) + + def testTransitivityVerification(self): + self.assertTrue(self.utils.verify_transitivity( + self.parity_relation, self.integers_set)) + self.assertTrue(self.utils.verify_transitivity( + self.first_letter_relation, self.names_set)) + self.assertTrue(self.utils.verify_transitivity( + self.greater_than_relation, self.integers_set)) + + def testAntiSymmetryVerification(self): + self.assertFalse(self.utils.verify_antisymmetry( + self.parity_relation, self.integers_set)) + self.assertFalse(self.utils.verify_antisymmetry( + self.first_letter_relation, self.names_set)) + self.assertTrue(self.utils.verify_antisymmetry( + self.greater_than_relation, self.integers_set)) + + def testEquivalencyVerification(self): + self.assertTrue(self.utils.verify_equivalency( + self.parity_relation, self.integers_set)) + self.assertTrue(self.utils.verify_equivalency( + self.first_letter_relation, self.names_set)) + self.assertFalse(self.utils.verify_equivalency( + self.greater_than_relation, self.integers_set)) + + def testSamples(self): + self.assertTrue(self.parity_relation.contains_ordered_pair(100, 500)) + self.assertTrue(self.parity_relation.contains_ordered_pair(101, 501)) + self.assertFalse(self.parity_relation.contains_ordered_pair(100, 501)) + self.assertTrue( + self.first_letter_relation.contains_ordered_pair("Alice", "Andre")) + self.assertFalse( + self.first_letter_relation.contains_ordered_pair("Alice", "Bruno")) + self.assertTrue( + self.greater_than_relation.contains_ordered_pair(500, 100)) + self.assertFalse( + self.greater_than_relation.contains_ordered_pair(100, 500)) + + def testPartitioning(self): + self.assertSetEqual(len(self.utils.get_partitioning( + self.parity_relation, self.integers_set)), 2) + self.assertSetEqual(len(self.utils.get_partitioning( + self.first_letter_relation, self.names_set)), 5) + self.assertSetEqual(self.utils.get_partitioning(self.first_letter_relation, self.names_set), {{"Alice", "Andre"}, {"Bob", "Bruno"}, + {"Charles", "Carlos", "Camila"}, {"Rodolfo"}, {"Zeus"}}) + + +if __name__ == "__main__": + unittest.main() diff --git a/equivalence-relation/projeto-logica-unifacisa/BinaryRelationUtils.py b/equivalence-relation/projeto-logica-unifacisa/BinaryRelationUtils.py index 6c96b4e..10fcda7 100644 --- a/equivalence-relation/projeto-logica-unifacisa/BinaryRelationUtils.py +++ b/equivalence-relation/projeto-logica-unifacisa/BinaryRelationUtils.py @@ -17,6 +17,7 @@ def verify_reflexivity(binary_relation, input_set): Return True if the binary relation in the given input set is reflexive or False if it is not. """ + # TODO: Replace line below with actual code. pass @staticmethod @@ -32,6 +33,7 @@ def verify_symmetry(binary_relation, input_set): Return True if the binary relation in the given input set is symmetric or False if it is not. """ + # TODO: Replace line below with actual code. pass @staticmethod @@ -47,6 +49,7 @@ def verify_transitivity(binary_relation, input_set): Return True if the binary relation in the given input set is transitive or False if it is not. """ + # TODO: Replace line below with actual code. pass @staticmethod @@ -62,6 +65,7 @@ def verify_antisymmetry(binary_relation, input_set): Return True if the binary relation in the given input set is antisymmetric or False if it is not. """ + # TODO: Replace line below with actual code. pass @staticmethod @@ -77,6 +81,7 @@ def verify_equivalency(binary_relation, input_set): Return True if the binary relation in the given input set is an equivalence relation or False if it is not. """ + # TODO: Replace line below with actual code. pass @staticmethod @@ -91,4 +96,5 @@ def get_partitioning(binary_relation, input_set): Return None if the binary relation is not an equivalence relation or a partitioning of the input set (e.g.: {{1, 3, 5, ...}, {2, 4, 6, ...}}) if it is an equivalence relation. """ - pass + # TODO: Replace line below with actual code. + return {} diff --git a/equivalence-relation/projeto-logica-unifacisa/GreaterThanBinaryRelation.py b/equivalence-relation/projeto-logica-unifacisa/GreaterThanBinaryRelation.py new file mode 100644 index 0000000..f4ac0f4 --- /dev/null +++ b/equivalence-relation/projeto-logica-unifacisa/GreaterThanBinaryRelation.py @@ -0,0 +1,30 @@ +#coding: utf-8 + +from BinaryRelation import BinaryRelation + + +class GreaterThanBinaryRelation(BinaryRelation): + """A Binary Relation which elements in an ordered pair share the same first letter.""" + + def contains_ordered_pair(self, x, y): + """ + This method returns a boolean value indicating if the first element of a given ordered pair is greater than the second one. + + Arguments: + x - The first element of the ordered pair. + y - The second element of the ordered pair. + + Return True if the first element of the ordered pair is greater than the second element, otherwise, return False. + """ + pass + + def relation(self, S): + """ + This method returns a set of pairs in SxS (a.k.a. S²) that belong to the binary relation. + + Arguments: + S - The input set. + + Return a set of pairs in SxS (a.k.a. S²) that belong to the binary relation. + """ + pass diff --git a/equivalence-relation/projeto-logica-unifacisa/SameFirstLetterBinaryRelation.py b/equivalence-relation/projeto-logica-unifacisa/SameFirstLetterBinaryRelation.py new file mode 100644 index 0000000..636da69 --- /dev/null +++ b/equivalence-relation/projeto-logica-unifacisa/SameFirstLetterBinaryRelation.py @@ -0,0 +1,30 @@ +#coding: utf-8 + +from BinaryRelation import BinaryRelation + + +class SameFirstLetterBinaryRelation(BinaryRelation): + """A Binary Relation which elements in an ordered pair share the same first letter.""" + + def contains_ordered_pair(self, x, y): + """ + This method returns a boolean value indicating if both elements of a given ordered pair have the same first letter. + + Arguments: + x - The first element of the ordered pair. + y - The second element of the ordered pair. + + Return True if the ordered pair belongs to the binary relation, otherwise, return False. + """ + pass + + def relation(self, S): + """ + This method returns a set of pairs in SxS (a.k.a. S²) that belong to the binary relation. + + Arguments: + S - The input set. + + Return a set of pairs in SxS (a.k.a. S²) that belong to the binary relation. + """ + pass diff --git a/equivalence-relation/projeto-logica-unifacisa/SameParityBinaryRelation.py b/equivalence-relation/projeto-logica-unifacisa/SameParityBinaryRelation.py new file mode 100644 index 0000000..8a1f0f4 --- /dev/null +++ b/equivalence-relation/projeto-logica-unifacisa/SameParityBinaryRelation.py @@ -0,0 +1,32 @@ +#coding: utf-8 + +from BinaryRelation import BinaryRelation + + +class SameParityBinaryRelation(BinaryRelation): + """ + A Binary Relation which elements in an ordered pair have the same parity (divisibility by 2). + """ + + def contains_ordered_pair(self, x, y): + """ + This method returns a boolean value indicating if both elements of a given ordered pair have the same parity. + + Arguments: + x - The first element of the ordered pair. + y - The second element of the ordered pair. + + Return True if the ordered pair belongs to the binary relation, otherwise, return False. + """ + pass + + def relation(self, S): + """ + This method returns a set of pairs in SxS (a.k.a. S²) that belong to the binary relation. + + Arguments: + S - The input set. + + Return a set of pairs in SxS (a.k.a. S²) that belong to the binary relation. + """ + pass