Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

ant task, isolating integration tests

  • Loading branch information...
commit ede5cc47734bf7e22c9b0f676c95a5566f05ba8a 1 parent 7a3aca3
@trptcolin authored
View
82 build.xml
@@ -0,0 +1,82 @@
+<project name="TicTacToe" basedir="." default="test">
+
+ <property name="lib.dir" value="lib" />
+ <property name="test.dir" value="spec" />
+ <property name="src.dir" value="src" />
+ <property name="build.dir" value="out" />
+
+ <property name="scala-compiler.jar"
+ value="${lib.dir}/scala-compiler.jar" />
+ <property name="scala-library.jar"
+ value="${lib.dir}/scala-library.jar" />
+ <property name="scala-swing.jar"
+ value="${lib.dir}/scala-swing.jar" />
+ <property name="statemap.jar"
+ value="${lib.dir}/statemap.jar" />
+ <property name="scalatest.jar"
+ value="${lib.dir}/scalatest-0.9.5.jar" />
+ <property name="jemmy.jar"
+ value="${lib.dir}/jemmy.jar" />
+ <property name="junit.jar"
+ value="${lib.dir}/junit-4.5.jar" />
+
+ <target name="clean">
+ <delete dir="${build.dir}"></delete>
+ </target>
+
+
+ <path id="build.classpath">
+ <pathelement location="${scala-library.jar}" />
+ <pathelement location="${scala-swing.jar}" />
+ <pathelement location="${statemap.jar}" />
+ <pathelement location="${build.dir}" />
+ </path>
+
+ <path id="test.classpath">
+ <pathelement location="${statemap.jar}" />
+ <pathelement location="${scalatest.jar}" />
+ <pathelement location="${jemmy.jar}" />
+ <pathelement location="${scala-library.jar}" />
+ <pathelement location="${scala-swing.jar}" />
+ <pathelement location="${build.dir}" />
+ </path>
+
+
+ <target name="init">
+ <taskdef resource="scala/tools/ant/antlib.xml">
+ <classpath>
+ <pathelement location="${scala-compiler.jar}" />
+ <pathelement location="${scala-library.jar}" />
+ </classpath>
+ </taskdef>
+ <taskdef name="scalatest" classname="org.scalatest.tools.ScalaTestTask">
+ <classpath refid="test.classpath" />
+ </taskdef>
+ </target>
+
+
+ <target name="build.compile" depends="init">
+ <mkdir dir="${build.dir}" />
+ <scalac srcdir="${src.dir}" destdir="${build.dir}">
+ <classpath refid="build.classpath" />
+ <include name="**/*.scala" />
+ </scalac>
+ </target>
+
+
+
+ <target name="test.compile">
+ <mkdir dir="${build.dir}" />
+ <scalac srcdir="${test.dir}" destdir="${build.dir}">
+ <classpath refid="test.classpath" />
+ <include name="**/*.scala" />
+ </scalac>
+ </target>
+
+ <target name="test" depends="clean, init, build.compile, test.compile">
+ <scalatest runpath="${build.dir}">
+ <reporter type="stdout" />
+ </scalatest>
+ </target>
+
+</project>
View
BIN  lib/jemmy.jar
Binary file not shown
View
BIN  lib/junit-4.5.jar
Binary file not shown
View
BIN  lib/scala-compiler.jar
Binary file not shown
View
BIN  lib/scala-library.jar
Binary file not shown
View
BIN  lib/scala-swing.jar
Binary file not shown
View
BIN  lib/scalatest-0.9.5.jar
Binary file not shown
View
BIN  lib/statemap.jar
Binary file not shown
View
64 src/SwingGame.scala
@@ -5,22 +5,20 @@ import swing.event._
class SwingGame(startingBoard: Board, players: Array[Player], frame: Frame) extends Game(startingBoard, players) {
private def generatePlayersButton(player1Type: String, player2Type: String): Component = {
- new Label (player1Type + " (X) vs. " + player2Type + " (O)") {
- SwingUi.addButtonStyles (this)
+ new Label(player1Type + " (X) vs. " + player2Type + " (O)") {
+ SwingUi.addButtonStyles(this)
reactions += {
- case MousePressed (source, point, modifiers, clicks, triggersPopup) =>
- setGameType (
+ case MousePressed(source, point, modifiers, clicks, triggersPopup) =>
+ setGameType(
Player.generate(player1Type, "X"), Player.generate(player2Type, "O"))
}
}
}
- // TODO: test me
def decideGameType: Unit = {
frame.contents = new BoxPanel(Orientation.Vertical) {
contents += new BoxPanel(Orientation.Vertical) {
xLayoutAlignment = 0.5
-
border = BorderFactory.createMatteBorder(0, 0, 10, 0, new Color(0, 0, 0, 0))
contents += new Label("Choose your Players:") {
@@ -44,7 +42,6 @@ class SwingGame(startingBoard: Board, players: Array[Player], frame: Frame) exte
frame.contents = boardStructure(board)
}
- // TODO: test me
def decidePlayAgain: Unit = {
frame.contents = new BoxPanel(Orientation.Vertical) {
contents += boardStructure(board)
@@ -52,53 +49,34 @@ class SwingGame(startingBoard: Board, players: Array[Player], frame: Frame) exte
border = BorderFactory.createLineBorder(SwingUi.transparent, 15)
contents += new Label("Play Again") {
- xLayoutAlignment = 0.5
-
SwingUi.addButtonStyles(this)
- reactions += {
- case MousePressed(source, point, modifiers, clicks, triggersPopup) =>
- fsm.PlayAgain()
- }
+ SwingUi.addPlayAgainAction(this, () => fsm.PlayAgain())
}
}
}
}
- // TODO: test me
- def boardStructure(board: Board) = {
+ private def boardStructure(board: Board) = {
new GridPanel(3, 3) {
border = BorderFactory.createLineBorder(SwingUi.transparent, 10)
- (0 to 8).foreach {
- i =>
- contents += new Label(board.positions(i)) {
- opaque = true
-
- val borderWidth = 3
- val borderBottom = if ((i / 3) == 2) 0
- else borderWidth
- val borderRight = if ((i % 3) == 2) 0
- else borderWidth
- border = BorderFactory.createMatteBorder(0, 0, borderBottom, borderRight, SwingUi.lime)
+ (0 to 8).foreach { squareIndex =>
+ contents += new Label(board.positions(squareIndex)) {
+ val teamColor =
+ if (board.positions(squareIndex) == "X")
+ SwingUi.turquoise
+ else
+ SwingUi.orange
- font = new Font("SansSerif", Font.PLAIN, 100)
- val teamColor =
- if (board.positions(i) == "X")
- SwingUi.turquoise
- else
- SwingUi.orange
+ SwingUi.addSquareStyles(this, teamColor, squareIndex)
- foreground = teamColor
-
- if (!board.over && isValidMove(board, i))
- reactions += SwingUi.squareReactions(teamColor)
- reactions += {
- case MousePressed(source, point, modifiers, clicks, triggersPopup) =>
- pickIfValidMove(board, i)
- }
-
- listenTo(Mouse.clicks, Mouse.moves)
- }
+ if (!board.over && isValidMove(board, squareIndex))
+ reactions += SwingUi.squareReactions(teamColor)
+ reactions += {
+ case MousePressed(source, point, modifiers, clicks, triggersPopup) =>
+ pickIfValidMove(board, squareIndex)
+ }
+ }
}
}
}
View
39 src/SwingUi.scala
@@ -23,6 +23,8 @@ object SwingUi {
)
def addButtonStyles(btn: Component): Unit = {
+ btn.xLayoutAlignment = 0.5
+
btn.opaque = true
btn.border = buttonBorder
btn.background = turquoise
@@ -33,6 +35,20 @@ object SwingUi {
btn.listenTo(btn.Mouse.clicks, btn.Mouse.moves)
}
+ def addSquareStyles(square: Component, teamColor: Color, squareIndex: Int): Unit = {
+ square.opaque = true
+
+ val borderWidth = 3
+ val borderBottom = if ((squareIndex / 3) == 2) 0 else borderWidth
+ val borderRight = if ((squareIndex % 3) == 2) 0 else borderWidth
+ square.border = BorderFactory.createMatteBorder(0, 0, borderBottom, borderRight, SwingUi.lime)
+
+ square.font = new Font("SansSerif", Font.PLAIN, 100)
+ square.foreground = teamColor
+
+ square.listenTo(square.Mouse.clicks, square.Mouse.moves)
+ }
+
val buttonReactions: PartialFunction[Event, Unit] = {
case MouseEntered(source, point, modifiers) =>
source.background = lime
@@ -46,6 +62,22 @@ object SwingUi {
source.cursor = new Cursor(Cursor.DEFAULT_CURSOR)
}
+
+
+ def setMainStyles(frame: Frame): Unit = {
+ frame.title = "Tic-Tac-Toe"
+ frame.preferredSize = (500, 500)
+ frame.background = blue
+ frame.foreground = lime
+ }
+
+ def addPlayAgainAction(square: Component, action: () => Unit): Unit = {
+ square.reactions += {
+ case MousePressed(source, point, modifiers, clicks, triggersPopup) =>
+ action()
+ }
+ }
+
def squareReactions(color: Color): PartialFunction[Event, Unit] = {
case MouseEntered(source, point, modifiers) =>
source.background = turquoise
@@ -57,11 +89,4 @@ object SwingUi {
source.cursor = new Cursor(Cursor.DEFAULT_CURSOR)
}
- def setMainStyles(frame: Frame): Unit = {
- frame.title = "Tic-Tac-Toe"
- frame.preferredSize = (500, 500)
- frame.background = blue
- frame.foreground = lime
- }
-
}
View
0  spec/BoardSpec.scala → test/BoardSpec.scala
File renamed without changes
View
0  spec/ComputerPlayerSpec.scala → test/ComputerPlayerSpec.scala
File renamed without changes
View
0  spec/ConsoleGameSpec.scala → test/ConsoleGameSpec.scala
File renamed without changes
View
0  spec/GameContextSpec.scala → test/GameContextSpec.scala
File renamed without changes
View
0  spec/GameSpec.scala → test/GameSpec.scala
File renamed without changes
View
0  spec/HumanPlayerSpec.scala → test/HumanPlayerSpec.scala
File renamed without changes
View
0  spec/MockBoard.scala → test/MockBoard.scala
File renamed without changes
View
0  spec/MockGame.scala → test/MockGame.scala
File renamed without changes
View
0  spec/MockGameContext.scala → test/MockGameContext.scala
File renamed without changes
View
0  spec/MockPlayer.scala → test/MockPlayer.scala
File renamed without changes
View
4 spec/SwingTicTacToeScenario.scala → test/SwingTicTacToeScenario.scala
@@ -21,7 +21,7 @@ class SwingTicTacToeScenario extends Spec with ShouldMatchers with BeforeAndAfte
describe("SwingTicTacToe") {
it("should play a game: computer vs. computer") {
val computerComputerButton = new JLabelOperator(mainWindow, "Computer (X) vs. Computer (O)")
- computerComputerButton should not be(null)
+ computerComputerButton should be(null)
computerComputerButton.clickMouse()
@@ -45,7 +45,7 @@ class SwingTicTacToeScenario extends Spec with ShouldMatchers with BeforeAndAfte
square = new JLabelOperator(mainWindow, 4)
square.clickMouse()
- square = new JLabelOperator(mainWindow, 2)
+ square = new JLabelOperator(mainWindow, 2)
square.clickMouse()
square = new JLabelOperator(mainWindow, 1)
Please sign in to comment.
Something went wrong with that request. Please try again.