Return-Path: X-Original-To: apmail-flex-commits-archive@www.apache.org Delivered-To: apmail-flex-commits-archive@www.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id 8798318503 for ; Tue, 16 Feb 2016 11:47:35 +0000 (UTC) Received: (qmail 92527 invoked by uid 500); 16 Feb 2016 11:47:35 -0000 Delivered-To: apmail-flex-commits-archive@flex.apache.org Received: (qmail 92400 invoked by uid 500); 16 Feb 2016 11:47:35 -0000 Mailing-List: contact commits-help@flex.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@flex.apache.org Delivered-To: mailing list commits@flex.apache.org Received: (qmail 92359 invoked by uid 99); 16 Feb 2016 11:47:35 -0000 Received: from git1-us-west.apache.org (HELO git1-us-west.apache.org) (140.211.11.23) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 16 Feb 2016 11:47:35 +0000 Received: by git1-us-west.apache.org (ASF Mail Server at git1-us-west.apache.org, from userid 33) id 33981E08CD; Tue, 16 Feb 2016 11:47:35 +0000 (UTC) Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: mihaic@apache.org To: commits@flex.apache.org Date: Tue, 16 Feb 2016 11:47:37 -0000 Message-Id: In-Reply-To: <1b4ab2468e94487f9f27d78ac541f575@git.apache.org> References: <1b4ab2468e94487f9f27d78ac541f575@git.apache.org> X-Mailer: ASF-Git Admin Mailer 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. 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 Authored: Mon Feb 15 15:01:22 2016 +0100 Committer: Mihai Chira 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); + } + } +}