Skip to content

Commit f6c74fa

Browse files
Tests: Draw the flat prim test's points and rects inside the images more often, and say which prims the timings are of
A copy changes something only when its source, its rect, its destination and its point all leave something to copy, which with every coordinate drawn from a few before an image to a few past it happened in about one round in eight. Three in four coordinates are now inside the image, and the test asks that at least a tenth of the rounds change something. ImageOperationCostTest traces whether ImageDataUtil called the flat prims or the object prims.
1 parent efa625d commit f6c74fa

2 files changed

Lines changed: 8 additions & 5 deletions

File tree

‎tests/unit/src/graphics/ImageFlatPrimTest.hx‎

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -403,9 +403,10 @@ class ImageFlatPrimTest extends Test
403403
/**
404404
Runs `operation` on two copies of each round's images, through the flat prim and through
405405
the object prim, which must leave the same bytes in every buffer and return the same.
406-
The parameters are drawn from a generator seeded the same for both. At least a quarter of
406+
The parameters are drawn from a generator seeded the same for both. At least a tenth of
407407
the rounds must change a buffer or return something, so that the comparison isn't of
408-
nothing.
408+
nothing: a copy changes nothing when its source, its rect, its destination or its point
409+
leaves nothing to copy, so only a fifth or so of those change anything.
409410
**/
410411
private static function check(salt:Int, operation:Scene->Random->Bool->String, ?pos:haxe.PosInfos):Void
411412
{
@@ -442,7 +443,7 @@ class ImageFlatPrimTest extends Test
442443
}
443444

444445
Assert.equals(0, failures.length, failures.length + " of " + ROUNDS + " rounds differ:\n" + failures.slice(0, 5).join("\n"), pos);
445-
Assert.isTrue(changed >= ROUNDS / 4, 'only $changed of $ROUNDS rounds changed anything', pos);
446+
Assert.isTrue(changed >= ROUNDS / 10, 'only $changed of $ROUNDS rounds changed anything', pos);
446447
}
447448

448449
private static function randomPoint(random:Random, image:Image):Vector2
@@ -463,11 +464,12 @@ class ImageFlatPrimTest extends Test
463464
}
464465

465466
/**
466-
A value from a few before 0 to a few past `size`, a quarter of them fractional.
467+
A value from 0 to `size`, or for a quarter of them from a few before 0 to a few past
468+
`size`, and a quarter of them fractional.
467469
**/
468470
private static function coordinate(random:Random, size:Int):Float
469471
{
470-
var value:Float = random.range(-3, size + 3);
472+
var value:Float = random.chance(3, 4) ? random.int(size + 1) : random.range(-3, size + 3);
471473
if (random.chance(1, 4)) value += [0.25, 0.5, 0.75][random.int(3)];
472474
return value;
473475
}

‎tests/unit/src/graphics/ImageOperationCostTest.hx‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@ class ImageOperationCostTest extends Test
6565
rect16 = new Rectangle(5, 5, 16, 16);
6666
small = ImageFixture.create(16, 16, 0x80FFFFFF);
6767

68+
trace("ImageOperationCost: ImageDataUtil calls the " + #if lime_disable_flat_cffi "object" #else "flat" #end + " prims, and times are in ns a call");
6869
report("fillRect 1x1", 0, 1, 2);
6970
report("fillRect 4x4", 3, 4, -1);
7071
report("copyPixels 16x16", 5, 6, 7);

0 commit comments

Comments
 (0)