[ascii] Test graphics backend, first unit test
This commit is contained in:
@@ -1,4 +0,0 @@
|
|||||||
-lib kiss
|
|
||||||
-cp src
|
|
||||||
--main Main
|
|
||||||
--interp
|
|
@@ -0,0 +1,7 @@
|
|||||||
|
package asciilib.backends.test;
|
||||||
|
|
||||||
|
import asciilib.GraphicsBackend;
|
||||||
|
import asciilib.Graphics;
|
||||||
|
|
||||||
|
@:build(kiss.Kiss.build())
|
||||||
|
class TestGraphicsBackend implements GraphicsBackend {}
|
@@ -0,0 +1,12 @@
|
|||||||
|
(defprop &mut :Int letterWidth 0)
|
||||||
|
(defprop &mut :Int letterHeight 0)
|
||||||
|
(defprop &mut :Int drawCalled 0)
|
||||||
|
|
||||||
|
(defmethod new [] 0)
|
||||||
|
|
||||||
|
(defmethod :Void initialize [:String title :Int width :Int height :Int _letterWidth :Int _letterHeight]
|
||||||
|
(set letterWidth _letterWidth)
|
||||||
|
(set letterHeight _letterHeight))
|
||||||
|
|
||||||
|
(defmethod :Void draw [:Graphics graphics]
|
||||||
|
(+= drawCalled 1))
|
3
projects/asciilib2/test.sh
Normal file → Executable file
3
projects/asciilib2/test.sh
Normal file → Executable file
@@ -1,3 +1,4 @@
|
|||||||
#! /bin/bash
|
#! /bin/bash
|
||||||
|
|
||||||
haxe build.hxml
|
haxelib dev asciilib .
|
||||||
|
(cd test && haxe build.hxml)
|
6
projects/asciilib2/test/build.hxml
Normal file
6
projects/asciilib2/test/build.hxml
Normal file
@@ -0,0 +1,6 @@
|
|||||||
|
-lib kiss
|
||||||
|
-lib asciilib
|
||||||
|
-lib utest
|
||||||
|
-cp src
|
||||||
|
--main Main
|
||||||
|
--interp
|
20
projects/asciilib2/test/src/Main.hx
Normal file
20
projects/asciilib2/test/src/Main.hx
Normal file
@@ -0,0 +1,20 @@
|
|||||||
|
package;
|
||||||
|
|
||||||
|
import utest.Runner;
|
||||||
|
import utest.ui.Report;
|
||||||
|
import asciilib.GameLogic;
|
||||||
|
import asciilib.Game;
|
||||||
|
import asciilib.backends.test.*;
|
||||||
|
|
||||||
|
class Main {
|
||||||
|
public static function newGame(logic:GameLogic) {
|
||||||
|
return new Game("Test game", 100, 40, 8, 12, logic, new TestGraphicsBackend());
|
||||||
|
}
|
||||||
|
|
||||||
|
static function main() {
|
||||||
|
var runner = new Runner();
|
||||||
|
runner.addCases(cases);
|
||||||
|
Report.create(runner);
|
||||||
|
runner.run();
|
||||||
|
}
|
||||||
|
}
|
@@ -0,0 +1,36 @@
|
|||||||
|
package cases;
|
||||||
|
|
||||||
|
import utest.Test;
|
||||||
|
import utest.Assert;
|
||||||
|
import asciilib.GameLogic;
|
||||||
|
import asciilib.Game;
|
||||||
|
import asciilib.Graphics;
|
||||||
|
import asciilib.Colors;
|
||||||
|
import asciilib.backends.test.TestGraphicsBackend;
|
||||||
|
|
||||||
|
class DrawOnlyWhenModifiedGameLogic implements GameLogic {
|
||||||
|
var firstDraw = true;
|
||||||
|
|
||||||
|
public function new() {}
|
||||||
|
|
||||||
|
public function update(deltaSeconds:Float):Void {}
|
||||||
|
|
||||||
|
public function draw(graphics:Void->Graphics):Void {
|
||||||
|
if (firstDraw) {
|
||||||
|
graphics().setLetter(0, 0, {char: "@", color: Colors.Red});
|
||||||
|
firstDraw = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
class DrawOnlyWhenModifiedTestCase extends Test {
|
||||||
|
function testDrawOnlyWhenModified() {
|
||||||
|
var game = Main.newGame(new DrawOnlyWhenModifiedGameLogic());
|
||||||
|
var graphicsBackend:TestGraphicsBackend = cast game.graphicsBackend;
|
||||||
|
game.draw();
|
||||||
|
Assert.equals("@", game.graphics.getLetter(0, 0).char);
|
||||||
|
Assert.equals(1, graphicsBackend.drawCalled);
|
||||||
|
game.draw();
|
||||||
|
Assert.equals(1, graphicsBackend.drawCalled);
|
||||||
|
}
|
||||||
|
}
|
Reference in New Issue
Block a user