This repository has been archived by the owner on Jul 10, 2022. It is now read-only.
forked from rodolfoams/set-theory
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add final code snippets and project tests.
- Loading branch information
1 parent
15761dc
commit b305f09
Showing
5 changed files
with
182 additions
and
1 deletion.
There are no files selected for viewing
83 changes: 83 additions & 0 deletions
83
equivalence-relation/projeto-logica-unifacisa/BinaryRelationTests.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
30 changes: 30 additions & 0 deletions
30
equivalence-relation/projeto-logica-unifacisa/GreaterThanBinaryRelation.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |
30 changes: 30 additions & 0 deletions
30
equivalence-relation/projeto-logica-unifacisa/SameFirstLetterBinaryRelation.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |
32 changes: 32 additions & 0 deletions
32
equivalence-relation/projeto-logica-unifacisa/SameParityBinaryRelation.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |