Skip to content

Commit

Permalink
Fix formatting
Browse files Browse the repository at this point in the history
  • Loading branch information
relatko committed Oct 26, 2023
1 parent 5b3b19c commit 82d1d36
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 19 deletions.
15 changes: 7 additions & 8 deletions azul/Floor.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
from typing import List
from itertools import chain, repeat, islice


class Floor:
_pointPattern: List[Points]
_usedTiles: UsedTilesGiveInterface
Expand All @@ -17,17 +18,15 @@ def __init__(self, pointPattern: List[Points], _usedTiles: UsedTilesGiveInterfac

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))))
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)




4 changes: 2 additions & 2 deletions azul/Points.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from __future__ import annotations
from typing import List


class Points:
_value: int

Expand All @@ -10,7 +11,6 @@ def __init__(self, value: int):
@staticmethod
def sum(pointsList: List[Points]) -> Points:
return Points(sum([x._value for x in pointsList]))

def __str__(self) -> str:
return str(self._value)

7 changes: 5 additions & 2 deletions azul/Tile.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,16 @@
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
return self._representation


STARTING_PLAYER: Tile = Tile("S")
RED: Tile = Tile("R")
Expand All @@ -18,5 +20,6 @@ def __str__(self) -> str:
GREEN: Tile = Tile("G")
BLACK: Tile = Tile("L")


def compressTileList(tiles: List[Tile]) -> str:
return "".join([str(x) for x in tiles])
5 changes: 2 additions & 3 deletions azul/UsedTilesGiveInterface.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,7 @@
from azul.Tile import Tile
from typing import List


class UsedTilesGiveInterface:
def give(self, tiles: List[Tile]) -> None:
pass


pass
14 changes: 10 additions & 4 deletions test/test_floor.py
Original file line number Diff line number Diff line change
@@ -1,29 +1,35 @@
from __future__ import annotations
import unittest
from azul.UsedTilesGiveInterface import UsedTilesGiveInterface
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)
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)
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()

0 comments on commit 82d1d36

Please sign in to comment.