-
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
Showing
7 changed files
with
63 additions
and
6 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
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 +1,2 @@ | ||
import stats | ||
from .stats import flip_coin | ||
from .stats import roll_dice |
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 |
---|---|---|
@@ -0,0 +1,19 @@ | ||
import click | ||
from .stats import flip_coin | ||
from .stats import roll_dice | ||
|
||
|
||
@click.command() | ||
def flip_coin_cli(): | ||
click.echo(flip_coin()) | ||
|
||
|
||
@click.command() | ||
@click.option( | ||
"-d", "--n-dice", default=1, show_default=True, help="Number of dice to roll" | ||
) | ||
@click.option("-s", "--n-sides", default=6, show_default=True, help="Number of sides") | ||
def roll_dice_cli(n_dice, n_sides): | ||
click.echo("") | ||
for d in roll_dice(n_dice, n_sides): | ||
click.secho(f" {d} \n", bold=True, bg="red") |
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,7 +1,10 @@ | ||
import random | ||
import click | ||
import numpy as np | ||
|
||
|
||
@click.command() | ||
def flip_coin(): | ||
def flip_coin() -> str: | ||
return random.choice(["Heads", "Tails"]) | ||
|
||
|
||
def roll_dice(n_dice: int, n_sides: int): | ||
return np.random.randint(1, n_sides, n_dice) |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
import pytest | ||
import numpy as np | ||
from calculate import stats | ||
|
||
|
||
def test_flip_coin(): | ||
coin = stats.flip_coin() | ||
assert coin in ["Heads", "Tails"] | ||
|
||
|
||
@pytest.mark.parametrize("n_dice", [1, 2, 5, 17]) | ||
@pytest.mark.parametrize("n_sides", [2, 3, 6, 20]) | ||
def test_roll_dice(n_dice, n_sides): | ||
dice = stats.roll_dice(n_dice, n_sides) | ||
assert len(dice) == n_dice | ||
assert np.all(dice >= 1) | ||
assert np.all(dice <= n_sides) |