diff --git a/.github/workflows/python-package.yml b/.github/workflows/python-package.yml new file mode 100644 index 0000000..6a80aed --- /dev/null +++ b/.github/workflows/python-package.yml @@ -0,0 +1,40 @@ +# This workflow will install Python dependencies, run tests and lint with a variety of Python versions +# For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-python + +name: Python package + +on: + push: + branches: [ "main", "gh-actions-demo" ] + pull_request: + branches: [ "main" ] + +jobs: + build: + + runs-on: ubuntu-latest + strategy: + fail-fast: false + matrix: + python-version: ["3.9", "3.10", "3.11"] + + steps: + - uses: actions/checkout@v4 + - 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 + python -m 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: | + python -m pytest diff --git a/quadutils/__init__.py b/quadutils/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/quadroots.py b/quadutils/quadroots.py similarity index 86% rename from quadroots.py rename to quadutils/quadroots.py index 5b6a2fb..beb5c82 100644 --- a/quadroots.py +++ b/quadutils/quadroots.py @@ -21,6 +21,6 @@ def quadroots(a, b, c): Roots of the equation. """ - x1 = (-b + np.sqrt(b**2 - 4*a*c))/2*a - x2 = (-b - np.sqrt(b**2 - 4*a*c))/2*a + x1 = (-b + np.sqrt(b**2 - 4*a*c))/(2*a) + x2 = (-b - np.sqrt(b**2 - 4*a*c))/(2*a) return (x1, x2) diff --git a/requirements.txt b/requirements.txt new file mode 100644 index 0000000..1cc18fc --- /dev/null +++ b/requirements.txt @@ -0,0 +1,2 @@ +numpy +pytest diff --git a/tests/test_utils.py b/tests/test_utils.py index 9fe6776..5350100 100644 --- a/tests/test_utils.py +++ b/tests/test_utils.py @@ -1,11 +1,12 @@ import numpy as np +from quadutils import quadroots as qr def test_quadroots_1(): a = 1.0 b = -3.0 c = 2.0 - roots = quadroots(a, b, c) + roots = qr.quadroots(a, b, c) x1_exact = 2.0 x2_exact = 1.0 - assert np.abs(roots[0] - x1_exact) < 1e-14 && np.abs(roots[0] - x2_exact) < 1e-14 + assert (np.abs(roots[0] - x1_exact) < 1e-14) and (np.abs(roots[1] - x2_exact)) < 1e-14