Skip to content

Commit

Permalink
Update config and test set
Browse files Browse the repository at this point in the history
  • Loading branch information
tamarinvs19 committed Jul 25, 2023
1 parent 2895029 commit e3451d7
Show file tree
Hide file tree
Showing 4 changed files with 401 additions and 35 deletions.
19 changes: 11 additions & 8 deletions utbot-python/samples/run_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ def generate_tests(
command += f" -m {','.join(method_names)}"
print(command)
code = os.system(command)
print(code)
return code


Expand All @@ -81,9 +82,10 @@ def check_coverage(
):
config = parse_config(config_file)
report: typing.Dict[str, bool] = {}
for part in config['parts'][:2]:
for file in part['files'][:2]:
for group in file['groups'][:2]:
coverage: typing.Dict[str, typing.Tuple[float, float]] = {}
for part in config['parts']:
for file in part['files']:
for group in file['groups']:
expected_coverage = group.get('coverage', 0)

file_suffix = f"{part['path'].replace('/', '_')}_{file['name']}"
Expand All @@ -92,8 +94,9 @@ def check_coverage(
actual_coverage_json = json.loads(fin.readline())
actual_covered = sum(lines['end'] - lines['start'] + 1 for lines in actual_coverage_json['covered'])
actual_not_covered = sum(lines['end'] - lines['start'] + 1 for lines in actual_coverage_json['notCovered'])
actual_coverage = round(actual_covered / (actual_not_covered + actual_covered)) * 100
actual_coverage = round(actual_covered / (actual_not_covered + actual_covered) * 100)

coverage[file_suffix] = (actual_coverage, expected_coverage)
report[file_suffix] = actual_coverage >= expected_coverage
if all(report.values()):
return True
Expand All @@ -102,15 +105,15 @@ def check_coverage(
print("-------------")
for file, good_coverage in report.items():
if not good_coverage:
print(file)
print(f"{file}: {coverage[file][0]}/{coverage[file][1]}")
return False


def main_test_generation(args):
config = parse_config(args.config_file)
for part in config['parts'][:2]:
for file in part['files'][:2]:
for group in file['groups'][:2]:
for part in config['parts']:
for file in part['files']:
for group in file['groups']:
full_name = pathlib.PurePath(args.path_to_test_dir, part['path'], file['name'])
output_file = pathlib.PurePath(args.output_dir, f"utbot_tests_{part['path'].replace('/', '_')}_{file['name']}.py")
coverage_output_file = pathlib.PurePath(args.coverage_output_dir, f"coverage_{part['path'].replace('/', '_')}_{file['name']}.json")
Expand Down
40 changes: 40 additions & 0 deletions utbot-python/samples/samples/structures/graph_matrix.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
# An island in matrix is a group of linked areas, all having the same value.
# This code counts number of islands in a given matrix, with including diagonal
# connections.


class Matrix: # Public class to implement a graph
def __init__(self, row: int, col: int, graph: list[list[bool]]) -> None:
self.ROW = row
self.COL = col
self.graph = graph

def __eq__(self, other):
return self.graph == other.graph

def is_safe(self, i: int, j: int, visited: list[list[bool]]) -> bool:
return (
0 <= i < self.ROW
and 0 <= j < self.COL
and not visited[i][j]
and self.graph[i][j]
)

def diffs(self, i: int, j: int, visited: list[list[bool]]) -> None:
# Checking all 8 elements surrounding nth element
row_nbr = [-1, -1, -1, 0, 0, 1, 1, 1] # Coordinate order
col_nbr = [-1, 0, 1, -1, 1, -1, 0, 1]
visited[i][j] = True # Make those cells visited
for k in range(8):
if self.is_safe(i + row_nbr[k], j + col_nbr[k], visited):
self.diffs(i + row_nbr[k], j + col_nbr[k], visited)

def count_islands(self) -> int: # And finally, count all islands.
visited = [[False for j in range(self.COL)] for i in range(self.ROW)]
count = 0
for i in range(self.ROW):
for j in range(self.COL):
if visited[i][j] is False and self.graph[i][j] == 1:
self.diffs(i, j, visited)
count += 1
return count
Loading

0 comments on commit e3451d7

Please sign in to comment.