-
Notifications
You must be signed in to change notification settings - Fork 2
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
10 changed files
with
201 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
# This workflow will install Python dependencies, run tests and lint with a single version of Python | ||
# For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-python | ||
|
||
name: Python application | ||
|
||
on: | ||
push: | ||
branches: [ "main" ] | ||
pull_request: | ||
branches: [ "main" ] | ||
|
||
permissions: | ||
contents: read | ||
|
||
jobs: | ||
mypy: | ||
|
||
runs-on: ubuntu-latest | ||
|
||
steps: | ||
- uses: actions/checkout@v3 | ||
- name: Set up Python 3.10 | ||
uses: actions/setup-python@v3 | ||
with: | ||
python-version: "3.10" | ||
- name: Install dependencies | ||
run: | | ||
python -m pip install --upgrade pip | ||
pip install mypy | ||
- name: Run mypy | ||
run: | | ||
mypy azul --strict | ||
mypy test --strict | ||
lint: | ||
|
||
runs-on: ubuntu-latest | ||
|
||
steps: | ||
- uses: actions/checkout@v3 | ||
- name: Set up Python 3.10 | ||
uses: actions/setup-python@v3 | ||
with: | ||
python-version: "3.10" | ||
- name: Install dependencies | ||
run: | | ||
python -m pip install --upgrade pip | ||
pip install pylint | ||
- name: Run lint | ||
run: | | ||
pylint azul/ | ||
pylint test/ | ||
test: | ||
|
||
runs-on: ubuntu-latest | ||
|
||
steps: | ||
- uses: actions/checkout@v3 | ||
- name: Set up Python 3.10 | ||
uses: actions/setup-python@v3 | ||
with: | ||
python-version: "3.10" | ||
- name: Tests | ||
run: | | ||
python3 -m unittest | ||
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,2 @@ | ||
.mypy_cache | ||
__pycache__ |
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,2 @@ | ||
[MASTER] | ||
disable = missing-module-docstring, missing-class-docstring, missing-function-docstring, too-few-public-methods |
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,12 @@ | ||
check_and_test: FORCE | ||
mypy azul --strict | ||
mypy test --strict | ||
python3 -m unittest | ||
lint: FORCE | ||
pylint azul/ | ||
pylint test/ | ||
|
||
format: FORCE | ||
autopep8 -i azul/*.py | ||
autopep8 -i test/*.py | ||
FORCE: ; |
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,31 @@ | ||
from __future__ import annotations | ||
from typing import List | ||
from itertools import chain, repeat, islice | ||
from azul.interfaces import UsedTilesGiveInterface | ||
from azul.simple_types import Tile, compress_tile_list, Points | ||
|
||
|
||
class Floor: | ||
_point_pattern: List[Points] | ||
_used_tiles: UsedTilesGiveInterface | ||
_tiles: List[Tile] | ||
|
||
def __init__(self, point_pattern: List[Points], used_tiles: UsedTilesGiveInterface): | ||
self._point_pattern = point_pattern.copy() | ||
self._used_tiles = used_tiles | ||
self._tiles = [] | ||
|
||
def put(self, tiles: List[Tile]) -> None: | ||
self._tiles.extend(tiles) | ||
|
||
def finish_round(self) -> Points: | ||
extended_pattern = chain( | ||
self._point_pattern, repeat(self._point_pattern[-1])) | ||
points: Points = Points.sum( | ||
list(islice(extended_pattern, 0, len(self._tiles)))) | ||
self._used_tiles.give(self._tiles.copy()) | ||
self._tiles = [] | ||
return points | ||
|
||
def state(self) -> str: | ||
return compress_tile_list(self._tiles) |
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,8 @@ | ||
from __future__ import annotations | ||
from typing import List | ||
from azul.simple_types import Tile | ||
|
||
|
||
class UsedTilesGiveInterface: | ||
def give(self, tiles: List[Tile]) -> None: | ||
pass |
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,42 @@ | ||
from __future__ import annotations | ||
from typing import List | ||
|
||
|
||
class Points: | ||
_value: int | ||
|
||
def __init__(self, value: int): | ||
self._value = value | ||
|
||
@property | ||
def value(self) -> int: | ||
return self._value | ||
|
||
@staticmethod | ||
def sum(points_list: List[Points]) -> Points: | ||
return Points(sum((x.value for x in points_list))) | ||
|
||
def __str__(self) -> str: | ||
return str(self._value) | ||
|
||
|
||
class Tile: | ||
_representation: str | ||
|
||
def __init__(self, representation: str): | ||
self._representation = representation | ||
|
||
def __str__(self) -> str: | ||
return self._representation | ||
|
||
|
||
STARTING_PLAYER: Tile = Tile("S") | ||
RED: Tile = Tile("R") | ||
BLUE: Tile = Tile("B") | ||
YELLOW: Tile = Tile("Y") | ||
GREEN: Tile = Tile("G") | ||
BLACK: Tile = Tile("L") | ||
|
||
|
||
def compress_tile_list(tiles: List[Tile]) -> str: | ||
return "".join([str(x) for x in tiles]) |
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,37 @@ | ||
from __future__ import annotations | ||
import unittest | ||
from typing import List | ||
from azul.interfaces import UsedTilesGiveInterface | ||
from azul.simple_types import Tile, STARTING_PLAYER, RED, GREEN, Points | ||
from azul.floor import Floor | ||
|
||
|
||
class FakeUsedTiles(UsedTilesGiveInterface): | ||
tiles_given: List[Tile] | ||
|
||
def __init__(self) -> None: | ||
self.tiles_given = [] | ||
|
||
def give(self, tiles: List[Tile]) -> None: | ||
self.tiles_given.extend(tiles) | ||
|
||
|
||
class TestFloor(unittest.TestCase): | ||
def setUp(self) -> None: | ||
self.used_tiles: FakeUsedTiles = FakeUsedTiles() | ||
self.floor: Floor = Floor( | ||
[Points(1), Points(2), Points(2)], self.used_tiles) | ||
|
||
def test_many_tiles(self) -> None: | ||
tiles = [STARTING_PLAYER, RED, GREEN, RED] | ||
self.assertCountEqual(self.floor.state(), "") | ||
self.floor.put(tiles) | ||
self.assertCountEqual(self.floor.state(), "SRRG") | ||
points: Points = self.floor.finish_round() | ||
self.assertEqual(str(points), "7") | ||
self.assertCountEqual(tiles, self.used_tiles.tiles_given) | ||
self.assertCountEqual(self.floor.state(), "") | ||
|
||
|
||
if __name__ == '__main__': | ||
unittest.main() |