forked from arpit/openpyro
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathArrayUtilTest.as
More file actions
78 lines (62 loc) · 2.46 KB
/
ArrayUtilTest.as
File metadata and controls
78 lines (62 loc) · 2.46 KB
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
package org.openPyro.utils
{
import flexunit.framework.TestCase;
public class ArrayUtilTest extends TestCase
{
// Reference declaration for class to test
private var classToTestRef : org.openPyro.utils.ArrayUtil;
private var testArray:Array;
public function ArrayUtilTest(methodName:String=null)
{
super(methodName);
}
override public function setUp():void
{
super.setUp();
testArray = ["zero","one","two","three","four","five","six","seven","eight"];
}
override public function tearDown():void
{
super.tearDown();
testArray = null;
}
public function testInsertAt():void{
ArrayUtil.insertAt(testArray, 1, "between_0_and_1");
assertTrue("Array value at 1 was unexpected "+testArray[1],testArray[1] == "between_0_and_1");
assertTrue("Array length was incorrect "+testArray.length,testArray.length == 10);
ArrayUtil.insertAt(testArray, 9, "after_8");
assertTrue("Array value at 9 was unexpected "+testArray[9], testArray[9]=="after_8");
var newArray:Array = new Array();
ArrayUtil.insertAt(newArray, 0, "new_zero");
assertTrue("Array value at 0 was unexpected "+newArray[0], newArray[0]=="new_zero");
}
public function testSwap():void{
ArrayUtil.swapByValue(testArray, "zero", "one");
assertTrue("Array value at 0 was unexpected "+testArray[0], testArray[0]=="one");
assertTrue("Array value at 1 was unexpected "+testArray[1], testArray[1]=="zero");
}
public function testRemove():void{
ArrayUtil.remove(testArray, "zero");
assertTrue("Array value at 0 was unexpected "+testArray[0], testArray[0]=="one");
assertTrue("Array length did not reduce after remove", testArray.length == 8);
}
public function testRemoveAt():void{
ArrayUtil.removeItemAt(testArray, 0);
assertTrue("Array value at 0 was unexpected "+testArray[0], testArray[0]=="one");
}
public function testRemoveDuplicates():void{
testArray = ["zero","one","zero","two","three","one"];
ArrayUtil.removeDuplicates(testArray);
assertTrue("Remove Duplicates failed ",testArray.length == 4);
assertTrue("Remove Duplicates failed ",testArray[0] == "zero");
assertTrue("Remove Duplicates order changed",testArray[2] == "two");
// testing complex objects
var duplicate:Object = {label:'label1', data:"d2"};
var t2:Array = [duplicate,
{label:'label2', data:"d2"},
duplicate]
ArrayUtil.removeDuplicates(t2);
assertTrue("Remove Duplicates failed ",t2.length == 2);
}
}
}