You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@flex.apache.org by mi...@apache.org on 2016/03/23 13:03:24 UTC
[4/4] git commit: [flex-sdk] [refs/heads/develop] - FLEX-26808 Adding
VectorUtil.toArrayInt() to convert a Vector to an Array (and a few unit tests
for it). This is useful for the unit testing we're doing for this ticket.
FLEX-26808
Adding VectorUtil.toArrayInt() to convert a Vector to an Array (and a few unit tests for it). This is useful for the unit testing we're doing for this ticket.
Project: http://git-wip-us.apache.org/repos/asf/flex-sdk/repo
Commit: http://git-wip-us.apache.org/repos/asf/flex-sdk/commit/f543314c
Tree: http://git-wip-us.apache.org/repos/asf/flex-sdk/tree/f543314c
Diff: http://git-wip-us.apache.org/repos/asf/flex-sdk/diff/f543314c
Branch: refs/heads/develop
Commit: f543314c4f2c5b962492cceca55a53d7718741fe
Parents: cd338fd
Author: Mihai Chira <mi...@apache.org>
Authored: Wed Mar 23 12:54:12 2016 +0100
Committer: Mihai Chira <mi...@apache.org>
Committed: Wed Mar 23 12:54:12 2016 +0100
----------------------------------------------------------------------
.../framework/src/mx/utils/VectorUtil.as | 11 ++++
.../framework/tests/mx/utils/VectorUtilTests.as | 55 ++++++++++++++++++++
2 files changed, 66 insertions(+)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/flex-sdk/blob/f543314c/frameworks/projects/framework/src/mx/utils/VectorUtil.as
----------------------------------------------------------------------
diff --git a/frameworks/projects/framework/src/mx/utils/VectorUtil.as b/frameworks/projects/framework/src/mx/utils/VectorUtil.as
index f909a7b..3e73895 100644
--- a/frameworks/projects/framework/src/mx/utils/VectorUtil.as
+++ b/frameworks/projects/framework/src/mx/utils/VectorUtil.as
@@ -26,5 +26,16 @@ package mx.utils {
{
return v && v.length ? v[0] : -1;
}
+
+ public static function toArrayInt(v:Vector.<int>):Array
+ {
+ var result:Array = [];
+ for (var i:int = 0; i < (v ? v.length : 0); i++)
+ {
+ result.push(v[i]);
+ }
+
+ return result;
+ }
}
}
http://git-wip-us.apache.org/repos/asf/flex-sdk/blob/f543314c/frameworks/projects/framework/tests/mx/utils/VectorUtilTests.as
----------------------------------------------------------------------
diff --git a/frameworks/projects/framework/tests/mx/utils/VectorUtilTests.as b/frameworks/projects/framework/tests/mx/utils/VectorUtilTests.as
index 2ef9ccd..674ec97 100644
--- a/frameworks/projects/framework/tests/mx/utils/VectorUtilTests.as
+++ b/frameworks/projects/framework/tests/mx/utils/VectorUtilTests.as
@@ -22,6 +22,12 @@ package mx.utils {
import org.flexunit.asserts.assertTrue;
public class VectorUtilTests {
+
+ //--------------------------------------------------------------------------
+ //
+ // getFirstItem()
+ //
+ //--------------------------------------------------------------------------
[Test]
public function test_empty_vector():void
{
@@ -93,5 +99,54 @@ package mx.utils {
assertStrictlyEquals(2, vector[1]);
assertEquals(3, VectorUtil.getFirstItem(vector));
}
+
+
+ //--------------------------------------------------------------------------
+ //
+ // toArrayInt()
+ //
+ //--------------------------------------------------------------------------
+ [Test]
+ public function test_toArrayInt_with_different_items():void
+ {
+ //given
+ var vector:Vector.<int> = new <int>[1, 2, 3];
+
+ //then
+ assertTrue(ArrayUtil.arraysMatch([1, 2, 3], VectorUtil.toArrayInt(vector)));
+ }
+
+ [Test]
+ public function test_toArrayInt_with_duplicate_items():void
+ {
+ //given
+ var vector:Vector.<int> = new <int>[2, 2, 3, 1];
+
+ //then
+ assertTrue(ArrayUtil.arraysMatch([2, 2, 3, 1], VectorUtil.toArrayInt(vector)));
+ }
+
+ [Test]
+ public function test_toArrayInt_with_0_items():void
+ {
+ //given
+ var vector:Vector.<int> = new <int>[];
+
+ //when
+ var result:Array = VectorUtil.toArrayInt(vector);
+
+ //then
+ assertEquals(0, result.length);
+ }
+
+ [Test]
+ public function test_toArrayInt_with_null():void
+ {
+ //when
+ var result:Array = VectorUtil.toArrayInt(null);
+
+ //then
+ assertEquals(0, result.length);
+ }
}
}