Skip to content

Commit 993298c

Browse files
committed
tests: add (failing) tests for random Array "sorting"
These tests fail because we do not implement the exact same algorithm as Flash Player: - in AVM1, the test produces a different result - in AVM2, the test panics because Rust's sort doesn't accomodate non-Ord comparison functions
1 parent fd61be2 commit 993298c

File tree

8 files changed

+731
-0
lines changed

8 files changed

+731
-0
lines changed
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
// Compile with:
2+
// mtasc -main -version 8 Test.as -out test.swf
3+
class Test {
4+
5+
static function main(current) {
6+
var array = [];
7+
for (var i = 0; i < 50; i++) {
8+
array.push(i);
9+
}
10+
11+
// "sort" the array using randomly-chosen comparison results.
12+
array.sort(function(a, b) {
13+
var r = Test.rng();
14+
if (r % 8 == 0) {
15+
trace("cmp: " + a + " == " + b);
16+
return 0;
17+
} else if (r > 0) {
18+
trace("cmp: " + a + " > " + b);
19+
return 1;
20+
} else {
21+
trace("cmp: " + a + " < " + b);
22+
return -1;
23+
}
24+
});
25+
26+
trace("// contents of array");
27+
trace(array);
28+
}
29+
30+
// A simple deterministic PRNG; namely, Xorshift.
31+
static var rngState = 0x12345678;
32+
static function rng() {
33+
rngState ^= rngState << 13;
34+
rngState ^= rngState >>> 17;
35+
rngState ^= rngState << 5;
36+
return rngState;
37+
}
38+
}

0 commit comments

Comments
 (0)