Created
May 25, 2014 18:57
-
-
Save azrafe7/b44ea424277b1802b8de to your computer and use it in GitHub Desktop.
FlxColor tests
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import flash.system.System; | |
import haxe.PosInfos; | |
import flixel.util.FlxColor; | |
class Main { | |
static function main() { | |
var test:TestSuite = new TestSuite(); | |
test.testColor_Color(); | |
test.testColor_Int(); | |
test.testInt_Color(); | |
test.testColor_UInt(); | |
test.testUInt_Color(); | |
test.testEquality(); | |
test.testRGBA(); | |
test.testNull(); | |
trace("[ALL TESTS PASSED]"); | |
TestSuite.quit(); | |
} | |
} | |
class TestSuite { | |
var c1:FlxColor; | |
var c2:FlxColor; | |
var i:Int; | |
var u:UInt; | |
public function new() { | |
c1 = 0xffffffff; | |
c2 = 0xfffffff0; | |
i = c1-1; | |
u = c2; | |
u++; | |
trace('c1: ${StringTools.hex(c1)} ($c1)'); | |
trace('c2: ${StringTools.hex(c2)} ($c2)'); | |
trace('i : ${StringTools.hex(i)} ($i)'); | |
trace('u : ${StringTools.hex(u)} ($u)'); | |
} | |
public static function quit() { | |
#if (flash || js) | |
System.exit(1); | |
#else | |
Sys.exit(1); | |
#end | |
} | |
public static function assertTrue(b:Bool, ?str:String, ?pos:PosInfos):Void | |
{ | |
var msg = (!b ? '[FAIL]' : ' [OK]') + ' @${pos.fileName}:${pos.lineNumber}: expected TRUE ' + (str != null ? str : ''); | |
if (!b) { | |
trace(msg); | |
quit(); | |
} else { | |
trace(msg); | |
} | |
} | |
public static function assertFalse(b:Bool, ?str:String, ?pos:PosInfos):Void | |
{ | |
var msg = (b ? '[FAIL]' : ' [OK]') + ' @${pos.fileName}:${pos.lineNumber}: expected FALSE ' + (str != null ? str : ''); | |
if (b) { | |
trace(msg); | |
quit(); | |
} else { | |
trace(msg); | |
} | |
} | |
public function testColor_Int() { | |
trace("-- testColor_Int"); | |
assertTrue(c1 != i, '$c1 != $i'); | |
assertFalse(c1 == i, '$c1 == $i'); | |
assertTrue(c1 > i, '$c1 > $i'); | |
assertFalse(c1 < i, '$c1 < $i'); | |
assertFalse(c1 <= i, '$c1 <= $i'); | |
assertTrue(c1 >= i, '$c1 >= $i'); | |
} | |
public function testColor_Color() { | |
trace("-- testColor_Color"); | |
assertTrue(c1 != c2, '$c1 != $c2'); | |
assertFalse(c1 == c2, '$c1 == $c2'); | |
assertTrue(c1 > c2, '$c1 > $c2'); | |
assertFalse(c1 < c2, '$c1 < $c2'); | |
assertFalse(c1 <= c2, '$c1 <= $c2'); | |
assertTrue(c1 >= c2, '$c1 >= $c2'); | |
} | |
public function testInt_Color() { | |
trace("-- testInt_Color"); | |
assertTrue(i != c1, '$i != $c1'); | |
assertFalse(i == c1, '$i == $c1'); | |
assertFalse(i > c1, '$i > $c1'); | |
assertTrue(i < c1, '$i < $c1'); | |
assertTrue(i <= c1, '$i <= $c1'); | |
assertFalse(i >= c1, '$i >= $c1'); | |
} | |
public function testColor_UInt() { | |
trace("-- testColor_UInt"); | |
assertTrue(c2 != u, '$c2 != $u'); | |
assertFalse(c2 == u, '$c2 == $u'); | |
assertFalse(c2 > u, '$c2 > $u'); | |
assertTrue(c2 < u, '$c2 < $u'); | |
assertTrue(c2 <= u, '$c2 <= $u'); | |
assertFalse(c2 >= u, '$c2 >= $u'); | |
} | |
public function testUInt_Color() { | |
trace("-- testUInt_Color"); | |
assertTrue(u != c2, '$u != $c2'); | |
assertFalse(u == c2, '$u == $c2'); | |
assertTrue(u > c2, '$u > $c2'); | |
assertFalse(u < c2, '$u < $c2'); | |
assertFalse(u <= c2, '$u <= $c2'); | |
assertTrue(u >= c2, '$u >= $c2'); | |
} | |
public function testEquality() { | |
trace("-- testEquality"); | |
u = 0xFFFFFFFF; | |
i = -1; | |
c1 = u; | |
c2 = i; | |
var u2:UInt = 16; | |
var i2:Int = 16; | |
assertTrue(new FlxColor(u2) == new FlxColor(i2), '$c1 == $c2'); | |
assertFalse(c2 != c1, '$c1 != $c2'); | |
assertFalse(c1 != c2, '$c1 != $c2'); | |
assertTrue(c1 == c2, '$c1 == $c2'); | |
assertTrue(c2 == c1, '$c2 == $c1'); | |
assertTrue(c1 == i, '$c1 == $i'); | |
assertTrue(i == c1, '$i == $c1'); | |
assertTrue(c1 == u, '$c1 == $u'); | |
assertTrue(u == c1, '$u == $c1'); | |
} | |
public function testRGBA() { | |
trace("-- testRGBA"); | |
c1 = 0x12345678; | |
assertTrue(c1.alpha == 0x12); | |
assertTrue(c1.red == 0x34); | |
assertTrue(c1.green == 0x56); | |
assertTrue(c1.blue == 0x78); | |
c1.alpha = 0x87; | |
c1.red = 0x65; | |
c1.green = 0x43; | |
c1.blue = 0x21; | |
assertTrue(c1 == 0x87654321); | |
assertTrue(0x87 == c1.alpha); | |
c1.green = -1; | |
assertTrue(c1.green == 0xff); | |
c1.alpha = 0xff; | |
assertTrue(c1 < 0); | |
} | |
public function testNull() { | |
function nullable(?color:FlxColor):FlxColor { | |
if (null != color) { | |
return color; | |
} else { | |
return 0xFFFFFFFF; | |
} | |
} | |
var c3:Null<FlxColor> = null; | |
assertTrue(c3 == null); | |
assertTrue(c3 != 0); | |
assertTrue(nullable() == 0xFFFFFFFF); | |
assertTrue(nullable() == FlxColor.WHITE); | |
assertTrue(nullable(FlxColor.RED) == 0xFFFF0000); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment