-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test: add benches for TheAlgorithms/backtracking
- Loading branch information
Showing
18 changed files
with
175 additions
and
0 deletions.
There are no files selected for viewing
17 changes: 17 additions & 0 deletions
17
tests/benchmarks/TheAlgorithms_bench/backtracking/test_bench_all_combinations.py
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,17 @@ | ||
from backtracking.all_combinations import combination_lists, generate_all_combinations | ||
|
||
|
||
def test_combination_lists(benchmark): | ||
benchmark(combination_lists, n=4, k=2) | ||
|
||
|
||
def test_generate_all_combinations(benchmark): | ||
benchmark(generate_all_combinations, n=4, k=2) | ||
|
||
|
||
def test_generate_all_combinations_edge_case(benchmark): | ||
benchmark(generate_all_combinations, n=0, k=0) | ||
|
||
|
||
def test_generate_all_combinations_larger(benchmark): | ||
benchmark(generate_all_combinations, n=5, k=4) |
11 changes: 11 additions & 0 deletions
11
tests/benchmarks/TheAlgorithms_bench/backtracking/test_bench_all_permutations.py
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,11 @@ | ||
from backtracking.all_permutations import generate_all_permutations | ||
|
||
|
||
def test_generate_all_permutations(benchmark): | ||
sequence = [1, 2, 3] | ||
benchmark(generate_all_permutations, sequence) | ||
|
||
|
||
def test_generate_all_permutations_str(benchmark): | ||
sequence = ["A", "B", "C"] | ||
benchmark(generate_all_permutations, sequence) |
11 changes: 11 additions & 0 deletions
11
tests/benchmarks/TheAlgorithms_bench/backtracking/test_bench_all_subsequences.py
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,11 @@ | ||
from backtracking.all_subsequences import generate_all_subsequences | ||
|
||
|
||
def test_generate_all_subsequences(benchmark): | ||
sequence = [3, 2, 1] | ||
benchmark(generate_all_subsequences, sequence) | ||
|
||
|
||
def test_generate_all_subsequences_str(benchmark): | ||
sequence = ["A", "B"] | ||
benchmark(generate_all_subsequences, sequence) |
13 changes: 13 additions & 0 deletions
13
tests/benchmarks/TheAlgorithms_bench/backtracking/test_bench_coloring.py
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,13 @@ | ||
from backtracking.coloring import color | ||
|
||
|
||
def test_color(benchmark): | ||
graph = [ | ||
[0, 1, 0, 0, 0], | ||
[1, 0, 1, 0, 1], | ||
[0, 1, 0, 1, 0], | ||
[0, 1, 1, 0, 0], | ||
[0, 1, 0, 0, 0], | ||
] | ||
max_colors = 3 | ||
benchmark(color, graph, max_colors) |
7 changes: 7 additions & 0 deletions
7
tests/benchmarks/TheAlgorithms_bench/backtracking/test_bench_combination_sum.py
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,7 @@ | ||
from backtracking.combination_sum import combination_sum | ||
|
||
|
||
def test_combination_sum(benchmark): | ||
candidates = [2, 3, 5] | ||
target = 8 | ||
benchmark(combination_sum, candidates, target) |
7 changes: 7 additions & 0 deletions
7
tests/benchmarks/TheAlgorithms_bench/backtracking/test_bench_crossword_puzzle_solver.py
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,7 @@ | ||
from backtracking.crossword_puzzle_solver import solve_crossword | ||
|
||
|
||
def test_solve_crossword(benchmark): | ||
puzzle = [[""] * 3 for _ in range(3)] | ||
words = ["cat", "dog", "car"] | ||
benchmark(solve_crossword, puzzle, words) |
6 changes: 6 additions & 0 deletions
6
tests/benchmarks/TheAlgorithms_bench/backtracking/test_bench_generate_parentheses.py
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,6 @@ | ||
from backtracking.generate_parentheses import generate_parenthesis | ||
|
||
|
||
def test_generate_parenthesis(benchmark): | ||
n = 3 | ||
benchmark(generate_parenthesis, n) |
12 changes: 12 additions & 0 deletions
12
tests/benchmarks/TheAlgorithms_bench/backtracking/test_bench_hamiltonian_cycle.py
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,12 @@ | ||
from backtracking.hamiltonian_cycle import hamilton_cycle | ||
|
||
|
||
def test_hamilton_cycle(benchmark): | ||
graph = [ | ||
[0, 1, 0, 1, 0], | ||
[1, 0, 1, 1, 1], | ||
[0, 1, 0, 0, 1], | ||
[1, 1, 0, 0, 1], | ||
[0, 1, 1, 1, 0], | ||
] | ||
benchmark(hamilton_cycle, graph) |
13 changes: 13 additions & 0 deletions
13
tests/benchmarks/TheAlgorithms_bench/backtracking/test_bench_knight_tour.py
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,13 @@ | ||
from backtracking.knight_tour import get_valid_pos, is_complete, open_knight_tour | ||
|
||
|
||
def test_get_valid_pos(benchmark): | ||
benchmark(get_valid_pos, (1, 3), 4) | ||
|
||
|
||
def test_is_complete(benchmark): | ||
benchmark(is_complete, [[1]]) | ||
|
||
|
||
def test_open_knight_tour(benchmark): | ||
benchmark(open_knight_tour, 1) |
5 changes: 5 additions & 0 deletions
5
tests/benchmarks/TheAlgorithms_bench/backtracking/test_bench_match_word_pattern.py
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,5 @@ | ||
from backtracking.match_word_pattern import match_word_pattern | ||
|
||
|
||
def test_match_word_pattern(benchmark): | ||
benchmark(match_word_pattern, "aba", "GraphTreesGraph") |
9 changes: 9 additions & 0 deletions
9
tests/benchmarks/TheAlgorithms_bench/backtracking/test_bench_minimax.py
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,9 @@ | ||
import math | ||
|
||
from backtracking.minimax import minimax | ||
|
||
|
||
def test_minimax(benchmark): | ||
scores = [90, 23, 6, 33, 21, 65, 123, 34423] | ||
height = math.log(len(scores), 2) | ||
benchmark(minimax, 0, 0, True, scores, height) |
11 changes: 11 additions & 0 deletions
11
tests/benchmarks/TheAlgorithms_bench/backtracking/test_bench_n_queens.py
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,11 @@ | ||
from backtracking.n_queens import is_safe, solve | ||
|
||
|
||
def test_is_safe(benchmark): | ||
board = [[0, 0, 0], [0, 0, 0], [0, 0, 0]] | ||
benchmark(is_safe, board, 1, 1) | ||
|
||
|
||
def test_solve(benchmark): | ||
board = [[0 for i in range(4)] for j in range(4)] | ||
benchmark(solve, board, 0) |
6 changes: 6 additions & 0 deletions
6
tests/benchmarks/TheAlgorithms_bench/backtracking/test_bench_n_queens_math.py
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,6 @@ | ||
from backtracking.n_queens_math import depth_first_search | ||
|
||
|
||
def test_depth_first_search(benchmark): | ||
boards = [] | ||
benchmark(depth_first_search, [], [], [], boards, 4) |
5 changes: 5 additions & 0 deletions
5
tests/benchmarks/TheAlgorithms_bench/backtracking/test_bench_power_sum.py
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,5 @@ | ||
from backtracking.power_sum import solve | ||
|
||
|
||
def test_solve(benchmark): | ||
benchmark(solve, 13, 2) |
12 changes: 12 additions & 0 deletions
12
tests/benchmarks/TheAlgorithms_bench/backtracking/test_bench_rat_in_maze.py
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,12 @@ | ||
from backtracking.rat_in_maze import solve_maze | ||
|
||
|
||
def test_solve_maze(benchmark): | ||
maze = [ | ||
[0, 1, 0, 1, 1], | ||
[0, 0, 0, 0, 0], | ||
[1, 0, 1, 0, 1], | ||
[0, 0, 1, 0, 0], | ||
[1, 0, 0, 1, 0], | ||
] | ||
benchmark(solve_maze, maze, 0, 0, len(maze) - 1, len(maze) - 1) |
16 changes: 16 additions & 0 deletions
16
tests/benchmarks/TheAlgorithms_bench/backtracking/test_bench_sudoku.py
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,16 @@ | ||
from backtracking.sudoku import sudoku | ||
|
||
|
||
def test_sudoku(benchmark): | ||
initial_grid = [ | ||
[3, 0, 6, 5, 0, 8, 4, 0, 0], | ||
[5, 2, 0, 0, 0, 0, 0, 0, 0], | ||
[0, 8, 7, 0, 0, 0, 0, 3, 1], | ||
[0, 0, 3, 0, 1, 0, 0, 8, 0], | ||
[9, 0, 0, 8, 6, 3, 0, 0, 5], | ||
[0, 5, 0, 0, 9, 0, 6, 0, 0], | ||
[1, 3, 0, 0, 0, 0, 2, 5, 0], | ||
[0, 0, 0, 0, 0, 0, 0, 7, 4], | ||
[0, 0, 5, 2, 0, 6, 3, 0, 0], | ||
] | ||
benchmark(sudoku, initial_grid) |
7 changes: 7 additions & 0 deletions
7
tests/benchmarks/TheAlgorithms_bench/backtracking/test_bench_sum_of_subsets.py
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,7 @@ | ||
from backtracking.sum_of_subsets import generate_sum_of_subsets_soln | ||
|
||
|
||
def test_generate_sum_of_subsets_soln(benchmark): | ||
nums = [3, 34, 4, 12, 5, 2] | ||
max_sum = 9 | ||
benchmark(generate_sum_of_subsets_soln, nums, max_sum) |
7 changes: 7 additions & 0 deletions
7
tests/benchmarks/TheAlgorithms_bench/backtracking/test_bench_word_search.py
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,7 @@ | ||
from backtracking.word_search import word_exists | ||
|
||
|
||
def test_word_exists(benchmark): | ||
board = [["A", "B", "C", "E"], ["S", "F", "C", "S"], ["A", "D", "E", "E"]] | ||
word = "ABCCED" | ||
benchmark(word_exists, board, word) |