Skip to content

Commit 95469c7

Browse files
authored
add a fate dice roller (#1)
* add a fate dice roller * add github action for tests
1 parent a922ef1 commit 95469c7

File tree

5 files changed

+65
-2
lines changed

5 files changed

+65
-2
lines changed
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
name: "Test Suite"
2+
description: "Run tests"
3+
4+
runs:
5+
using: "composite"
6+
steps:
7+
- name: Install deps
8+
run: |
9+
pip install -r requirements.txt
10+
shell: bash
11+
12+
- name: Run Tests
13+
run: |
14+
pytest src/
15+
shell: bash
16+

.github/workflows/pull_request.yml

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
name: Pull Request
2+
3+
on:
4+
pull_request:
5+
branches:
6+
- '*'
7+
8+
paths-ignore:
9+
- '**.md'
10+
11+
jobs:
12+
test:
13+
runs-on: ubuntu-latest
14+
steps:
15+
- name: "Checkout code"
16+
uses: actions/checkout@v2
17+
18+
- name: "Test Suite"
19+
uses: ./.github/actions/test_suite

requirements.txt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
requests==2.28.1
2-
black==22.10.0
2+
black==22.10.0
3+
pytest==7.2.0

src/some_file.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,19 @@
11
import requests
2+
from random import randint
23

34

45
def make_a_request() -> int:
56
response = requests.get('https://example.com')
67
return response.status_code
8+
9+
10+
def roll_fate(bonus: int = 0) -> int:
11+
return sum([_fate_to_number(randint(1, 6)) for _ in range(4)]) + bonus
12+
13+
14+
def _fate_to_number(raw: int) -> int:
15+
if raw < 3:
16+
return -1
17+
if raw > 4:
18+
return 1
19+
return 0

src/test_some_file.py

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,20 @@
11
from http import HTTPStatus
2-
from some_file import make_a_request
2+
from unittest.mock import patch
3+
4+
from some_file import make_a_request, roll_fate
35

46

57
def test_make_a_request() -> None:
68
assert make_a_request() == HTTPStatus.OK
9+
10+
11+
def test_roll_fate_no_mock() -> None:
12+
assert -4 <= roll_fate(0) <= 4
13+
14+
15+
class TestRollFate:
16+
def test_all_1s_returns_negative_four(self) -> None:
17+
with patch('some_file.randint', return_value=1):
18+
assert roll_fate(0) == -4
19+
assert roll_fate(0) == -4
20+
assert roll_fate(0) == -4

0 commit comments

Comments
 (0)