-
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
5a32d55
commit 7419b5d
Showing
12 changed files
with
139 additions
and
36 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
name: CI | ||
|
||
on: [push] | ||
|
||
jobs: | ||
build: | ||
runs-on: ubuntu-22.04 | ||
strategy: | ||
matrix: | ||
python-version: ["3.9"] | ||
steps: | ||
- uses: actions/checkout@v3 | ||
- name: Set up Python ${{ matrix.python-version }} | ||
uses: actions/setup-python@v3 | ||
with: | ||
python-version: ${{ matrix.python-version }} | ||
|
||
- name: Install dependencies | ||
run: | | ||
python -m pip install --upgrade pip | ||
pip install -r requirements.txt | ||
pip install -r requirements_qa.txt | ||
- name: Test clique solver | ||
run: | | ||
source scripts/bootstrap.sh | ||
pytest -v -m clique | ||
- name: Test coloring solver | ||
run: | | ||
source scripts/bootstrap.sh | ||
pytest -v -m coloring |
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
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,24 @@ | ||
import pytest | ||
|
||
from heurograph import Graph | ||
from heurograph.clique import find_clique | ||
|
||
|
||
def _validate_clique(clique: list[int], graph: Graph) -> bool: | ||
for clique_vertex in clique: | ||
clique_copy = clique.copy() | ||
clique_copy.remove(clique_vertex) | ||
for _clique_vertex in clique_copy: | ||
if _clique_vertex not in graph.neighbors(clique_vertex): | ||
return False | ||
return True | ||
|
||
|
||
@pytest.mark.clique | ||
def test_find_clique() -> None: | ||
graph = Graph() | ||
graph.make_complete() | ||
|
||
clique = find_clique(graph.vertices[0], graph) | ||
if not _validate_clique(clique, graph): | ||
raise ValueError('Solver returns not clique') |
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 |
---|---|---|
@@ -1,3 +1,4 @@ | ||
from heurograph.coloring.coloring_result import ColoringResult | ||
from heurograph.coloring.greedy_coloring import ( | ||
color_graph_greedy, color_graph_greedy_randomized_sorted, | ||
color_graph_greedy_sorted, color_graph_greedy_sorted_shuffled) |
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
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,35 @@ | ||
from typing import Callable | ||
|
||
import pytest | ||
|
||
from heurograph import Graph | ||
from heurograph.coloring import (ColoringResult, color_graph_greedy, | ||
color_graph_greedy_randomized_sorted, | ||
color_graph_greedy_sorted, | ||
color_graph_greedy_sorted_shuffled) | ||
|
||
|
||
def _validate_coloring(coloring: list[int], graph: Graph) -> bool: | ||
for vertex_1 in graph.vertices: | ||
for vertex_2 in graph.neighbors(vertex_1): | ||
if coloring[vertex_1] == coloring[vertex_2]: | ||
return False | ||
return True | ||
|
||
|
||
testing_functions = [ | ||
color_graph_greedy, | ||
color_graph_greedy_randomized_sorted, | ||
color_graph_greedy_sorted, | ||
color_graph_greedy_sorted_shuffled | ||
] | ||
|
||
@pytest.mark.clique | ||
@pytest.mark.parametrize('function', testing_functions) | ||
def test_coloring(function: Callable) -> None: | ||
graph = Graph() | ||
graph.make_complete() | ||
|
||
coloring_result: ColoringResult = function(graph) | ||
if not _validate_coloring(coloring_result.ordered_colors, graph): | ||
raise ValueError('Solver returns not correct coloring') |
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,4 @@ | ||
[pytest] | ||
markers = | ||
clique: Test for clique solver | ||
coloring: Test for coloring solver |
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 |
---|---|---|
@@ -1 +1,2 @@ | ||
isort==5.12.0 | ||
isort==5.12.0 | ||
pytest==7.4.2 |
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,2 @@ | ||
export PYTHONPATH=${PYTHONPATH}:$(pwd) | ||
export PYTHONUNBUFFERED=true |