[ascii] Test graphics backend, first unit test
This commit is contained in:
@@ -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