Skip to content

Commit

Permalink
Enhancement: Fixing #35
Browse files Browse the repository at this point in the history
  • Loading branch information
mojtaba-eshghie committed Sep 11, 2024
1 parent 9715169 commit 49b6cc6
Show file tree
Hide file tree
Showing 6 changed files with 42 additions and 51 deletions.
77 changes: 34 additions & 43 deletions tests/test_comparator.py
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()
4 changes: 2 additions & 2 deletions tests/test_comparator_with_dataset.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import csv
import unittest
from src.config import debug_print
from src.comparator import Comparator
from src.predi.config import debug_print
from src.predi.comparator import Comparator

class TestComparatorWithDataset(unittest.TestCase):
def setUp(self):
Expand Down
Empty file.
4 changes: 2 additions & 2 deletions tests/test_parser.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import unittest
from src.tokenizer import Tokenizer
from src.parser import Parser, ASTNode
from src.predi.tokenizer import Tokenizer
from src.predi.parser import Parser, ASTNode


class TestParser(unittest.TestCase):
Expand Down
6 changes: 3 additions & 3 deletions tests/test_simplifier.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import unittest
from src.tokenizer import Tokenizer
from src.parser import Parser, ASTNode
from src.simplifier import Simplifier
from src.predi.tokenizer import Tokenizer
from src.predi.parser import Parser, ASTNode
from src.predi.simplifier import Simplifier

class TestSimplifier(unittest.TestCase):
def setUp(self):
Expand Down
2 changes: 1 addition & 1 deletion tests/test_tokenizer.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import unittest
import csv
import os
from src.tokenizer import Tokenizer
from src.predi.tokenizer import Tokenizer



Expand Down

0 comments on commit 49b6cc6

Please sign in to comment.