-
Notifications
You must be signed in to change notification settings - Fork 432
/
FlxArrayUtilTest.hx
124 lines (102 loc) · 2.27 KB
/
FlxArrayUtilTest.hx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
package flixel.util;
import massive.munit.Assert;
using flixel.util.FlxArrayUtil;
class FlxArrayUtilTest
{
@Test
function testFlatten2DArray()
{
var array = [[1, 2, 3], [3, 2, 1], [2, 1, 3]];
var flattened = FlxArrayUtil.flatten2DArray(array);
Assert.isTrue([1, 2, 3, 3, 2, 1, 2, 1, 3].equals(flattened));
}
@Test
function testEqualsNullNull()
{
Assert.isTrue((null : Array<Int>).equals(null));
}
@Test
function testEqualsNullNotNull()
{
Assert.isFalse((null : Array<Int>).equals([]));
}
@Test
function testEqualsNotNullNull()
{
Assert.isFalse([].equals(null));
}
@Test
function testEqualsEmptyEmpty()
{
Assert.isTrue([].equals([]));
}
@Test
function testEqualsDifferentLength()
{
Assert.isFalse([1, 2, 3].equals([1, 2]));
}
@Test
function testEqualsSame()
{
Assert.isTrue([1, 2, 3].equals([1, 2, 3]));
}
@Test
function testEqualsSameLengthButDifferent()
{
Assert.isFalse([1, 2, 3].equals([3, 2, 1]));
}
@Test
function testLastNullArray()
{
Assert.isNull((null : Array<Int>).last());
}
@Test
function testLastEmptyArray()
{
Assert.isNull([].last());
}
@Test
function testLast()
{
Assert.areEqual(1, [1].last());
Assert.areEqual(3, [1, 2, 3].last());
}
@Test
function testSwapByIndex()
{
Assert.isTrue([0, 1, 2, 3, 4, 5].swapByIndex(2, 4).equals([0, 1, 4, 3, 2, 5]));
}
@Test
function testSafeSwapByIndex()
{
Assert.isTrue([0, 1, 2, 3].safeSwapByIndex(0, 3).equals([3, 1, 2, 0]));
Assert.isTrue([0, 1, 2, 3].safeSwapByIndex(2, 4).equals([0, 1, 2, 3]));
Assert.isTrue([0, 1, 2, 3].safeSwapByIndex(-1, 2).equals([0, 1, 2, 3]));
}
@Test
function testSwap()
{
Assert.isTrue([0, 1, 2, 3, 4, 5].swap(1, 3).equals([0, 3, 2, 1, 4, 5]));
}
@Test
function testSafeSwap()
{
Assert.isTrue([0, 1, 2, 3, 4, 5].safeSwap(0, 2).equals([2, 1, 0, 3, 4, 5]));
Assert.isTrue([0, 1, 2, 3, 4, 5].safeSwap(1, 6).equals([0, 1, 2, 3, 4, 5]));
}
@Test
@:haxe.warning("-WDeprecated")
function testSetLength()
{
final arr = [0, 1, 2, 3, 4, 5];
// ignores negative numbers
arr.setLength(-1);
FlxAssert.arraysEqual([0, 1, 2, 3, 4, 5], arr);
// expected usage
arr.setLength(3);
FlxAssert.arraysEqual([0, 1, 2], arr);
// can't make arrays bigger
arr.setLength(5);
FlxAssert.arraysEqual([0, 1, 2], arr);
}
}