Skip to content

Commit 4368eb9

Browse files
committed
add test in instrumentation
1 parent 7f1e666 commit 4368eb9

File tree

2 files changed

+7
-4
lines changed

2 files changed

+7
-4
lines changed

code_to_optimize/bubble_sort_method.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ def __init__(self, x=0):
33
self.x = x
44

55
def sorter(self, arr):
6+
print("codeflash stdout : BubbleSorter.sorter() called")
67
for i in range(len(arr)):
78
for j in range(len(arr) - 1):
89
if arr[j] > arr[j + 1]:

tests/test_instrument_all_and_run.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -168,6 +168,8 @@ def test_sort():
168168
pytest_max_loops=1,
169169
testing_time=0.1,
170170
)
171+
assert "codeflash stdout: Sorting list" in test_results[0].stdout
172+
assert "result: [0, 1, 2, 3, 4, 5]" in test_results[0].stdout
171173
assert test_results[0].id.function_getting_tested == "sorter"
172174
assert test_results[0].id.iteration_id == "1_0"
173175
assert test_results[0].id.test_class_name is None
@@ -179,7 +181,8 @@ def test_sort():
179181
assert test_results[0].runtime > 0
180182
assert test_results[0].did_pass
181183
assert test_results[0].return_value == ([0, 1, 2, 3, 4, 5],)
182-
184+
assert "codeflash stdout: Sorting list" in test_results[1].stdout
185+
assert "result: [0.0, 1.0, 2.0, 3.0, 4.0, 5.0]" in test_results[1].stdout
183186
assert test_results[1].id.function_getting_tested == "sorter"
184187
assert test_results[1].id.iteration_id == "4_0"
185188
assert test_results[1].id.test_class_name is None
@@ -340,13 +343,11 @@ def test_sort():
340343
pytest_max_loops=1,
341344
testing_time=0.1,
342345
)
343-
344346
assert len(test_results) == 4
345347
assert test_results[0].id.function_getting_tested == "BubbleSorter.__init__"
346348
assert test_results[0].id.test_function_name == "test_sort"
347349
assert test_results[0].did_pass
348350
assert test_results[0].return_value[0] == {"x": 0}
349-
350351
assert test_results[1].id.function_getting_tested == "BubbleSorter.sorter"
351352
assert test_results[1].id.iteration_id == "2_0"
352353
assert test_results[1].id.test_class_name is None
@@ -358,7 +359,8 @@ def test_sort():
358359
assert test_results[1].runtime > 0
359360
assert test_results[1].did_pass
360361
assert test_results[1].return_value == ([0, 1, 2, 3, 4, 5],)
361-
362+
assert "codeflash stdout : BubbleSorter.sorter() called" in test_results[1].stdout
363+
assert compare_test_results(test_results, test_results)
362364
assert test_results[2].id.function_getting_tested == "BubbleSorter.__init__"
363365
assert test_results[2].id.test_function_name == "test_sort"
364366
assert test_results[2].did_pass

0 commit comments

Comments
 (0)