-
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.
- Loading branch information
1 parent
9715169
commit 49b6cc6
Showing
6 changed files
with
42 additions
and
51 deletions.
There are no files selected for viewing
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 |
---|---|---|
@@ -1,53 +1,44 @@ | ||
import unittest | ||
from src.comparator import Comparator | ||
from src.predi.comparator import Comparator | ||
|
||
|
||
# Test cases for the Comparator class | ||
test_cases = { | ||
'The first predicate is stronger.': [ | ||
("a > b", "a >= b"), | ||
("msg.sender == msg.origin && a >= b", "msg.sender == msg.origin"), | ||
("msg.sender == msg.origin", "msg.sender == msg.origin || a < b"), | ||
], | ||
'The second predicate is stronger.': [ | ||
("msg.sender == msg.origin || a < b", "a < b"), | ||
("a > 12", "a > 13"), | ||
], | ||
'The predicates are equivalent.': [ | ||
("msg.sender == msg.origin", "msg.origin == msg.sender"), | ||
("limiter[identity][sender]<(now-adminRate)", "limiter[identity][sender]+adminRate<now"), | ||
("used[salt]==false", "!used[salt]"), | ||
], | ||
'The predicates are not equivalent and neither is stronger.': [ | ||
("(a > b) && (a <= c)", "(a >= b) && (a < c)"), | ||
("msg.sender != msg.origin", "a >= b"), | ||
("ethBalances[_msgSender()]<=9e18", "tokens<=remainingTokens"), | ||
("NS<(1days)", "NS<NE"), | ||
("super.balanceOf(to)+amount<=holdLimitAmount", "balanceOf(to)+amount<=holdLimitAmount"), | ||
(" currentSupply+1<=MAX_SUPPLY", "currentSupply+boyzToUse.length<=MAX_SUPPLY"), | ||
] | ||
} | ||
|
||
class TestComparator(unittest.TestCase): | ||
def setUp(self): | ||
self.comparator = Comparator() | ||
|
||
|
||
def test_comparator(self): | ||
for expected, test_data in test_cases.items(): | ||
for data in test_data: | ||
result = self.comparator.compare(data[0], data[1]) | ||
self.assertEqual(result, expected, f"Test case failed: {data[0]} vs {data[1]}") | ||
|
||
def test_comparator_equivalence(self): | ||
result = self.comparator.compare("a > b", "a >= b") | ||
self.assertEqual(result, "The first predicate is stronger.") | ||
|
||
def test_comparator_equivalence(self): | ||
result = self.comparator.compare("(a > b) && (a <= c)", "(a >= b) && (a < c)") | ||
self.assertEqual(result, "The predicates are not equivalent and neither is stronger.") | ||
|
||
def test_compare_equivalent_predicates(self): | ||
predicate1 = "msg.sender == msg.origin" | ||
predicate2 = "msg.origin == msg.sender" | ||
result = self.comparator.compare(predicate1, predicate2) | ||
self.assertEqual(result, "The predicates are equivalent.") | ||
|
||
def test_compare_stronger_predicate(self): | ||
predicate1 = "msg.sender == msg.origin && a >= b" | ||
predicate2 = "msg.sender == msg.origin" | ||
result = self.comparator.compare(predicate1, predicate2) | ||
self.assertEqual(result, "The first predicate is stronger.") | ||
|
||
def test_compare_non_equivalent_predicates(self): | ||
predicate1 = "msg.sender != msg.origin" | ||
predicate2 = "a >= b" | ||
try: | ||
result = self.comparator.compare(predicate1, predicate2) | ||
except ValueError as e: | ||
result = "The predicates are not equivalent and neither is stronger." | ||
self.assertEqual(result, "The predicates are not equivalent and neither is stronger.") | ||
|
||
def test_compare_disjoint_predicates(self): | ||
predicate1 = "msg.sender == msg.origin" | ||
predicate2 = "msg.sender != msg.origin" | ||
print('trying...') | ||
result = self.comparator.compare(predicate1, predicate2) | ||
print(f"Result: {result}") | ||
self.assertEqual(result, "The predicates are not equivalent and neither is stronger.") | ||
|
||
def test_compare_with_complex_predicate(self): | ||
predicate1 = "msg.sender == msg.origin || a < b" | ||
predicate2 = "a < b" | ||
result = self.comparator.compare(predicate1, predicate2) | ||
self.assertEqual(result, "The second predicate is stronger.") | ||
|
||
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
Empty file.
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
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
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