flex-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mih...@apache.org
Subject [3/6] git commit: [flex-sdk] [refs/heads/develop] - FLEX-33058 Adding a few unit tests for ObjectUtil.compare() to start to test how useful this function is in HierarchicalCollectionViewCursor.findAny.
Date Tue, 16 Feb 2016 11:47:37 GMT
FLEX-33058
Adding a few unit tests for ObjectUtil.compare() to start to test how useful this function
is in HierarchicalCollectionViewCursor.findAny.


Project: http://git-wip-us.apache.org/repos/asf/flex-sdk/repo
Commit: http://git-wip-us.apache.org/repos/asf/flex-sdk/commit/4967c6b6
Tree: http://git-wip-us.apache.org/repos/asf/flex-sdk/tree/4967c6b6
Diff: http://git-wip-us.apache.org/repos/asf/flex-sdk/diff/4967c6b6

Branch: refs/heads/develop
Commit: 4967c6b6fe1fdae38cfa1969aa01be60eb0e44a7
Parents: 77a3ae7
Author: Mihai Chira <mihaic@apache.org>
Authored: Mon Feb 15 15:01:22 2016 +0100
Committer: Mihai Chira <mihaic@apache.org>
Committed: Mon Feb 15 15:01:22 2016 +0100

----------------------------------------------------------------------
 .../tests/mx/utils/ObjectUtil_Compare_Tests.as  | 113 +++++++++++++++++++
 1 file changed, 113 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/flex-sdk/blob/4967c6b6/frameworks/projects/framework/tests/mx/utils/ObjectUtil_Compare_Tests.as
----------------------------------------------------------------------
diff --git a/frameworks/projects/framework/tests/mx/utils/ObjectUtil_Compare_Tests.as b/frameworks/projects/framework/tests/mx/utils/ObjectUtil_Compare_Tests.as
new file mode 100644
index 0000000..5c33d9c
--- /dev/null
+++ b/frameworks/projects/framework/tests/mx/utils/ObjectUtil_Compare_Tests.as
@@ -0,0 +1,113 @@
+////////////////////////////////////////////////////////////////////////////////
+//
+//  Licensed to the Apache Software Foundation (ASF) under one or more
+//  contributor license agreements.  See the NOTICE file distributed with
+//  this work for additional information regarding copyright ownership.
+//  The ASF licenses this file to You under the Apache License, Version 2.0
+//  (the "License"); you may not use this file except in compliance with
+//  the License.  You may obtain a copy of the License at
+//
+//      http://www.apache.org/licenses/LICENSE-2.0
+//
+//  Unless required by applicable law or agreed to in writing, software
+//  distributed under the License is distributed on an "AS IS" BASIS,
+//  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+//  See the License for the specific language governing permissions and
+//  limitations under the License.
+//
+////////////////////////////////////////////////////////////////////////////////
+
+package mx.utils {
+    import org.flexunit.asserts.assertEquals;
+
+    public class ObjectUtil_Compare_Tests
+    {
+        private static const A_SMALLER_THAN_B:int = -1;
+        private static const A_LARGER_THAN_B:int = 1;
+        private static const A_EQUAL_TO_B:int = 0;
+
+        [Test]
+        public function test_object_is_smaller_when_first_property_smaller_even_if_second_property_larger():void
+        {
+            //given
+            var objectA:Object = {propertyA:1, propertyB:23};
+            var objectB:Object = {propertyA:45, propertyB:2};
+
+            //when
+            var compareResult:int = ObjectUtil.compare(objectA, objectB);
+
+            //then
+            assertEquals(A_SMALLER_THAN_B, compareResult);
+        }
+
+        [Test]
+        public function test_object_is_larger_when_first_property_larger_even_if_second_property_smaller():void
+        {
+            //given
+            var objectA:Object = {propertyA:45, propertyB:2};
+            var objectB:Object = {propertyA:1, propertyB:23};
+
+            //when
+            var compareResult:int = ObjectUtil.compare(objectA, objectB);
+
+            //then
+            assertEquals(A_LARGER_THAN_B, compareResult);
+        }
+
+        [Test]
+        public function test_object_is_smaller_even_when_common_properties_equal_but_missing_extra_properties():void
+        {
+            //given
+            var objectA:Object = {propertyA:45};
+            var objectB:Object = {propertyA:45, propertyB:2};
+
+            //when
+            var compareResult:int = ObjectUtil.compare(objectA, objectB);
+
+            //then
+            assertEquals(A_SMALLER_THAN_B, compareResult);
+        }
+
+        [Test]
+        public function test_object_is_smaller_even_when_common_property_larger_but_missing_extra_properties():void
+        {
+            //given
+            var objectA:Object = {propertyA:46};
+            var objectB:Object = {propertyA:45, propertyB:2};
+
+            //when
+            var compareResult:int = ObjectUtil.compare(objectA, objectB);
+
+            //then
+            assertEquals(A_SMALLER_THAN_B, compareResult);
+        }
+
+        [Test]
+        public function test_null_and_undefined_are_seen_equal():void
+        {
+            //given
+            var objectA:Object = {propertyA:45, propertyB:null};
+            var objectB:Object = {propertyA:45, propertyB:undefined};
+
+            //when
+            var compareResult:int = ObjectUtil.compare(objectA, objectB);
+
+            //then
+            assertEquals(A_EQUAL_TO_B, compareResult);
+        }
+
+        [Test]
+        public function test_NaN_seen_larger_than_largest_number():void
+        {
+            //given
+            var objectA:Object = {propertyA:Number.MAX_VALUE};
+            var objectB:Object = {propertyA:NaN};
+
+            //when
+            var compareResult:int = ObjectUtil.compare(objectA, objectB);
+
+            //then
+            assertEquals(A_SMALLER_THAN_B, compareResult);
+        }
+    }
+}


Mime
View raw message