-
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.
Floor class Create pylint.yml Fix formatting Remove lint Create python-app.yml Delete unused stuff
- Loading branch information
Showing
10 changed files
with
156 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,32 @@ | ||
# 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: | ||
build: | ||
|
||
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: Test and checks | ||
run: | | ||
make |
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,6 @@ | ||
test: FORCE | ||
mypy azul --strict | ||
mypy test --strict | ||
python3 -m unittest | ||
|
||
FORCE: ; |
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,32 @@ | ||
from __future__ import annotations | ||
from azul.UsedTilesGiveInterface import UsedTilesGiveInterface | ||
from azul.Tile import Tile, compressTileList | ||
from azul.Points import Points | ||
from typing import List | ||
from itertools import chain, repeat, islice | ||
|
||
|
||
class Floor: | ||
_pointPattern: List[Points] | ||
_usedTiles: UsedTilesGiveInterface | ||
_tiles: List[Tile] | ||
|
||
def __init__(self, pointPattern: List[Points], _usedTiles: UsedTilesGiveInterface): | ||
self._pointPattern = pointPattern.copy() | ||
self._usedTiles = _usedTiles | ||
self._tiles = [] | ||
|
||
def put(self, tiles: List[Tile]) -> None: | ||
self._tiles.extend(tiles) | ||
|
||
def finishRound(self) -> Points: | ||
extendedPattern = chain( | ||
self._pointPattern, repeat(self._pointPattern[-1])) | ||
points: Points = Points.sum( | ||
list(islice(extendedPattern, 0, len(self._tiles)))) | ||
self._usedTiles.give(self._tiles.copy()) | ||
self._tiles = [] | ||
return points | ||
|
||
def state(self) -> str: | ||
return compressTileList(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,16 @@ | ||
from __future__ import annotations | ||
from typing import List | ||
|
||
|
||
class Points: | ||
_value: int | ||
|
||
def __init__(self, value: int): | ||
self._value = value | ||
|
||
@staticmethod | ||
def sum(pointsList: List[Points]) -> Points: | ||
return Points(sum([x._value for x in pointsList])) | ||
|
||
def __str__(self) -> str: | ||
return str(self._value) |
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,25 @@ | ||
from __future__ import annotations | ||
from enum import Enum | ||
from typing import List | ||
|
||
|
||
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 compressTileList(tiles: List[Tile]) -> str: | ||
return "".join([str(x) for x in 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 azul.Tile import Tile | ||
from typing import List | ||
|
||
|
||
class UsedTilesGiveInterface: | ||
def give(self, tiles: List[Tile]) -> None: | ||
pass |
Empty file.
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,35 @@ | ||
from __future__ import annotations | ||
import unittest | ||
from azul.UsedTilesGiveInterface import UsedTilesGiveInterface | ||
from azul.Tile import Tile, STARTING_PLAYER, RED, GREEN | ||
from azul.Floor import Floor | ||
from azul.Points import Points | ||
from typing import List | ||
|
||
|
||
class FakeUsedTiles(UsedTilesGiveInterface): | ||
tilesGiven: List[Tile] | ||
|
||
def __init__(self) -> None: | ||
self.tilesGiven = [] | ||
|
||
def give(self, tiles: List[Tile]) -> None: | ||
self.tilesGiven.extend(tiles) | ||
|
||
|
||
class TestFloor(unittest.TestCase): | ||
def setUp(self) -> None: | ||
self.usedTiles: FakeUsedTiles = FakeUsedTiles() | ||
self.floor: Floor = Floor( | ||
[Points(1), Points(2), Points(2)], self.usedTiles) | ||
|
||
def test_many_tiles(self) -> None: | ||
tiles = [STARTING_PLAYER, RED, GREEN, RED] | ||
self.floor.put(tiles) | ||
points: Points = self.floor.finishRound() | ||
self.assertEquals(str(points), "7") | ||
self.assertCountEqual(tiles, self.usedTiles.tilesGiven) | ||
|
||
|
||
if __name__ == '__main__': | ||
unittest.main() |