Skip to content

Commit

Permalink
docs(hexagon): add scaladoc, style and one more test
Browse files Browse the repository at this point in the history
  • Loading branch information
manuandru committed Sep 6, 2023
1 parent 51be676 commit 9dff79f
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 5 deletions.
7 changes: 7 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
.bloop/
.metals/
.vscode/
project/.bloop/
project/metals.sbt
project/project/

.DS_Store
.idea/*
scaladoc/
Expand Down
17 changes: 17 additions & 0 deletions src/main/scala/scatan/mvc/model/map/Hexagon.scala
Original file line number Diff line number Diff line change
@@ -1,11 +1,28 @@
package scatan.mvc.model.map

/** An Hexagon in the space rapresented by 3 coordinates.
*/
trait Hexagon:
def row: Int
def col: Int
def slice: Int

/** @return
* the set of all neighbours
*/
def neighbours: Set[Hexagon]

/** Neighborhood means that two Hexagon are far away 1 in coordinate system
* @param another
* Hexagon to test on
* @return
* true if another is a neighbour of this hexagon
*/
def isNeighbour(another: Hexagon): Boolean

/** @return
* the distance from the center
*/
def layer: Int

object Hexagon:
Expand Down
20 changes: 15 additions & 5 deletions src/test/scala/scatan/mvc/model/map/HexagonTest.scala
Original file line number Diff line number Diff line change
Expand Up @@ -17,29 +17,39 @@ class HexagonTest extends BaseTest with ScalaCheckPropertyChecks:
forAll { (r: Int, c: Int, s: Int) =>
val hexagon1 = Hexagon(r, c, s)
val hexagon2 = Hexagon(r, c, s)
hexagon1 should equal(hexagon2)
hexagon1 shouldBe hexagon2
}
}

it should "respect the identity law in order to be a Monoid" in {
forAll { (r: Int, c: Int, s: Int) =>
val hexagon = Hexagon(r, c, s)
hexagon |+| Monoid[Hexagon].empty should be(hexagon)
Monoid[Hexagon].empty |+| hexagon should be(hexagon)
hexagon |+| Monoid[Hexagon].empty shouldBe hexagon
Monoid[Hexagon].empty |+| hexagon shouldBe hexagon
}
}

it should "respect the associative law in order to be a Monoid" in {
forAll { (r1: Int, c1: Int, s1: Int, r2: Int, c2: Int, s2: Int) =>
val hexagon1 = Hexagon(r1, c1, s1)
val hexagon2 = Hexagon(r2, c2, s2)
hexagon1 |+| hexagon2 should be(hexagon2 |+| hexagon1)
hexagon1 |+| hexagon2 shouldBe (hexagon2 |+| hexagon1)
}
}

it should "have 6 neighbours" in {
forAll { (r: Int, c: Int, s: Int) =>
val hexagon = Hexagon(r, c, s)
hexagon.neighbours.size should equal(6)
hexagon.neighbours should have size 6
}
}

"An Hexagon in the center" should "be in layer 0" in {
val centeredHexagon = Hexagon(0, 0, 0)
centeredHexagon.layer shouldBe 0
}

it should "have neighbours at layer 1" in {
val centeredHexagon = Hexagon(0, 0, 0)
all(centeredHexagon.neighbours.map(_.layer)) shouldBe 1
}

0 comments on commit 9dff79f

Please sign in to comment.