Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: fix linting issues in main,benchmark, and generate #33

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions bosco/benchmark.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@
import os
import sys
from timeit import repeat
from typing import List, Tuple
from typing import Any, List, Tuple


def run_sorting_algorithm(
file_path: str, algorithm: str, array: List[int]
file_path: str, algorithm: str, array: List[Any]
) -> Tuple[float, float, float]:
"""Run a sorting algorithm and profile it with the timeit package."""
directory, file_name = os.path.split(file_path)
Expand Down
6 changes: 5 additions & 1 deletion bosco/generate.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,16 @@ def generate_random_container(
type_: str = "int",
) -> List[Union[int, float, str]]:
"""Generate a random list defined by the size and element type."""
random_list: List[Union[int, float, str]] = []

if type_ == "int":
# Generate a list of random integers within the range [1, size*size]
random_list = [random.randint(1, size * size) for _ in range(size)]
elif type_ == "float":
# Generate a list of random floating-point numbers within the range [1, size*size]
random_list = [random.uniform(1, size * size) for _ in range(size)]
random_list = [
float(random.uniform(1, size * size)) for _ in range(size)
]
elif type_ == "str":
# Generate a list of random strings of length 10 composed of letters and digits
random_list = [
Expand Down
6 changes: 3 additions & 3 deletions bosco/main.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
"""Bosco runs benchmarks to assess the performance of Python functions."""

import plotly.graph_objs as go
import plotly.graph_objs as go # type: ignore
import typer
from plotly.subplots import make_subplots
from plotly.subplots import make_subplots # type: ignore
from rich.console import Console
from tabulate import tabulate
from tabulate import tabulate # type: ignore

from bosco import benchmark, generate

Expand Down
12 changes: 6 additions & 6 deletions poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 0 additions & 2 deletions poetry.toml

This file was deleted.

209 changes: 209 additions & 0 deletions tests/test_sorting.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,209 @@
import pytest

from bosco import sorting

class TestBubbleSort:

# The function sorts a list of integers in ascending order.
def test_sort_ascending_order(self):
# Arrange
input_list = [4, 2, 1, 3]
expected_output = [1, 2, 3, 4]

# Act
result = sorting.bubble_sort(input_list)

# Assert
assert result == expected_output

# The function sorts an empty list and returns an empty list.
def test_sort_empty_list(self):
# Arrange
input_list = []
expected_output = []

# Act
result = sorting.bubble_sort(input_list)

# Assert
assert result == expected_output

class TestInsertionSort:

# The function sorts a list of integers in ascending order.
def test_sorts_list_in_ascending_order(self):
# Arrange
input_list = [4, 2, 1, 3]
expected_output = [1, 2, 3, 4]

# Act
result = sorting.insertion_sort(input_list)

# Assert
assert result == expected_output

# The function works correctly with an empty list.
def test_works_correctly_with_empty_list(self):
# Arrange
input_list = []
expected_output = []

# Act
result = sorting.insertion_sort(input_list)

# Assert
assert result == expected_output

class TestMerge:

# Merging two non-empty arrays of equal length
def test_merge_equal_length(self):
# Arrange
left = [1, 3, 5]
right = [2, 4, 6]
expected_result = [1, 2, 3, 4, 5, 6]

# Act
result = sorting.merge(left, right)

# Assert
assert result == expected_result

# Merging an empty array with a non-empty array
def test_merge_empty_array(self):
# Arrange
left = []
right = [1, 2, 3]
expected_result = [1, 2, 3]

# Act
result = sorting.merge(left, right)

# Assert
assert result == expected_result

class TestMergeSort:

# The function correctly sorts a list of integers in ascending order.
def test_sort_list_of_integers(self):
# Arrange
array = [5, 2, 8, 1, 9, 3]
expected_result = [1, 2, 3, 5, 8, 9]

# Act
result = sorting.merge_sort(array)

# Assert
assert result == expected_result

# The function correctly sorts an empty list.
def test_sort_empty_list(self):
# Arrange
array = []
expected_result = []

# Act
result = sorting.merge_sort(array)

# Assert
assert result == expected_result

class TestSelectionSort:

# The function sorts a list of integers in ascending order.
def test_sort_ascending_order(self):
# Arrange
array = [4, 2, 1, 3]
expected_result = [1, 2, 3, 4]

# Act
sorting.selection_sort(array)

# Assert
assert array == expected_result

# The function sorts an empty list.
def test_sort_empty_list(self):
# Arrange
array = []
expected_result = []

# Act
sorting.selection_sort(array)

# Assert
assert array == expected_result

class TestHeapify:

# Given an array with one element, the function should return the same array
def test_array_with_one_element(self):
# Arrange
array = [5]

# Act
sorting.heapify(array, len(array), 0)

# Assert
assert array == [5]

# Given an empty array, the function should return an empty array
def test_empty_array(self):
# Arrange
array = []

# Act
sorting.heapify(array, len(array), 0)

# Assert
assert array == []

class TestShellSort:

# The function sorts a list of integers in ascending order.
def test_sorts_list_in_ascending_order(self):
# Arrange
array = [4, 2, 7, 1, 5]

# Act
result = sorting.shell_sort(array)

# Assert
assert result == [1, 2, 4, 5, 7]

# The function sorts an empty list.
def test_sorts_empty_list(self):
# Arrange
array = []

# Act
result = sorting.shell_sort(array)

# Assert
assert result == []

class TestBucketSort:

# sorts a list of positive integers in ascending order
def test_sort_positive_integers(self):
# Arrange
arr = [5, 2, 8, 1, 9]
expected = [1, 2, 5, 8, 9]

# Act
result = sorting.bucket_sort(arr)

# Assert
assert result == expected

# sorts an empty list
def test_sort_empty_list(self):
# Arrange
arr = []
expected = []

# Act
result = sorting.bucket_sort(arr)

# Assert
assert result == expected
Loading