NikhilSetiya commited on
Commit
5ebb00f
·
2 Parent(s): 8d34c11a28de97

Resolve merge conflicts

Browse files
Files changed (5) hide show
  1. .gitattributes +1 -1
  2. .github/workflows/test.yml +0 -31
  3. README.md +1 -1
  4. backend.py +0 -37
  5. test_calculator.py +0 -48
.gitattributes CHANGED
@@ -2,4 +2,4 @@
2
  *.md linguist-language=Markdown
3
  *.txt linguist-language=Text
4
  *.yml linguist-language=YAML
5
- *.yaml linguist-language=YAML
 
2
  *.md linguist-language=Markdown
3
  *.txt linguist-language=Text
4
  *.yml linguist-language=YAML
5
+ *.yaml linguist-language=YAML
.github/workflows/test.yml DELETED
@@ -1,31 +0,0 @@
1
- name: Python Tests
2
-
3
- on:
4
- push:
5
- branches: [ main ]
6
- pull_request:
7
- branches: [ main ]
8
-
9
- jobs:
10
- test:
11
- runs-on: ubuntu-latest
12
- strategy:
13
- matrix:
14
- python-version: [3.9, 3.10]
15
-
16
- steps:
17
- - uses: actions/checkout@v3
18
-
19
- - name: Set up Python ${{ matrix.python-version }}
20
- uses: actions/setup-python@v4
21
- with:
22
- python-version: ${{ matrix.python-version }}
23
-
24
- - name: Install dependencies
25
- run: |
26
- python -m pip install --upgrade pip
27
- pip install -r requirements.txt
28
-
29
- - name: Run tests
30
- run: |
31
- pytest test_calculator.py -v
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
README.md CHANGED
@@ -85,4 +85,4 @@ The application handles various error cases:
85
  Feel free to submit issues and enhancement requests!
86
 
87
  ## License
88
- This project is licensed under the MIT License - see the LICENSE file for details.
 
85
  Feel free to submit issues and enhancement requests!
86
 
87
  ## License
88
+ This project is licensed under the MIT License - see the LICENSE file for details.
backend.py DELETED
@@ -1,37 +0,0 @@
1
- from fastapi import FastAPI
2
- from pydantic import BaseModel
3
- from typing import Union
4
-
5
- app = FastAPI()
6
-
7
- class CalculatorInput(BaseModel):
8
- num1: float
9
- num2: float
10
- operation: str
11
-
12
- class CalculatorResponse(BaseModel):
13
- result: float
14
- operation: str
15
-
16
- @app.post("/calculate", response_model=CalculatorResponse)
17
- async def calculate(input_data: CalculatorInput):
18
- result = 0.0
19
-
20
- if input_data.operation == "add":
21
- result = input_data.num1 + input_data.num2
22
- elif input_data.operation == "subtract":
23
- result = input_data.num1 - input_data.num2
24
- elif input_data.operation == "multiply":
25
- result = input_data.num1 * input_data.num2
26
- elif input_data.operation == "divide":
27
- if input_data.num2 == 0:
28
- raise ValueError("Cannot divide by zero")
29
- result = input_data.num1 / input_data.num2
30
- else:
31
- raise ValueError("Invalid operation")
32
-
33
- return CalculatorResponse(result=result, operation=input_data.operation)
34
-
35
- if __name__ == "__main__":
36
- import uvicorn
37
- uvicorn.run(app, host="0.0.0.0", port=8000)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
test_calculator.py DELETED
@@ -1,48 +0,0 @@
1
- import pytest
2
- from fastapi.testclient import TestClient
3
- from backend import app
4
-
5
- client = TestClient(app)
6
-
7
- def test_addition():
8
- response = client.post(
9
- "/calculate",
10
- json={"num1": 5, "num2": 3, "operation": "add"}
11
- )
12
- assert response.status_code == 200
13
- assert response.json()["result"] == 8
14
- assert response.json()["operation"] == "add"
15
-
16
- def test_subtraction():
17
- response = client.post(
18
- "/calculate",
19
- json={"num1": 5, "num2": 3, "operation": "subtract"}
20
- )
21
- assert response.status_code == 200
22
- assert response.json()["result"] == 2
23
- assert response.json()["operation"] == "subtract"
24
-
25
- def test_multiplication():
26
- response = client.post(
27
- "/calculate",
28
- json={"num1": 5, "num2": 3, "operation": "multiply"}
29
- )
30
- assert response.status_code == 200
31
- assert response.json()["result"] == 15
32
- assert response.json()["operation"] == "multiply"
33
-
34
- def test_division():
35
- response = client.post(
36
- "/calculate",
37
- json={"num1": 6, "num2": 2, "operation": "divide"}
38
- )
39
- assert response.status_code == 200
40
- assert response.json()["result"] == 3
41
- assert response.json()["operation"] == "divide"
42
-
43
- def test_division_by_zero():
44
- response = client.post(
45
- "/calculate",
46
- json={"num1": 5, "num2": 0, "operation": "divide"}
47
- )
48
- assert response.status_code == 422 # FastAPI returns 422 for validation errors