-
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
a499081
commit d9a0cfa
Showing
7 changed files
with
151 additions
and
28 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
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 |
---|---|---|
|
@@ -16,7 +16,13 @@ repos: | |
args: [--exit-non-zero-on-fix] | ||
- id: ruff-format | ||
|
||
- repo: https://github.com/pre-commit/mirrors-prettier | ||
rev: "v3.0.3" | ||
# - repo: https://github.com/pre-commit/mirrors-prettier | ||
# rev: "v3.0.3" | ||
# hooks: | ||
# - id: prettier | ||
|
||
- repo: https://github.com/biomejs/pre-commit | ||
rev: "v0.6.1" | ||
hooks: | ||
- id: prettier | ||
- id: biome-check | ||
additional_dependencies: ["@biomejs/[email protected]"] |
Empty file.
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 |
---|---|---|
@@ -1,41 +1,75 @@ | ||
import pytest | ||
from app import app | ||
|
||
from app import app, fibonacci | ||
|
||
|
||
@pytest.fixture | ||
def client(): | ||
"""Creates a test client for the Flask application.""" | ||
app.config["TESTING"] = True | ||
with app.test_client() as client: | ||
yield client | ||
|
||
def test_add(client): | ||
response = client.get('/add/2/3') | ||
assert response.status_code == 200 | ||
assert response.data == b'5' | ||
|
||
response = client.get('/add/-1/1') | ||
def test_hello(client): | ||
"""Tests the hello endpoint.""" | ||
response = client.get("/") | ||
assert response.status_code == 200 | ||
assert response.data == b'0' | ||
assert response.data.decode("utf-8") == "hello world" | ||
|
||
|
||
def test_fibonacci(client): | ||
response = client.get('/fibonacci/1') | ||
def test_add(client): | ||
"""Tests the add endpoint with various inputs.""" | ||
# Test positive numbers | ||
response = client.get("/add/1/2") | ||
assert response.status_code == 200 | ||
assert response.data == b'0' | ||
assert response.data.decode("utf-8") == "3" | ||
|
||
response = client.get('/fibonacci/2') | ||
# Test zero | ||
response = client.get("/add/0/0") | ||
assert response.status_code == 200 | ||
assert response.data == b'1' | ||
assert response.data.decode("utf-8") == "0" | ||
|
||
response = client.get('/fibonacci/5') | ||
# Test negative numbers | ||
response = client.get("/add/%2D1/1") # Using URL-encoded minus sign | ||
assert response.status_code == 200 | ||
assert response.data == b'3' | ||
assert response.data.decode("utf-8") == "0" | ||
|
||
response = client.get('/fibonacci/10') | ||
# Additional negative number test cases | ||
response = client.get("/add/%2D5/3") | ||
assert response.status_code == 200 | ||
assert response.data == b'55' | ||
assert response.data.decode("utf-8") == "-2" | ||
|
||
response = client.get('/fibonacci/0') | ||
|
||
def test_fibonacci_function(): | ||
"""Tests the fibonacci function directly.""" | ||
# Test invalid input | ||
assert fibonacci(0) == "Invalid input" | ||
assert fibonacci(-1) == "Invalid input" | ||
|
||
# Test base cases | ||
assert fibonacci(1) == 0 | ||
assert fibonacci(2) == 1 | ||
|
||
# Test other valid inputs | ||
assert fibonacci(3) == 1 | ||
assert fibonacci(4) == 2 | ||
assert fibonacci(5) == 3 | ||
assert fibonacci(6) == 5 | ||
assert fibonacci(7) == 8 | ||
|
||
|
||
def test_fibonacci_endpoint(client): | ||
"""Tests the fibonacci endpoint with various inputs.""" | ||
# Test valid inputs | ||
response = client.get("/fibonacci/1") | ||
assert response.status_code == 200 | ||
assert response.data == b'Invalid input' | ||
assert response.data.decode("utf-8") == "0" | ||
|
||
response = client.get('/fibonacci/-1') | ||
response = client.get("/fibonacci/7") | ||
assert response.status_code == 200 | ||
assert response.data == b'Invalid input' | ||
assert response.data.decode("utf-8") == "8" | ||
|
||
# Test invalid input type (will be caught by Flask's routing) | ||
response = client.get("/fibonacci/invalid") | ||
assert response.status_code == 404 |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.