-
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
675d8d5
commit 1a029c8
Showing
2 changed files
with
50 additions
and
3 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
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,45 @@ | ||
import unittest | ||
from random import randint | ||
|
||
import matplotlib.pyplot as plt | ||
|
||
from vis import Vis | ||
|
||
|
||
def insertion_sort(arr: list[int]) -> list[int]: | ||
for i in range(1, len(arr)): | ||
for j in range(i, 0, -1): | ||
if arr[j] < arr[j - 1]: | ||
arr[j], arr[j - 1] = arr[j - 1], arr[j] | ||
else: | ||
break | ||
return arr | ||
|
||
|
||
def batch(n: int): | ||
numbers = [randint(-100, n) for _ in range(n)] | ||
insertion_sort(numbers) | ||
|
||
|
||
def observe(size, time, complexity, confidence, results): | ||
print(f"{size}\t{time:0.2f}\t{complexity}\t{confidence:0.2f}%") | ||
results.append((size, time, complexity, confidence)) | ||
|
||
|
||
class VisTest(unittest.TestCase): | ||
def test_something(self): | ||
results = [] | ||
vis = Vis() | ||
vis.visualize( | ||
batch, | ||
[100, 1000, 2000, 4000], | ||
performance_callback=lambda size, time, complexity, confidence: observe(size, time, complexity, confidence, results), | ||
keep_open=False | ||
) | ||
plt.close() | ||
self.assertEqual('n2', results[-1][2]) | ||
self.assertGreater(results[-1][3], 99.5) | ||
|
||
|
||
if __name__ == '__main__': | ||
unittest.main() |