diff --git a/.github/workflows/python-app.yml b/.github/workflows/python-app.yml new file mode 100644 index 0000000..e60056c --- /dev/null +++ b/.github/workflows/python-app.yml @@ -0,0 +1,39 @@ +# This workflow will install Python dependencies, run tests and lint with a single version of Python +# For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-python + +name: Python application + +on: + push: + branches: [ "main" ] + pull_request: + branches: [ "main" ] + +permissions: + contents: read + +jobs: + build: + + runs-on: ubuntu-latest + + steps: + - uses: actions/checkout@v3 + - name: Set up Python 3.10 + uses: actions/setup-python@v3 + with: + python-version: "3.10" + - name: Install dependencies + run: | + python -m pip install --upgrade pip + pip install flake8 pytest + if [ -f requirements.txt ]; then pip install -r requirements.txt; fi + - name: Lint with flake8 + run: | + # stop the build if there are Python syntax errors or undefined names + flake8 . --count --select=E9,F63,F7,F82 --show-source --statistics + # exit-zero treats all errors as warnings. The GitHub editor is 127 chars wide + flake8 . --count --exit-zero --max-complexity=10 --max-line-length=127 --statistics + - name: Test with pytest + run: | + pytest Modeli_test.py diff --git a/.github/workflows/python-test.yml b/.github/workflows/python-test.yml new file mode 100644 index 0000000..c901d85 --- /dev/null +++ b/.github/workflows/python-test.yml @@ -0,0 +1,24 @@ +name: Python Tests + +on: + pull_request: {} + push: {} + +jobs: + build: + runs-on: ubuntu-latest + + steps: + - uses: actions/checkout@v3 + - name: Set up Python 3.12 + uses: actions/setup-python@v4 + with: + python-version: 3.12 + - name: Install dependencies + run: | + python -m pip install --upgrade pip + if [ -f requirements.txt ]; then pip install -r requirements.txt; fi + - name: Run pytest + run: | + pip install pytest + pytest diff --git a/.gitignore b/.gitignore index f5e96db..819d160 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,4 @@ -venv \ No newline at end of file +venv +__pycache__ +.pytest_cache +.vscode diff --git a/Modeli.py b/Modeli.py index 366d5d6..6970f35 100644 --- a/Modeli.py +++ b/Modeli.py @@ -12,7 +12,7 @@ def remove_child(self, child_node): if child is not child_node] def dfs_search(self, target): - print(self.depth, self.value, target[self.depth]) + if self is None: return False diff --git a/Modeli_test.py b/Modeli_test.py new file mode 100644 index 0000000..a7bd3af --- /dev/null +++ b/Modeli_test.py @@ -0,0 +1,33 @@ +from Modeli import * +import pytest + +aviokompanija = Aviokompanija() +korisnik = Korisnik() + +KlasaEkonomska = KlasaLeta(0, [Sediste(0, 1), Sediste(1, 1)], 500) # 0 - ekonomska +KlasaBiznis = KlasaLeta(1, [Sediste(0, 1), Sediste(1, 1)], 1000) # 1 - biznis +KlasaPrva = KlasaLeta(2, [Sediste(0, 1), Sediste(1, 1)], 2500) # 2 - prva + +Polazak1 = Destinacija("19:30", "04.04.2024", "London", 0) # 0 - polazak +Dolazak1 = Destinacija("22:00", "04.04.2024", "Madrid", 1) # 1 - dolazak +Polazak2 = Destinacija("12:15", "04.07.2024", "Beograd", 0) # 0 - polazak +Dolazak2 = Destinacija("03:00", "06.07.2024", "Moskva", 1) # 1 - dolazak +Polazak3 = Destinacija("17:00", "12.05.2024", "Kanbera", 0) # 0 - polazak +Dolazak3 = Destinacija("17:55", "12.05.2024", "Sidni", 1) # 1 - dolazak + +Let1 = Let(300, 150, [KlasaEkonomska, KlasaBiznis, KlasaPrva], Polazak1, Dolazak1) +Let2 = Let(300, 150, [KlasaEkonomska, KlasaBiznis, KlasaPrva], Polazak2, Dolazak2) +Let3 = Let(300, 150, [KlasaEkonomska, KlasaBiznis, KlasaPrva], Polazak3, Dolazak3) +aviokompanija.dodajLet(Let1) +aviokompanija.dodajLet(Let2) +aviokompanija.dodajLet(Let3) +""" +for child in aviokompanija.getLetovi().children: + print(child.value) + for child2 in child.children: + print(child2.value) +""" + +@pytest.mark.parametrize("test_input,expected", [(["London", "04.04.2024", "19:30", "Madrid", "04.04.2024", "22:00"], True), (["Beograd", "04.07.2024", "12:15", "Moskva", "06.07.2024", "03:00"], True), (["Kanbera", "12.05.2024", "17:00", "Sidni", "12.05.2024", "17:55"], True)]) +def test_eval(test_input, expected): + assert korisnik.dajArgumente(test_input, aviokompanija) == expected \ No newline at end of file diff --git a/requirements.txt b/requirements.txt new file mode 100644 index 0000000..3f3aa9e --- /dev/null +++ b/requirements.txt @@ -0,0 +1,7 @@ +colorama==0.4.6 +exceptiongroup==1.2.0 +iniconfig==2.0.0 +packaging==24.0 +pluggy==1.4.0 +pytest==8.1.1 +tomli==2.0.1 \ No newline at end of file