FLEX-35037 Renaming test files to 1) show what they're testing and 2) make sure they're picked up and ran by the test scripts.
Project: http://git-wip-us.apache.org/repos/asf/flex-sdk/repo Commit: http://git-wip-us.apache.org/repos/asf/flex-sdk/commit/81643dd1 Tree: http://git-wip-us.apache.org/repos/asf/flex-sdk/tree/81643dd1 Diff: http://git-wip-us.apache.org/repos/asf/flex-sdk/diff/81643dd1 Branch: refs/heads/develop Commit: 81643dd12a659647b88921e27c2a10d43661a27b Parents: 1d8d02c Author: Mihai Chira <mih...@apache.org> Authored: Mon Feb 22 19:15:36 2016 +0100 Committer: Mihai Chira <mih...@apache.org> Committed: Mon Feb 22 19:15:36 2016 +0100 ---------------------------------------------------------------------- .../tests/mx/collections/AddRemoveNumbers.as | 174 ---------- .../tests/mx/collections/AddRemoveObjects.as | 274 --------------- .../tests/mx/collections/AddRemoveStrings.as | 200 ----------- .../ArrayCollection_AddRemoveNumbers_Tests.as | 174 ++++++++++ .../ArrayCollection_AddRemoveObjects_Tests.as | 274 +++++++++++++++ .../ArrayCollection_AddRemoveStrings_Tests.as | 200 +++++++++++ ...ArrayCollection_FilerAndSortNumbers_Tests.as | 114 +++++++ ...ArrayCollection_FilerAndSortStrings_Tests.as | 114 +++++++ .../ArrayCollection_FilterNumbers_Tests.as | 315 +++++++++++++++++ .../ArrayCollection_FilterStrings_Tests.as | 341 +++++++++++++++++++ .../ArrayCollection_SortNumbers_Tests.as | 212 ++++++++++++ .../ArrayCollection_SortStrings_Tests.as | 254 ++++++++++++++ .../tests/mx/collections/FilerAndSortNumbers.as | 114 ------- .../tests/mx/collections/FilerAndSortStrings.as | 114 ------- .../tests/mx/collections/FilterNumbers.as | 315 ----------------- .../tests/mx/collections/FilterStrings.as | 341 ------------------- .../tests/mx/collections/SortNumbers.as | 212 ------------ .../tests/mx/collections/SortStrings.as | 254 -------------- 18 files changed, 1998 insertions(+), 1998 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/flex-sdk/blob/81643dd1/frameworks/projects/framework/tests/mx/collections/AddRemoveNumbers.as ---------------------------------------------------------------------- diff --git a/frameworks/projects/framework/tests/mx/collections/AddRemoveNumbers.as b/frameworks/projects/framework/tests/mx/collections/AddRemoveNumbers.as deleted file mode 100644 index efd43f5..0000000 --- a/frameworks/projects/framework/tests/mx/collections/AddRemoveNumbers.as +++ /dev/null @@ -1,174 +0,0 @@ -//////////////////////////////////////////////////////////////////////////////// -// -// 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.collections { - import org.flexunit.asserts.*; - - public class AddRemoveNumbers - { - protected var _sut:ArrayCollection; - - [Before] - public function setUp():void - { - _sut = new ArrayCollection(); - } - - [After] - public function tearDown():void - { - _sut = null; - } - - [Test] - public function empty():void - { - //then - assertEquals(_sut.length, 0); - } - - [Test] - public function addNumbers():void - { - _sut.addItem(1); - assertEquals("Length is not one", 1, _sut.length); - assertEquals("First element not correct", 1, _sut[0]); - _sut.addItem(2); - assertEquals("Length is not two", 2, _sut.length); - assertEquals("Second element not correct", 2, _sut[1]); - } - - [Test] - public function addDuplicate():void - { - addNumbers(); - _sut.addItem(1); - assertEquals("Length is not three", 3, _sut.length); - assertEquals("First element not correct", 1, _sut[0]); - assertEquals("Second element not correct", 2, _sut[1]); - assertEquals("Second element not correct", 1, _sut[2]); - } - - [Test] - public function removeDuplicate():void - { - addNumbers(); - _sut.addItem(1); - _sut.removeItemAt(0); - assertEquals("Length is not two", 2, _sut.length); - assertEquals("First element not correct", 2, _sut[0]); - assertEquals("Second element not correct", 1, _sut[1]); - } - - [Test] - public function removeAllNumbers():void - { - addNumbers(); - _sut.removeAll(); - assertEquals("Length is not zero", 0, _sut.length); - } - - [Test] - public function removeFirstNumbers():void - { - addNumbers(); - _sut.removeItemAt(0); - assertEquals("First element not correct", 2, _sut[0]); - assertEquals("Length is not one", 1, _sut.length); - _sut.removeItemAt(0); - assertEquals("Length is not zero", 0, _sut.length); - } - - [Test] - public function removeLastNumbers():void - { - addNumbers(); - _sut.removeItemAt(1); - assertEquals("First element not correct", 1, _sut[0]); - assertEquals("Length is not one", 1, _sut.length); - _sut.removeItemAt(0); - assertEquals("Length is not zero", 0, _sut.length); - } - - [Test] - public function removeItemByIndex():void - { - addNumbers(); - _sut.removeItemAt(_sut.getItemIndex(1)); - assertEquals("First element not correct", 2, _sut[0]); - assertEquals("Length is not one", 1, _sut.length); - _sut.removeItemAt(_sut.getItemIndex(2)); - assertEquals("Length is not zero", 0, _sut.length); - } - - [Test] - public function outOfRange():void - { - addNumbers(); - try { - _sut.removeItemAt(-1); - } - catch (error:Error) - { - assertTrue("Error not range error", error is RangeError); - } - assertEquals("Length is not two", 2, _sut.length); - try { - _sut.removeItemAt(10); - } - catch (error:Error) - { - assertTrue("Error not range error", error is RangeError); - } - assertEquals("Length is not two", 2, _sut.length); - } - - [Test] - public function swapItemsTwoThenOne():void - { - addNumbers(); - - var item1:Number = _sut.getItemAt(0) as Number; - var item2:Number = _sut.getItemAt(1) as Number; - - _sut.setItemAt(item2,0); - _sut.setItemAt(item1,1); - - assertEquals("Length is not two", 2, _sut.length); - assertEquals("First element not correct", 2, _sut[0]); - assertEquals("Second element not correct", 1, _sut[1]); - } - - [Test] - public function swapItemsOneThenTwo():void - { - addNumbers(); - - var item1:Number = _sut.getItemAt(0) as Number; - var item2:Number = _sut.getItemAt(1) as Number; - - _sut.setItemAt(item1,1); - _sut.setItemAt(item2,0); - - assertEquals("Length is not two", 2, _sut.length); - assertEquals("First element not correct", 2, _sut[0]); - assertEquals("Second element not correct", 1, _sut[1]); - } - - } -} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/flex-sdk/blob/81643dd1/frameworks/projects/framework/tests/mx/collections/AddRemoveObjects.as ---------------------------------------------------------------------- diff --git a/frameworks/projects/framework/tests/mx/collections/AddRemoveObjects.as b/frameworks/projects/framework/tests/mx/collections/AddRemoveObjects.as deleted file mode 100644 index 69817d4..0000000 --- a/frameworks/projects/framework/tests/mx/collections/AddRemoveObjects.as +++ /dev/null @@ -1,274 +0,0 @@ -//////////////////////////////////////////////////////////////////////////////// -// -// 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.collections { - import org.flexunit.asserts.*; - - public class AddRemoveObjects - { - private var _sut:ArrayCollection; - - protected var players:Array = [ - {team:"TeamOne",jerseyNumber:80,lastName:"PlayerA",firstName:"Aa"}, - {team:"TeamTwo",jerseyNumber:7, lastName:"PlayerB",firstName:"Bb"}, - {team:"TeamOne",jerseyNumber:12, lastName:"PlayerC",firstName:"Cc"}, - {team:"TeamOne",jerseyNumber:21,lastName:"PlayerD",firstName:"Dd"}, - {team:"TeamThree",jerseyNumber:34, lastName:"PlayerE",firstName:"Ee"}, - {team:"TeamOne",jerseyNumber:12, lastName:"PlayerF",firstName:"Ff"}, - {team:"TeamTwo",jerseyNumber:7, lastName:"PlayerG",firstName:"Gg"} - ]; - - [Before] - public function setUp():void - { - _sut = new ArrayCollection(); - } - - [After] - public function tearDown():void - { - _sut = null; - } - - [Test] - public function empty():void - { - assertEquals(_sut.length, 0); - } - - [Test] - public function addObjects():void - { - _sut = new ArrayCollection(players); - assertEquals("Length is not seven", 7, _sut.length); - assertEquals("First element not correct", players[0], _sut[0]); - assertEquals("Second element not correct", players[1], _sut[1]); - assertEquals("Third element not correct", players[2], _sut[2]); - assertEquals("Fouth element not correct", players[3], _sut[3]); - assertEquals("Fifth element not correct", players[4], _sut[4]); - assertEquals("Sixth element not correct", players[5], _sut[5]); - assertEquals("Seventh element not correct", players[6], _sut[6]); - } - - [Test] - public function addDuplicate():void - { - addObjects(); - _sut.addItem(players[0]); - assertEquals("Length is not eight", 8, _sut.length); - assertEquals("First element not correct", players[0], _sut[0]); - assertEquals("Second element not correct", players[1], _sut[1]); - assertEquals("Third element not correct", players[2], _sut[2]); - assertEquals("Fouth element not correct", players[3], _sut[3]); - assertEquals("Fifth element not correct", players[4], _sut[4]); - assertEquals("Sixth element not correct", players[5], _sut[5]); - assertEquals("Seventh element not correct", players[6], _sut[6]); - assertEquals("Eighth element not correct", players[0], _sut[7]); - } - - [Test] - public function removeDuplicate():void - { - //given - addObjects(); - var firstPlayer:* = players[0]; - var secondPlayer:* = players[1]; - var thirdPlayer:* = players[2]; - var fourthPlayer:* = players[3]; - var fifthPlayer:* = players[4]; - var sixthPlayer:* = players[5]; - var seventhPlayer:* = players[6]; - - //when - _sut.addItem(players[0]); - _sut.removeItemAt(0); - //then - assertEquals("Length is not seven", 7, _sut.length); - assertEquals("First element not correct", secondPlayer, _sut[0]); - assertEquals("Second element not correct", thirdPlayer, _sut[1]); - assertEquals("Third element not correct", fourthPlayer, _sut[2]); - assertEquals("Fourth element not correct", fifthPlayer, _sut[3]); - assertEquals("Fifth element not correct", sixthPlayer, _sut[4]); - assertEquals("Sixth element not correct", seventhPlayer, _sut[5]); - assertEquals("Seventh element not correct", firstPlayer, _sut[6]); - } - - [Test] - public function removeAllObjects():void - { - addObjects(); - _sut.removeAll(); - assertEquals("Length is not zero", 0, _sut.length); - } - - [Test] - public function removeFirstObjects():void - { - //given - addObjects(); - var secondPlayer:Object = players[1]; - - //when - _sut.removeItemAt(0); - - //then - assertEquals("First element not correct", secondPlayer, _sut[0]); - assertEquals("Length is not six", 6, _sut.length); - - //when - _sut.removeItemAt(0); - //then - assertEquals("Length is not five", 5, _sut.length); - - //when - _sut.removeItemAt(0); - //then - assertEquals("Length is not four", 4, _sut.length); - - //when - _sut.removeItemAt(0); - //then - assertEquals("Length is not three", 3, _sut.length); - - //when - _sut.removeItemAt(0); - //then - assertEquals("Length is not two", 2, _sut.length); - - //when - _sut.removeItemAt(0); - //then - assertEquals("Length is not one", 1, _sut.length); - - //when - _sut.removeItemAt(0); - //then - assertEquals("Length is not zero", 0, _sut.length); - } - - [Test] - public function removeLastNumbers():void - { - addObjects(); - _sut.removeItemAt(6); - assertEquals("First element not correct", players[0], _sut[0]); - assertEquals("Length is not six", 6, _sut.length); - _sut.removeItemAt(0); - assertEquals("Length is not five", 5, _sut.length); - _sut.removeItemAt(0); - assertEquals("Length is not four", 4, _sut.length); - _sut.removeItemAt(0); - assertEquals("Length is not three", 3, _sut.length); - _sut.removeItemAt(0); - assertEquals("Length is not two", 2, _sut.length); - _sut.removeItemAt(0); - assertEquals("Length is not one", 1, _sut.length); - _sut.removeItemAt(0); - assertEquals("Length is not zero", 0, _sut.length); - } - - [Test] - public function removeItemByIndex():void - { - //given - addObjects(); - const secondPlayer:Object = players[1]; - const thirdPlayer:Object = players[2]; - const fourthPlayer:Object = players[3]; - - //when - _sut.removeItemAt(_sut.getItemIndex(players[0])); - - //then - assertEquals("First element incorrect", secondPlayer, _sut[0]); - assertEquals("Length is not six", 6, _sut.length); - - //when - _sut.removeItemAt(_sut.getItemIndex(thirdPlayer)); - - //then - assertEquals("First element not correct", secondPlayer, _sut[0]); - assertEquals("Second element not correct", fourthPlayer, _sut[1]); - assertEquals("Length is not four", 5, _sut.length); - } - - [Test] - public function outOfRange():void - { - addObjects(); - try { - _sut.removeItemAt(-1); - } - catch (error:Error) - { - assertTrue("Error not range error", error is RangeError); - } - assertEquals("Length is not seven", 7, _sut.length); - try { - _sut.removeItemAt(10); - } - catch (error:Error) - { - assertTrue("Error not range error", error is RangeError); - } - assertEquals("Length is not seven", 7, _sut.length); - } - - [Test] - public function swapItemsTwoThenOne():void - { - //given - addObjects(); - var item1:Object = _sut.getItemAt(0); - var item2:Object = _sut.getItemAt(1); - var firstPlayer:* = players[0]; - var secondPlayer:* = players[1]; - - //when - _sut.setItemAt(item2,0); - _sut.setItemAt(item1,1); - - //then - assertEquals("Length is not seven", 7, _sut.length); - assertEquals("First element not correct", secondPlayer, _sut[0]); - assertEquals("Second element not correct", firstPlayer, _sut[1]); - } - - [Test] - public function swapItemsOneThenTwo():void - { - //given - addObjects(); - var item1:Object = _sut.getItemAt(0); - var item2:Object = _sut.getItemAt(1); - var secondPlayer:Object = players[1]; - var firstPlayer:Object = players[0]; - - //when - _sut.setItemAt(item1,1); - _sut.setItemAt(item2,0); - - //then - assertEquals("Length is not seven", 7, _sut.length); - assertEquals("First element not correct", secondPlayer, _sut[0]); - assertEquals("Second element not correct", firstPlayer, _sut[1]); - - } - - } -} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/flex-sdk/blob/81643dd1/frameworks/projects/framework/tests/mx/collections/AddRemoveStrings.as ---------------------------------------------------------------------- diff --git a/frameworks/projects/framework/tests/mx/collections/AddRemoveStrings.as b/frameworks/projects/framework/tests/mx/collections/AddRemoveStrings.as deleted file mode 100644 index d6bdc53..0000000 --- a/frameworks/projects/framework/tests/mx/collections/AddRemoveStrings.as +++ /dev/null @@ -1,200 +0,0 @@ -//////////////////////////////////////////////////////////////////////////////// -// -// 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.collections { - import org.flexunit.asserts.*; - - public class AddRemoveStrings - { - protected var _sut:ArrayCollection; - - [Before] - public function setUp():void - { - _sut = new ArrayCollection(); - } - - [After] - public function tearDown():void - { - _sut = null; - } - - [Test] - public function empty():void - { - assertEquals(0, _sut.length); - } - - [Test] - public function addStrings():void - { - _sut.addItem("A"); - assertEquals("Length is not one", 1, _sut.length); - assertEquals("First element not correct", "A", _sut[0]); - - _sut.addItem("B"); - assertEquals("Length is not two", 2, _sut.length); - assertEquals("Second element not correct", "B", _sut[1]); - - _sut.addItem("D"); - assertEquals("Length is not three", 3, _sut.length); - assertEquals("Second element not correct", "D", _sut[2]); - - _sut.addItem("C"); - assertEquals("Length is not four", 4, _sut.length); - assertEquals("Second element not correct", "C", _sut[3]); - } - - [Test] - public function addDuplicate():void - { - //given - addStrings(); - - //when - _sut.addItem("B"); - - //then - assertEquals("Length is not five", 5, _sut.length); - assertEquals("First element not correct", "A", _sut[0]); - assertEquals("Second element not correct", "B", _sut[1]); - assertEquals("Second element not correct", "D", _sut[2]); - assertEquals("Second element not correct", "C", _sut[3]); - assertEquals("Second element not correct", "B", _sut[4]); - } - - [Test] - public function removeDuplicate():void - { - //given - addStrings(); - - //when - _sut.addItem("B"); - _sut.removeItemAt(1); - - //then - assertEquals("Length is not four", 4, _sut.length); - assertEquals("First element not correct", "A", _sut[0]); - assertEquals("Second element not correct", "D", _sut[1]); - assertEquals("Second element not correct", "C", _sut[2]); - assertEquals("Second element not correct", "B", _sut[3]); - } - - [Test] - public function removeAllStrings():void - { - addStrings(); - _sut.removeAll(); - assertEquals("Length is not zero", 0, _sut.length); - } - - [Test] - public function removeFirstStrings():void - { - addStrings(); - _sut.removeItemAt(0); - assertEquals("First element not correct", "B", _sut[0]); - assertEquals("Length is not three", 3, _sut.length); - _sut.removeItemAt(0); - assertEquals("Length is not two", 2, _sut.length); - } - - [Test] - public function removeLastStrings():void - { - addStrings(); - _sut.removeItemAt(1); - assertEquals("First element not correct", "A", _sut[0]); - assertEquals("Length is not three", 3, _sut.length); - _sut.removeItemAt(0); - assertEquals("Length is not two", 2, _sut.length); - } - - [Test] - public function removeItemByIndex():void - { - addStrings(); - _sut.removeItemAt(_sut.getItemIndex("B")); - assertEquals("First element not correct", "A", _sut[0]); - assertEquals("Length is not three", 3, _sut.length); - _sut.removeItemAt(_sut.getItemIndex("D")); - assertEquals("Length is not two", 2, _sut.length); - } - - [Test] - public function outOfRange():void - { - addStrings(); - try { - _sut.removeItemAt(-1); - } - catch (error:Error) - { - assertTrue("Error not range error", error is RangeError); - } - assertEquals("Length is not four", 4, _sut.length); - try { - _sut.removeItemAt(10); - } - catch (error:Error) - { - assertTrue("Error not range error", error is RangeError); - } - assertEquals("Length is not two", 4, _sut.length); - } - - [Test] - public function swapItemsTwoThenOne():void - { - //given - addStrings(); - var item1:String = _sut.getItemAt(0) as String; - var item2:String = _sut.getItemAt(1) as String; - - //when - _sut.setItemAt(item2, 0); - _sut.setItemAt(item1, 1); - - //then - assertEquals("Length is not four", 4, _sut.length); - assertEquals("First element not correct", "B", _sut[0]); - assertEquals("Second element not correct", "A", _sut[1]); - } - - [Test] - public function swapItemsOneThenTwo():void - { - //given - addStrings(); - var item1:String = _sut.getItemAt(0) as String; - var item2:String = _sut.getItemAt(1) as String; - - //when - _sut.setItemAt(item1, 1); - _sut.setItemAt(item2, 0); - - //then - assertEquals("Length is not four", 4, _sut.length); - assertEquals("First element not correct", "B", _sut[0]); - assertEquals("Second element not correct", "A", _sut[1]); - } - - } -} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/flex-sdk/blob/81643dd1/frameworks/projects/framework/tests/mx/collections/ArrayCollection_AddRemoveNumbers_Tests.as ---------------------------------------------------------------------- diff --git a/frameworks/projects/framework/tests/mx/collections/ArrayCollection_AddRemoveNumbers_Tests.as b/frameworks/projects/framework/tests/mx/collections/ArrayCollection_AddRemoveNumbers_Tests.as new file mode 100644 index 0000000..93d302a --- /dev/null +++ b/frameworks/projects/framework/tests/mx/collections/ArrayCollection_AddRemoveNumbers_Tests.as @@ -0,0 +1,174 @@ +//////////////////////////////////////////////////////////////////////////////// +// +// 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.collections { + import org.flexunit.asserts.*; + + public class ArrayCollection_AddRemoveNumbers_Tests + { + protected var _sut:ArrayCollection; + + [Before] + public function setUp():void + { + _sut = new ArrayCollection(); + } + + [After] + public function tearDown():void + { + _sut = null; + } + + [Test] + public function empty():void + { + //then + assertEquals(_sut.length, 0); + } + + [Test] + public function addNumbers():void + { + _sut.addItem(1); + assertEquals("Length is not one", 1, _sut.length); + assertEquals("First element not correct", 1, _sut[0]); + _sut.addItem(2); + assertEquals("Length is not two", 2, _sut.length); + assertEquals("Second element not correct", 2, _sut[1]); + } + + [Test] + public function addDuplicate():void + { + addNumbers(); + _sut.addItem(1); + assertEquals("Length is not three", 3, _sut.length); + assertEquals("First element not correct", 1, _sut[0]); + assertEquals("Second element not correct", 2, _sut[1]); + assertEquals("Second element not correct", 1, _sut[2]); + } + + [Test] + public function removeDuplicate():void + { + addNumbers(); + _sut.addItem(1); + _sut.removeItemAt(0); + assertEquals("Length is not two", 2, _sut.length); + assertEquals("First element not correct", 2, _sut[0]); + assertEquals("Second element not correct", 1, _sut[1]); + } + + [Test] + public function removeAllNumbers():void + { + addNumbers(); + _sut.removeAll(); + assertEquals("Length is not zero", 0, _sut.length); + } + + [Test] + public function removeFirstNumbers():void + { + addNumbers(); + _sut.removeItemAt(0); + assertEquals("First element not correct", 2, _sut[0]); + assertEquals("Length is not one", 1, _sut.length); + _sut.removeItemAt(0); + assertEquals("Length is not zero", 0, _sut.length); + } + + [Test] + public function removeLastNumbers():void + { + addNumbers(); + _sut.removeItemAt(1); + assertEquals("First element not correct", 1, _sut[0]); + assertEquals("Length is not one", 1, _sut.length); + _sut.removeItemAt(0); + assertEquals("Length is not zero", 0, _sut.length); + } + + [Test] + public function removeItemByIndex():void + { + addNumbers(); + _sut.removeItemAt(_sut.getItemIndex(1)); + assertEquals("First element not correct", 2, _sut[0]); + assertEquals("Length is not one", 1, _sut.length); + _sut.removeItemAt(_sut.getItemIndex(2)); + assertEquals("Length is not zero", 0, _sut.length); + } + + [Test] + public function outOfRange():void + { + addNumbers(); + try { + _sut.removeItemAt(-1); + } + catch (error:Error) + { + assertTrue("Error not range error", error is RangeError); + } + assertEquals("Length is not two", 2, _sut.length); + try { + _sut.removeItemAt(10); + } + catch (error:Error) + { + assertTrue("Error not range error", error is RangeError); + } + assertEquals("Length is not two", 2, _sut.length); + } + + [Test] + public function swapItemsTwoThenOne():void + { + addNumbers(); + + var item1:Number = _sut.getItemAt(0) as Number; + var item2:Number = _sut.getItemAt(1) as Number; + + _sut.setItemAt(item2,0); + _sut.setItemAt(item1,1); + + assertEquals("Length is not two", 2, _sut.length); + assertEquals("First element not correct", 2, _sut[0]); + assertEquals("Second element not correct", 1, _sut[1]); + } + + [Test] + public function swapItemsOneThenTwo():void + { + addNumbers(); + + var item1:Number = _sut.getItemAt(0) as Number; + var item2:Number = _sut.getItemAt(1) as Number; + + _sut.setItemAt(item1,1); + _sut.setItemAt(item2,0); + + assertEquals("Length is not two", 2, _sut.length); + assertEquals("First element not correct", 2, _sut[0]); + assertEquals("Second element not correct", 1, _sut[1]); + } + + } +} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/flex-sdk/blob/81643dd1/frameworks/projects/framework/tests/mx/collections/ArrayCollection_AddRemoveObjects_Tests.as ---------------------------------------------------------------------- diff --git a/frameworks/projects/framework/tests/mx/collections/ArrayCollection_AddRemoveObjects_Tests.as b/frameworks/projects/framework/tests/mx/collections/ArrayCollection_AddRemoveObjects_Tests.as new file mode 100644 index 0000000..a6ae79d --- /dev/null +++ b/frameworks/projects/framework/tests/mx/collections/ArrayCollection_AddRemoveObjects_Tests.as @@ -0,0 +1,274 @@ +//////////////////////////////////////////////////////////////////////////////// +// +// 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.collections { + import org.flexunit.asserts.*; + + public class ArrayCollection_AddRemoveObjects_Tests + { + private var _sut:ArrayCollection; + + protected var players:Array = [ + {team:"TeamOne",jerseyNumber:80,lastName:"PlayerA",firstName:"Aa"}, + {team:"TeamTwo",jerseyNumber:7, lastName:"PlayerB",firstName:"Bb"}, + {team:"TeamOne",jerseyNumber:12, lastName:"PlayerC",firstName:"Cc"}, + {team:"TeamOne",jerseyNumber:21,lastName:"PlayerD",firstName:"Dd"}, + {team:"TeamThree",jerseyNumber:34, lastName:"PlayerE",firstName:"Ee"}, + {team:"TeamOne",jerseyNumber:12, lastName:"PlayerF",firstName:"Ff"}, + {team:"TeamTwo",jerseyNumber:7, lastName:"PlayerG",firstName:"Gg"} + ]; + + [Before] + public function setUp():void + { + _sut = new ArrayCollection(); + } + + [After] + public function tearDown():void + { + _sut = null; + } + + [Test] + public function empty():void + { + assertEquals(_sut.length, 0); + } + + [Test] + public function addObjects():void + { + _sut = new ArrayCollection(players); + assertEquals("Length is not seven", 7, _sut.length); + assertEquals("First element not correct", players[0], _sut[0]); + assertEquals("Second element not correct", players[1], _sut[1]); + assertEquals("Third element not correct", players[2], _sut[2]); + assertEquals("Fouth element not correct", players[3], _sut[3]); + assertEquals("Fifth element not correct", players[4], _sut[4]); + assertEquals("Sixth element not correct", players[5], _sut[5]); + assertEquals("Seventh element not correct", players[6], _sut[6]); + } + + [Test] + public function addDuplicate():void + { + addObjects(); + _sut.addItem(players[0]); + assertEquals("Length is not eight", 8, _sut.length); + assertEquals("First element not correct", players[0], _sut[0]); + assertEquals("Second element not correct", players[1], _sut[1]); + assertEquals("Third element not correct", players[2], _sut[2]); + assertEquals("Fouth element not correct", players[3], _sut[3]); + assertEquals("Fifth element not correct", players[4], _sut[4]); + assertEquals("Sixth element not correct", players[5], _sut[5]); + assertEquals("Seventh element not correct", players[6], _sut[6]); + assertEquals("Eighth element not correct", players[0], _sut[7]); + } + + [Test] + public function removeDuplicate():void + { + //given + addObjects(); + var firstPlayer:* = players[0]; + var secondPlayer:* = players[1]; + var thirdPlayer:* = players[2]; + var fourthPlayer:* = players[3]; + var fifthPlayer:* = players[4]; + var sixthPlayer:* = players[5]; + var seventhPlayer:* = players[6]; + + //when + _sut.addItem(players[0]); + _sut.removeItemAt(0); + //then + assertEquals("Length is not seven", 7, _sut.length); + assertEquals("First element not correct", secondPlayer, _sut[0]); + assertEquals("Second element not correct", thirdPlayer, _sut[1]); + assertEquals("Third element not correct", fourthPlayer, _sut[2]); + assertEquals("Fourth element not correct", fifthPlayer, _sut[3]); + assertEquals("Fifth element not correct", sixthPlayer, _sut[4]); + assertEquals("Sixth element not correct", seventhPlayer, _sut[5]); + assertEquals("Seventh element not correct", firstPlayer, _sut[6]); + } + + [Test] + public function removeAllObjects():void + { + addObjects(); + _sut.removeAll(); + assertEquals("Length is not zero", 0, _sut.length); + } + + [Test] + public function removeFirstObjects():void + { + //given + addObjects(); + var secondPlayer:Object = players[1]; + + //when + _sut.removeItemAt(0); + + //then + assertEquals("First element not correct", secondPlayer, _sut[0]); + assertEquals("Length is not six", 6, _sut.length); + + //when + _sut.removeItemAt(0); + //then + assertEquals("Length is not five", 5, _sut.length); + + //when + _sut.removeItemAt(0); + //then + assertEquals("Length is not four", 4, _sut.length); + + //when + _sut.removeItemAt(0); + //then + assertEquals("Length is not three", 3, _sut.length); + + //when + _sut.removeItemAt(0); + //then + assertEquals("Length is not two", 2, _sut.length); + + //when + _sut.removeItemAt(0); + //then + assertEquals("Length is not one", 1, _sut.length); + + //when + _sut.removeItemAt(0); + //then + assertEquals("Length is not zero", 0, _sut.length); + } + + [Test] + public function removeLastNumbers():void + { + addObjects(); + _sut.removeItemAt(6); + assertEquals("First element not correct", players[0], _sut[0]); + assertEquals("Length is not six", 6, _sut.length); + _sut.removeItemAt(0); + assertEquals("Length is not five", 5, _sut.length); + _sut.removeItemAt(0); + assertEquals("Length is not four", 4, _sut.length); + _sut.removeItemAt(0); + assertEquals("Length is not three", 3, _sut.length); + _sut.removeItemAt(0); + assertEquals("Length is not two", 2, _sut.length); + _sut.removeItemAt(0); + assertEquals("Length is not one", 1, _sut.length); + _sut.removeItemAt(0); + assertEquals("Length is not zero", 0, _sut.length); + } + + [Test] + public function removeItemByIndex():void + { + //given + addObjects(); + const secondPlayer:Object = players[1]; + const thirdPlayer:Object = players[2]; + const fourthPlayer:Object = players[3]; + + //when + _sut.removeItemAt(_sut.getItemIndex(players[0])); + + //then + assertEquals("First element incorrect", secondPlayer, _sut[0]); + assertEquals("Length is not six", 6, _sut.length); + + //when + _sut.removeItemAt(_sut.getItemIndex(thirdPlayer)); + + //then + assertEquals("First element not correct", secondPlayer, _sut[0]); + assertEquals("Second element not correct", fourthPlayer, _sut[1]); + assertEquals("Length is not four", 5, _sut.length); + } + + [Test] + public function outOfRange():void + { + addObjects(); + try { + _sut.removeItemAt(-1); + } + catch (error:Error) + { + assertTrue("Error not range error", error is RangeError); + } + assertEquals("Length is not seven", 7, _sut.length); + try { + _sut.removeItemAt(10); + } + catch (error:Error) + { + assertTrue("Error not range error", error is RangeError); + } + assertEquals("Length is not seven", 7, _sut.length); + } + + [Test] + public function swapItemsTwoThenOne():void + { + //given + addObjects(); + var item1:Object = _sut.getItemAt(0); + var item2:Object = _sut.getItemAt(1); + var firstPlayer:* = players[0]; + var secondPlayer:* = players[1]; + + //when + _sut.setItemAt(item2,0); + _sut.setItemAt(item1,1); + + //then + assertEquals("Length is not seven", 7, _sut.length); + assertEquals("First element not correct", secondPlayer, _sut[0]); + assertEquals("Second element not correct", firstPlayer, _sut[1]); + } + + [Test] + public function swapItemsOneThenTwo():void + { + //given + addObjects(); + var item1:Object = _sut.getItemAt(0); + var item2:Object = _sut.getItemAt(1); + var secondPlayer:Object = players[1]; + var firstPlayer:Object = players[0]; + + //when + _sut.setItemAt(item1,1); + _sut.setItemAt(item2,0); + + //then + assertEquals("Length is not seven", 7, _sut.length); + assertEquals("First element not correct", secondPlayer, _sut[0]); + assertEquals("Second element not correct", firstPlayer, _sut[1]); + + } + + } +} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/flex-sdk/blob/81643dd1/frameworks/projects/framework/tests/mx/collections/ArrayCollection_AddRemoveStrings_Tests.as ---------------------------------------------------------------------- diff --git a/frameworks/projects/framework/tests/mx/collections/ArrayCollection_AddRemoveStrings_Tests.as b/frameworks/projects/framework/tests/mx/collections/ArrayCollection_AddRemoveStrings_Tests.as new file mode 100644 index 0000000..0ae1873 --- /dev/null +++ b/frameworks/projects/framework/tests/mx/collections/ArrayCollection_AddRemoveStrings_Tests.as @@ -0,0 +1,200 @@ +//////////////////////////////////////////////////////////////////////////////// +// +// 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.collections { + import org.flexunit.asserts.*; + + public class ArrayCollection_AddRemoveStrings_Tests + { + protected var _sut:ArrayCollection; + + [Before] + public function setUp():void + { + _sut = new ArrayCollection(); + } + + [After] + public function tearDown():void + { + _sut = null; + } + + [Test] + public function empty():void + { + assertEquals(0, _sut.length); + } + + [Test] + public function addStrings():void + { + _sut.addItem("A"); + assertEquals("Length is not one", 1, _sut.length); + assertEquals("First element not correct", "A", _sut[0]); + + _sut.addItem("B"); + assertEquals("Length is not two", 2, _sut.length); + assertEquals("Second element not correct", "B", _sut[1]); + + _sut.addItem("D"); + assertEquals("Length is not three", 3, _sut.length); + assertEquals("Second element not correct", "D", _sut[2]); + + _sut.addItem("C"); + assertEquals("Length is not four", 4, _sut.length); + assertEquals("Second element not correct", "C", _sut[3]); + } + + [Test] + public function addDuplicate():void + { + //given + addStrings(); + + //when + _sut.addItem("B"); + + //then + assertEquals("Length is not five", 5, _sut.length); + assertEquals("First element not correct", "A", _sut[0]); + assertEquals("Second element not correct", "B", _sut[1]); + assertEquals("Second element not correct", "D", _sut[2]); + assertEquals("Second element not correct", "C", _sut[3]); + assertEquals("Second element not correct", "B", _sut[4]); + } + + [Test] + public function removeDuplicate():void + { + //given + addStrings(); + + //when + _sut.addItem("B"); + _sut.removeItemAt(1); + + //then + assertEquals("Length is not four", 4, _sut.length); + assertEquals("First element not correct", "A", _sut[0]); + assertEquals("Second element not correct", "D", _sut[1]); + assertEquals("Second element not correct", "C", _sut[2]); + assertEquals("Second element not correct", "B", _sut[3]); + } + + [Test] + public function removeAllStrings():void + { + addStrings(); + _sut.removeAll(); + assertEquals("Length is not zero", 0, _sut.length); + } + + [Test] + public function removeFirstStrings():void + { + addStrings(); + _sut.removeItemAt(0); + assertEquals("First element not correct", "B", _sut[0]); + assertEquals("Length is not three", 3, _sut.length); + _sut.removeItemAt(0); + assertEquals("Length is not two", 2, _sut.length); + } + + [Test] + public function removeLastStrings():void + { + addStrings(); + _sut.removeItemAt(1); + assertEquals("First element not correct", "A", _sut[0]); + assertEquals("Length is not three", 3, _sut.length); + _sut.removeItemAt(0); + assertEquals("Length is not two", 2, _sut.length); + } + + [Test] + public function removeItemByIndex():void + { + addStrings(); + _sut.removeItemAt(_sut.getItemIndex("B")); + assertEquals("First element not correct", "A", _sut[0]); + assertEquals("Length is not three", 3, _sut.length); + _sut.removeItemAt(_sut.getItemIndex("D")); + assertEquals("Length is not two", 2, _sut.length); + } + + [Test] + public function outOfRange():void + { + addStrings(); + try { + _sut.removeItemAt(-1); + } + catch (error:Error) + { + assertTrue("Error not range error", error is RangeError); + } + assertEquals("Length is not four", 4, _sut.length); + try { + _sut.removeItemAt(10); + } + catch (error:Error) + { + assertTrue("Error not range error", error is RangeError); + } + assertEquals("Length is not two", 4, _sut.length); + } + + [Test] + public function swapItemsTwoThenOne():void + { + //given + addStrings(); + var item1:String = _sut.getItemAt(0) as String; + var item2:String = _sut.getItemAt(1) as String; + + //when + _sut.setItemAt(item2, 0); + _sut.setItemAt(item1, 1); + + //then + assertEquals("Length is not four", 4, _sut.length); + assertEquals("First element not correct", "B", _sut[0]); + assertEquals("Second element not correct", "A", _sut[1]); + } + + [Test] + public function swapItemsOneThenTwo():void + { + //given + addStrings(); + var item1:String = _sut.getItemAt(0) as String; + var item2:String = _sut.getItemAt(1) as String; + + //when + _sut.setItemAt(item1, 1); + _sut.setItemAt(item2, 0); + + //then + assertEquals("Length is not four", 4, _sut.length); + assertEquals("First element not correct", "B", _sut[0]); + assertEquals("Second element not correct", "A", _sut[1]); + } + + } +} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/flex-sdk/blob/81643dd1/frameworks/projects/framework/tests/mx/collections/ArrayCollection_FilerAndSortNumbers_Tests.as ---------------------------------------------------------------------- diff --git a/frameworks/projects/framework/tests/mx/collections/ArrayCollection_FilerAndSortNumbers_Tests.as b/frameworks/projects/framework/tests/mx/collections/ArrayCollection_FilerAndSortNumbers_Tests.as new file mode 100644 index 0000000..18ac40d --- /dev/null +++ b/frameworks/projects/framework/tests/mx/collections/ArrayCollection_FilerAndSortNumbers_Tests.as @@ -0,0 +1,114 @@ +//////////////////////////////////////////////////////////////////////////////// +// +// 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.collections { + import org.flexunit.asserts.*; + + public class ArrayCollection_FilerAndSortNumbers_Tests + { + private var _sut:ArrayCollection; + + [Before] + public function setUp():void + { + _sut = new ArrayCollection(); + } + + [After] + public function tearDown():void + { + _sut = null; + } + + + protected function addNumbers():void + { + _sut.addItem(6); + _sut.addItem(2); + _sut.addItem(3); + _sut.addItem(1); + _sut.addItem(5); + _sut.addItem(4); + } + + protected function even(object:Object):Boolean + { + return Number(object) % 2 == 0; + } + + protected function odd(object:Object):Boolean + { + return Number(object) % 2 == 1; + } + + [Test] + public function filterAndSortCombinations():void + { + addNumbers(); + _sut.filterFunction = even; + _sut.sort = new Sort(); + _sut.refresh(); + + assertEquals("Length is not three", 3, _sut.length); + assertEquals("First element not correct", 2, _sut[0]); + assertEquals("Second element not correct", 4, _sut[1]); + assertEquals("Third element not correct", 6, _sut[2]); + + _sut.filterFunction = odd; + _sut.refresh(); + + assertEquals("Length is not three", 3, _sut.length); + assertEquals("First element not correct", 1, _sut[0]); + assertEquals("Second element not correct", 3, _sut[1]); + assertEquals("Third element not correct", 5, _sut[2]); + + _sut.sort = new Sort(); + _sut.sort.fields = [new SortField(null, false, true, true)]; + _sut.refresh(); + + assertEquals("Length is not three", 3, _sut.length); + assertEquals("First element not correct", 5, _sut[0]); + assertEquals("Second element not correct", 3, _sut[1]); + assertEquals("Third element not correct", 1, _sut[2]); + + _sut.filterFunction = null; + _sut.refresh(); + + assertEquals("Length is not six", 6, _sut.length); + assertEquals("First element not correct", 6, _sut[0]); + assertEquals("Second element not correct", 5, _sut[1]); + assertEquals("Third element not correct", 4, _sut[2]); + assertEquals("Fourth element not correct", 3, _sut[3]); + assertEquals("Fith element not correct", 2, _sut[4]); + assertEquals("Six element not correct", 1, _sut[5]); + + _sut.sort = null; + _sut.refresh(); + + assertEquals("Length is not six", 6, _sut.length); + assertEquals("First element not correct", 6, _sut[0]); + assertEquals("Second element not correct", 2, _sut[1]); + assertEquals("Third element not correct", 3, _sut[2]); + assertEquals("Fourth element not correct", 1, _sut[3]); + assertEquals("Fith element not correct", 5, _sut[4]); + assertEquals("Six element not correct", 4, _sut[5]); + } + + + } +} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/flex-sdk/blob/81643dd1/frameworks/projects/framework/tests/mx/collections/ArrayCollection_FilerAndSortStrings_Tests.as ---------------------------------------------------------------------- diff --git a/frameworks/projects/framework/tests/mx/collections/ArrayCollection_FilerAndSortStrings_Tests.as b/frameworks/projects/framework/tests/mx/collections/ArrayCollection_FilerAndSortStrings_Tests.as new file mode 100644 index 0000000..c4e4a2c --- /dev/null +++ b/frameworks/projects/framework/tests/mx/collections/ArrayCollection_FilerAndSortStrings_Tests.as @@ -0,0 +1,114 @@ +//////////////////////////////////////////////////////////////////////////////// +// +// 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.collections { + import org.flexunit.asserts.*; + + public class ArrayCollection_FilerAndSortStrings_Tests + { + private var _sut:ArrayCollection; + + [Before] + public function setUp():void + { + _sut = new ArrayCollection(); + } + + [After] + public function tearDown():void + { + _sut = null; + } + + + protected function addNumbers():void + { + _sut.addItem(6); + _sut.addItem(2); + _sut.addItem(3); + _sut.addItem(1); + _sut.addItem(5); + _sut.addItem(4); + } + + protected function even(object:Object):Boolean + { + return Number(object) % 2 == 0; + } + + protected function odd(object:Object):Boolean + { + return Number(object) % 2 == 1; + } + + [Test] + public function filterAndSortCombinations():void + { + addNumbers(); + _sut.filterFunction = even; + _sut.sort = new Sort(); + _sut.refresh(); + + assertEquals("Length is not three", 3, _sut.length); + assertEquals("First element not correct", 2, _sut[0]); + assertEquals("Second element not correct", 4, _sut[1]); + assertEquals("Third element not correct", 6, _sut[2]); + + _sut.filterFunction = odd; + _sut.refresh(); + + assertEquals("Length is not three", 3, _sut.length); + assertEquals("First element not correct", 1, _sut[0]); + assertEquals("Second element not correct", 3, _sut[1]); + assertEquals("Third element not correct", 5, _sut[2]); + + _sut.sort = new Sort(); + _sut.sort.fields = [new SortField(null, false, true, true)]; + _sut.refresh(); + + assertEquals("Length is not three", 3, _sut.length); + assertEquals("First element not correct", 5, _sut[0]); + assertEquals("Second element not correct", 3, _sut[1]); + assertEquals("Third element not correct", 1, _sut[2]); + + _sut.filterFunction = null; + _sut.refresh(); + + assertEquals("Length is not six", 6, _sut.length); + assertEquals("First element not correct", 6, _sut[0]); + assertEquals("Second element not correct", 5, _sut[1]); + assertEquals("Third element not correct", 4, _sut[2]); + assertEquals("Fourth element not correct", 3, _sut[3]); + assertEquals("Fith element not correct", 2, _sut[4]); + assertEquals("Six element not correct", 1, _sut[5]); + + _sut.sort = null; + _sut.refresh(); + + assertEquals("Length is not six", 6, _sut.length); + assertEquals("First element not correct", 6, _sut[0]); + assertEquals("Second element not correct", 2, _sut[1]); + assertEquals("Third element not correct", 3, _sut[2]); + assertEquals("Fourth element not correct", 1, _sut[3]); + assertEquals("Fith element not correct", 5, _sut[4]); + assertEquals("Six element not correct", 4, _sut[5]); + } + + + } +} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/flex-sdk/blob/81643dd1/frameworks/projects/framework/tests/mx/collections/ArrayCollection_FilterNumbers_Tests.as ---------------------------------------------------------------------- diff --git a/frameworks/projects/framework/tests/mx/collections/ArrayCollection_FilterNumbers_Tests.as b/frameworks/projects/framework/tests/mx/collections/ArrayCollection_FilterNumbers_Tests.as new file mode 100644 index 0000000..9662b6d --- /dev/null +++ b/frameworks/projects/framework/tests/mx/collections/ArrayCollection_FilterNumbers_Tests.as @@ -0,0 +1,315 @@ +//////////////////////////////////////////////////////////////////////////////// +// +// 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.collections { + import org.flexunit.asserts.*; + + public class ArrayCollection_FilterNumbers_Tests + { + private var _sut:ArrayCollection; + + [Before] + public function setUp():void + { + _sut = new ArrayCollection(); + } + + [After] + public function tearDown():void + { + _sut = null; + } + + protected function addNumbers():void + { + _sut.addItem(1); + _sut.addItem(2); + } + + protected function allIn(object:Object):Boolean + { + return true; + } + + protected function allOut(object:Object):Boolean + { + return false; + } + + protected function isOne(object:Object):Boolean + { + return object == 1; + } + + [Test] + public function nullFilter():void + { + addNumbers(); + _sut.filterFunction = null; + _sut.refresh(); + + assertEquals("Length is not two", 2, _sut.length); + assertEquals("First element not correct", 1, _sut[0]); + assertEquals("Second element not correct", 2, _sut[1]); + } + + [Test] + public function trueFilter():void + { + addNumbers(); + _sut.filterFunction = allIn; + _sut.refresh(); + + assertEquals("Length is not two", 2, _sut.length); + assertEquals("First element not correct", 1, _sut[0]); + assertEquals("Second element not correct", 2, _sut[1]); + } + + [Test] + public function falseFilter():void + { + addNumbers(); + _sut.filterFunction = allOut; + _sut.refresh(); + + assertEquals("Length is not two", 0, _sut.length); + } + + + [Test] + public function filterNoRefresh():void + { + addNumbers(); + _sut.filterFunction = allOut; + + // Filter should not take effect + assertEquals("Length is not two", 2, _sut.length); + assertEquals("First element not correct", 1, _sut[0]); + assertEquals("Second element not correct", 2, _sut[1]); + } + + [Test] + public function nullFilterNoRefresh():void + { + addNumbers(); + _sut.filterFunction = null; + + // Filter should not take effect + assertEquals("Length is not two", 2, _sut.length); + assertEquals("First element not correct", 1, _sut[0]); + assertEquals("Second element not correct", 2, _sut[1]); + } + + [Test] + public function filterDoubleRefresh():void + { + addNumbers(); + _sut.filterFunction = allOut; + _sut.refresh(); + + assertEquals("Length is not zero", 0, _sut.length); + + _sut.filterFunction = null; + _sut.refresh(); + + // Filter should not take effect + assertEquals("Length is not two", 2, _sut.length); + assertEquals("First element not correct", 1, _sut[0]); + assertEquals("Second element not correct", 2, _sut[1]); + } + + // RTEs in Apache Flex 4.9.1 + [Test] + public function filterAddAfterNullNoRefresh():void + { + addNumbers(); + + _sut.filterFunction = allOut; + _sut.refresh(); + + assertEquals("Length is not zero", 0, _sut.length); + + _sut.filterFunction = null; + addNumbers(); + + // Filter should be in effect and first 2 items sorted + // item added after are not filtered until refresh called + assertEquals("Length is not two", 2, _sut.length); + assertEquals("First element not correct", 1, _sut[0]); + assertEquals("Second element not correct", 2, _sut[1]); + + _sut.refresh(); + assertEquals("Length is not four", 4, _sut.length); + assertEquals("First element not correct", 1, _sut[0]); + assertEquals("Second element not correct", 2, _sut[1]); + assertEquals("First element not correct", 1, _sut[2]); + assertEquals("Second element not correct", 2, _sut[3]); + } + + [Test] + public function filterRemoveAfterNullNoRefresh():void + { + addNumbers(); + + _sut.filterFunction = allOut; + _sut.refresh(); + _sut.filterFunction = null; + + assertEquals("Length is not zero", 0, _sut.length); + + try { + _sut.removeItemAt(0); + } + catch (error:Error) + { + assertTrue("Error not range error", error is RangeError); + } + + assertEquals("Length is not zero", 0, _sut.length); + + _sut.refresh(); + assertEquals("Length is not two", 2, _sut.length); + } + + [Test] + public function filterIncludingDuplicates():void + { + addNumbers(); + addNumbers(); + + _sut.filterFunction = isOne; + _sut.refresh(); + + assertEquals("Length is not two", 2, _sut.length); + + assertEquals("First element not correct", 1, _sut[0]); + assertEquals("Second element not correct", 1, _sut[1]); + } + + // Fails in Apache Flex 4.9.1 + [Test] + public function swapItemsTwoThenOne():void + { + //given + addNumbers(); + _sut.filterFunction = allIn; + _sut.refresh(); + + var item1:Number = _sut.getItemAt(0) as Number; + var item2:Number = _sut.getItemAt(1) as Number; + + //when + _sut.setItemAt(item2, 0); + _sut.setItemAt(item1, 1); + + //then + assertEquals("Length is not two", 2, _sut.length); + assertEquals("First element not correct", 2, _sut[0]); + assertEquals("Second element not correct", 1, _sut[1]); + } + + [Test] + public function swapItemsOneThenTwo():void + { + addNumbers(); + _sut.filterFunction = allIn; + _sut.refresh(); + + var item1:Number = _sut.getItemAt(0) as Number; + var item2:Number = _sut.getItemAt(1) as Number; + + _sut.setItemAt(item1,1); + _sut.setItemAt(item2,0); + + assertEquals("Length is not two", 2, _sut.length); + assertEquals("First element not correct", 2, _sut[0]); + assertEquals("Second element not correct", 1, _sut[1]); + } + + [Test] + public function removeAllAfterFiltered():void + { + addNumbers(); + _sut.filterFunction = allOut; + _sut.refresh(); + + assertEquals("Length is not two", 0, _sut.length); + + _sut.removeAll(); + + assertEquals("Length is not two", 0, _sut.length); + + _sut.filterFunction = null; + _sut.refresh(); + + assertEquals("Length is not two", 2, _sut.length); + assertEquals("First element not correct", 1, _sut[0]); + assertEquals("Second element not correct", 2, _sut[1]); + } + + [Test] + public function removeFilteredItem():void + { + addNumbers(); + _sut.filterFunction = isOne; + _sut.refresh(); + + assertEquals("Length is not one", 1, _sut.length); + + _sut.removeItemAt(_sut.getItemIndex(1)); + + assertEquals("Length is not zero", 0, _sut.length); + + _sut.filterFunction = null; + _sut.refresh(); + + assertEquals("Length is not two", 1, _sut.length); + assertEquals("First element not correct", 2, _sut[0]); + } + + [Test] + public function removeNonFilteredItem():void + { + addNumbers(); + _sut.filterFunction = isOne; + _sut.refresh(); + + assertEquals("Length is not one", 1, _sut.length); + + try { + // not removed as filter hids it - perhaps it should be removed? + _sut.removeItemAt(_sut.getItemIndex(2)); + } + catch (error:Error) + { + assertTrue("Error not range error", error is RangeError); + } + + assertEquals("Length is not one", 1, _sut.length); + + _sut.filterFunction = null; + _sut.refresh(); + + assertEquals("Length is not two", 2, _sut.length); + assertEquals("First element not correct", 1, _sut[0]); + assertEquals("First element not correct", 2, _sut[1]); + } + + + } +} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/flex-sdk/blob/81643dd1/frameworks/projects/framework/tests/mx/collections/ArrayCollection_FilterStrings_Tests.as ---------------------------------------------------------------------- diff --git a/frameworks/projects/framework/tests/mx/collections/ArrayCollection_FilterStrings_Tests.as b/frameworks/projects/framework/tests/mx/collections/ArrayCollection_FilterStrings_Tests.as new file mode 100644 index 0000000..2d764dc --- /dev/null +++ b/frameworks/projects/framework/tests/mx/collections/ArrayCollection_FilterStrings_Tests.as @@ -0,0 +1,341 @@ +//////////////////////////////////////////////////////////////////////////////// +// +// 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.collections { + import org.flexunit.asserts.*; + + public class ArrayCollection_FilterStrings_Tests + { + private var _sut:ArrayCollection; + + [Before] + public function setUp():void + { + _sut = new ArrayCollection(); + } + + [After] + public function tearDown():void + { + _sut = null; + } + + protected function addStrings():void + { + _sut.addItem("A"); + _sut.addItem("B"); + _sut.addItem("D"); + _sut.addItem("C"); + } + + protected function allIn(object:Object):Boolean + { + return true; + } + + protected function allOut(object:Object):Boolean + { + return false; + } + + protected function isA(object:Object):Boolean + { + return object == "A"; + } + + [Test] + public function nullFilter():void + { + addStrings(); + _sut.filterFunction = null; + _sut.refresh(); + + assertEquals("Length is not four", 4, _sut.length); + assertEquals("First element not correct", "A", _sut[0]); + assertEquals("Second element not correct", "B", _sut[1]); + assertEquals("Third element not correct", "D", _sut[2]); + assertEquals("Four element not correct", "C", _sut[3]); + } + + [Test] + public function trueFilter():void + { + addStrings(); + _sut.filterFunction = allIn; + _sut.refresh(); + + assertEquals("Length is not four", 4, _sut.length); + assertEquals("First element not correct", "A", _sut[0]); + assertEquals("Second element not correct", "B", _sut[1]); + assertEquals("Third element not correct", "D", _sut[2]); + assertEquals("Four element not correct", "C", _sut[3]); + } + + [Test] + public function falseFilter():void + { + addStrings(); + _sut.filterFunction = allOut; + _sut.refresh(); + + assertEquals("Length is not zero", 0, _sut.length); + } + + + [Test] + public function filterNoRefresh():void + { + addStrings(); + _sut.filterFunction = allOut; + + // Filter should not take effect + assertEquals("Length is not four", 4, _sut.length); + assertEquals("First element not correct", "A", _sut[0]); + assertEquals("Second element not correct", "B", _sut[1]); + assertEquals("Third element not correct", "D", _sut[2]); + assertEquals("Four element not correct", "C", _sut[3]); + } + + [Test] + public function nullFilterNoRefresh():void + { + addStrings(); + _sut.filterFunction = null; + + // Filter should not take effect + assertEquals("Length is not four", 4, _sut.length); + assertEquals("First element not correct", "A", _sut[0]); + assertEquals("Second element not correct", "B", _sut[1]); + assertEquals("Third element not correct", "D", _sut[2]); + assertEquals("Four element not correct", "C", _sut[3]); + } + + [Test] + public function filterDoubleRefresh():void + { + addStrings(); + _sut.filterFunction = allOut; + _sut.refresh(); + + assertEquals("Length is not zero", 0, _sut.length); + + _sut.filterFunction = null; + _sut.refresh(); + + // Filter should not take effect + assertEquals("Length is not four", 4, _sut.length); + assertEquals("First element not correct", "A", _sut[0]); + assertEquals("Second element not correct", "B", _sut[1]); + assertEquals("Third element not correct", "D", _sut[2]); + assertEquals("Four element not correct", "C", _sut[3]); + } + + // RTEs in Apache Flex 4.9.1 + [Test] + public function filterAddAfterNullNoRefresh():void + { + addStrings(); + + _sut.filterFunction = allOut; + _sut.refresh(); + + assertEquals("Length is not zero", 0, _sut.length); + + _sut.filterFunction = null; + addStrings(); + + // Filter should be in effect and first 2 items sorted + // item added after are not filtered until refresh called + assertEquals("Length is not four", 4, _sut.length); + assertEquals("First element not correct", "A", _sut[0]); + assertEquals("Second element not correct", "B", _sut[1]); + assertEquals("Third element not correct", "D", _sut[2]); + assertEquals("Four element not correct", "C", _sut[3]); + + _sut.refresh(); + assertEquals("Length is not eight", 8, _sut.length); + assertEquals("First element not correct", "A", _sut[0]); + assertEquals("Second element not correct", "B", _sut[1]); + assertEquals("Third element not correct", "D", _sut[2]); + assertEquals("Four element not correct", "C", _sut[3]); + assertEquals("First element not correct", "A", _sut[4]); + assertEquals("Second element not correct", "B", _sut[5]); + assertEquals("Third element not correct", "D", _sut[6]); + assertEquals("Four element not correct", "C", _sut[7]); + } + + [Test] + public function filterRemoveAfterNullNoRefresh():void + { + addStrings(); + + _sut.filterFunction = allOut; + _sut.refresh(); + _sut.filterFunction = null; + + assertEquals("Length is not zero", 0, _sut.length); + + try { + _sut.removeItemAt(0); + } + catch (error:Error) + { + assertTrue("Error not range error", error is RangeError); + } + + assertEquals("Length is not zero", 0, _sut.length); + + _sut.refresh(); + assertEquals("Length is not four", 4, _sut.length); + } + + [Test] + public function filterIncludingDuplicates():void + { + addStrings(); + addStrings(); + + _sut.filterFunction = isA; + _sut.refresh(); + + assertEquals("Length is not two", 2, _sut.length); + + assertEquals("First element not correct", "A", _sut[0]); + assertEquals("Second element not correct", "A", _sut[1]); + } + + // Fails in Apache Flex 4.9.1 + [Test] + public function swapItemsTwoThenOne():void + { + //given + addStrings(); + _sut.filterFunction = allIn; + _sut.refresh(); + + var item1:String = _sut.getItemAt(0) as String; + var item2:String = _sut.getItemAt(1) as String; + + //when + _sut.setItemAt(item2,0); + _sut.setItemAt(item1,1); + + //then + assertEquals("Length is not four", 4, _sut.length); + assertEquals("First element not correct", _sut[0], "B"); + assertEquals("Second element not correct", _sut[1], "A"); + assertEquals("Third element not correct", _sut[2], "D"); + assertEquals("Four element not correct", _sut[3], "C"); + } + + [Test] + public function swapItemsOneThenTwo():void + { + addStrings(); + _sut.filterFunction = allIn; + _sut.refresh(); + + var item1:String = _sut.getItemAt(0) as String; + var item2:String = _sut.getItemAt(1) as String; + + _sut.setItemAt(item1,1); + _sut.setItemAt(item2,0); + + assertEquals("Length is not four", 4, _sut.length); + assertEquals("First element not correct", "B", _sut[0]); + assertEquals("Second element not correct", "A", _sut[1]); + assertEquals("Third element not correct", "D", _sut[2]); + assertEquals("Four element not correct", "C", _sut[3]); + } + + [Test] + public function removeAllAfterFiltered():void + { + addStrings(); + _sut.filterFunction = allOut; + _sut.refresh(); + + assertEquals("Length is not two", 0, _sut.length); + + _sut.removeAll(); + + assertEquals("Length is not two", 0, _sut.length); + + _sut.filterFunction = null; + _sut.refresh(); + + assertEquals("Length is not four", 4, _sut.length); + assertEquals("First element not correct", "A", _sut[0]); + assertEquals("Second element not correct", "B", _sut[1]); + assertEquals("Third element not correct", "D", _sut[2]); + assertEquals("Four element not correct", "C", _sut[3]); + } + + [Test] + public function removeFilteredItem():void + { + addStrings(); + _sut.filterFunction = isA; + _sut.refresh(); + + assertEquals("Length is not one", 1, _sut.length); + + _sut.removeItemAt(_sut.getItemIndex("A")); + + assertEquals("Length is not zero", 0, _sut.length); + + _sut.filterFunction = null; + _sut.refresh(); + + assertEquals("Length is not three", 3, _sut.length); + assertEquals("First element not correct", "B", _sut[0]); + } + + [Test] + public function removeNonFilteredItem():void + { + addStrings(); + _sut.filterFunction = isA; + _sut.refresh(); + + assertEquals("Length is not one", 1, _sut.length); + + try { + // not removed as filter hids it - perhaps it should be removed? + _sut.removeItemAt(_sut.getItemIndex("B")); + } + catch (error:Error) + { + assertTrue("Error not range error", error is RangeError); + } + + assertEquals("Length is not one", 1, _sut.length); + + _sut.filterFunction = null; + _sut.refresh(); + + assertEquals("Length is not four", 4, _sut.length); + assertEquals("First element not correct", "A", _sut[0]); + assertEquals("Second element not correct", "B", _sut[1]); + assertEquals("Third element not correct", "D", _sut[2]); + assertEquals("Four element not correct", "C", _sut[3]); + } + + + } +} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/flex-sdk/blob/81643dd1/frameworks/projects/framework/tests/mx/collections/ArrayCollection_SortNumbers_Tests.as ---------------------------------------------------------------------- diff --git a/frameworks/projects/framework/tests/mx/collections/ArrayCollection_SortNumbers_Tests.as b/frameworks/projects/framework/tests/mx/collections/ArrayCollection_SortNumbers_Tests.as new file mode 100644 index 0000000..85f800e --- /dev/null +++ b/frameworks/projects/framework/tests/mx/collections/ArrayCollection_SortNumbers_Tests.as @@ -0,0 +1,212 @@ +//////////////////////////////////////////////////////////////////////////////// +// +// 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.collections { + import org.flexunit.asserts.*; + + public class ArrayCollection_SortNumbers_Tests + { + private var _sut:ArrayCollection; + + [Before] + public function setUp():void + { + _sut = new ArrayCollection(); + } + + [After] + public function tearDown():void + { + _sut = null; + } + + protected function addNumbers():void + { + _sut.addItem(1); + _sut.addItem(2); + } + + [Test] + public function nullSort():void + { + addNumbers(); + _sut.sort = null; + _sut.refresh(); + + assertEquals("Length is not two", 2, _sut.length); + assertEquals("First element not correct", 1, _sut[0]); + assertEquals("Second element not correct", 2, _sut[1]); + } + + [Test] + public function emptySort():void + { + addNumbers(); + _sut.sort = new Sort(); + _sut.refresh(); + + assertEquals("Length is not two", 2, _sut.length); + assertEquals("First element not correct", 1, _sut[0]); + assertEquals("Second element not correct", 2, _sut[1]); + } + + [Test] + public function reverseSort():void + { + var sort:Sort = new Sort(); + sort.fields = [new SortField(null, false, true, true)]; + addNumbers(); + _sut.sort = sort; + _sut.refresh(); + + assertEquals("Length is not two", 2, _sut.length); + assertEquals("First element not correct", 2, _sut[0]); + assertEquals("Second element not correct", 1, _sut[1]); + } + + [Test] + public function sortNoRefresh():void + { + var sort:Sort = new Sort(); + sort.fields = [new SortField(null, false, true, true)]; + addNumbers(); + _sut.sort = sort; + + // Short should not take effect + assertEquals("Length is not two", 2, _sut.length); + assertEquals("First element not correct", 1, _sut[0]); + assertEquals("Second element not correct", 2, _sut[1]); + } + + [Test] + public function nullSortNoRefresh():void + { + var sort:Sort = new Sort(); + sort.fields = [new SortField(null, false, true, true)]; + addNumbers(); + _sut.sort = sort; + _sut.refresh(); + _sut.sort = null; + + // Sort should be in effect + assertEquals("Length is not two", 2, _sut.length); + assertEquals("First element not correct", 2, _sut[0]); + assertEquals("Second element not correct", 1, _sut[1]); + + _sut.refresh(); + + // and back to original + assertEquals("Length is not two", 2, _sut.length); + assertEquals("First element not correct", 1, _sut[0]); + assertEquals("Second element not correct", 2, _sut[1]); + } + + [Test] + public function sortDoubleRefresh():void + { + var sort:Sort = new Sort(); + sort.fields = [new SortField(null, false, true, true)]; + addNumbers(); + _sut.sort = sort; + _sut.refresh(); + _sut.sort = null; + _sut.refresh(); + + // Sort should not be in effect + assertEquals("Length is not two", 2, _sut.length); + assertEquals("First element not correct", 1, _sut[0]); + assertEquals("Second element not correct", 2, _sut[1]); + } + + // RTEs in APache flex 4.9.1 + [Test] + public function sortAddAfterNullNoRefresh():void + { + addNumbers(); + + var sort:Sort = new Sort(); + sort.fields = [new SortField(null, false, true, true)]; + _sut.sort = sort; + _sut.refresh(); + _sut.sort = null; + addNumbers(); + + // Sort should be in effect and first 2 items sorted + // item added after are not sorted + assertEquals("Length is not four", 4, _sut.length); + assertEquals("First element not correct", 2, _sut[0]); + assertEquals("Second element not correct", 1, _sut[1]); + assertEquals("Third element not correct", 1, _sut[2]); + assertEquals("Fourth element not correct", 2, _sut[3]); + + _sut.refresh(); + + // and back to being unsorted + assertEquals("Length is not four", 4, _sut.length); + assertEquals("First element not correct", 1, _sut[0]); + assertEquals("Second element not correct", 2, _sut[1]); + assertEquals("Third element not correct", 1, _sut[2]); + assertEquals("Fourth element not correct", 2, _sut[3]); + } + + // RTEs in Apache Flex 4.9.1 + [Test] + public function sortRemoveAfterNullNoRefresh():void + { + addNumbers(); + + var sort:Sort = new Sort(); + sort.fields = [new SortField(null, false, true, true)]; + _sut.sort = sort; + _sut.refresh(); + _sut.sort = null; + + assertEquals("Length is not two", 2, _sut.length); + + _sut.removeItemAt(0); // still sorted so 2 is removed leaving 1 + assertEquals("Length is not one", 1, _sut.length); + assertEquals("First element not correct", 1, _sut[0]); + + _sut.refresh(); + + // still the same + assertEquals("Length is not one", 1, _sut.length); + assertEquals("First element not correct", 1, _sut[0]); + } + + [Test] + public function sortIncludingDuplicates():void + { + addNumbers(); + addNumbers(); + + var sort:Sort = new Sort(); + sort.fields = [new SortField(null, false, true, true)]; + _sut.sort = sort; + _sut.refresh(); + + assertEquals("Length is not four", 4, _sut.length); + + assertEquals("First element not correct", 2, _sut[0]); + assertEquals("Second element not correct", 2, _sut[1]); + assertEquals("Third element not correct", 1, _sut[2]); + assertEquals("Fourth element not correct", 1, _sut[3]); + } + + } +} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/flex-sdk/blob/81643dd1/frameworks/projects/framework/tests/mx/collections/ArrayCollection_SortStrings_Tests.as ---------------------------------------------------------------------- diff --git a/frameworks/projects/framework/tests/mx/collections/ArrayCollection_SortStrings_Tests.as b/frameworks/projects/framework/tests/mx/collections/ArrayCollection_SortStrings_Tests.as new file mode 100644 index 0000000..3f49d52 --- /dev/null +++ b/frameworks/projects/framework/tests/mx/collections/ArrayCollection_SortStrings_Tests.as @@ -0,0 +1,254 @@ +//////////////////////////////////////////////////////////////////////////////// +// +// 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.collections { + import org.flexunit.asserts.*; + + public class ArrayCollection_SortStrings_Tests + { + private var _sut:ArrayCollection; + + [Before] + public function setUp():void + { + _sut = new ArrayCollection(); + } + + [After] + public function tearDown():void + { + _sut = null; + } + + protected function addStrings():void + { + _sut.addItem("A"); + _sut.addItem("B"); + _sut.addItem("D"); + _sut.addItem("C"); + } + + [Test] + public function nullSort():void + { + addStrings(); + _sut.sort = null; + _sut.refresh(); + + assertEquals("Length is not four", 4, _sut.length); + assertEquals("First element not correct", "A", _sut[0]); + assertEquals("Second element not correct", "B", _sut[1]); + assertEquals("First element not correct", "D", _sut[2]); + assertEquals("Second element not correct", "C", _sut[3]); + } + + [Test] + public function emptySort():void + { + addStrings(); + _sut.sort = new Sort(); + _sut.refresh(); + + assertEquals("Length is not four", 4, _sut.length); + assertEquals("First element not correct", "A", _sut[0]); + assertEquals("Second element not correct", "B", _sut[1]); + assertEquals("First element not correct", "C", _sut[2]); + assertEquals("Second element not correct", "D", _sut[3]); + } + + [Test] + public function reverseSort():void + { + var sort:Sort = new Sort(); + sort.fields = [new SortField(null, false, true)]; + addStrings(); + _sut.sort = sort; + _sut.refresh(); + + assertEquals("Length is not four", 4, _sut.length); + assertEquals("First element not correct", "D", _sut[0]); + assertEquals("Second element not correct", "C", _sut[1]); + assertEquals("First element not correct", "B", _sut[2]); + assertEquals("Second element not correct", "A", _sut[3]); + } + + [Test] + public function forwardSort():void + { + var sort:Sort = new Sort(); + sort.fields = [new SortField()]; + addStrings(); + _sut.sort = sort; + _sut.refresh(); + + assertEquals("Length is not four", 4, _sut.length); + assertEquals("First element not correct", "A", _sut[0]); + assertEquals("Second element not correct", "B", _sut[1]); + assertEquals("First element not correct", "C", _sut[2]); + assertEquals("Second element not correct", "D", _sut[3]); + } + + [Test] + public function sortNoRefresh():void + { + var sort:Sort = new Sort(); + sort.fields = [new SortField()]; + addStrings(); + _sut.sort = sort; + + // Short should not take effect + assertEquals("Length is not four", 4, _sut.length); + assertEquals("First element not correct", "A", _sut[0]); + assertEquals("Second element not correct", "B", _sut[1]); + assertEquals("First element not correct", "D", _sut[2]); + assertEquals("Second element not correct", "C", _sut[3]); + } + + [Test] + public function nullSortNoRefresh():void + { + var sort:Sort = new Sort(); + sort.fields = [new SortField()]; + addStrings(); + _sut.sort = sort; + _sut.refresh(); + _sut.sort = null; + + // Sort should be in effect + assertEquals("Length is not four", 4, _sut.length); + assertEquals("First element not correct", "A", _sut[0]); + assertEquals("Second element not correct", "B", _sut[1]); + assertEquals("First element not correct", "C", _sut[2]); + assertEquals("Second element not correct", "D", _sut[3]); + + _sut.refresh(); + + // and back to original + assertEquals("Length is not four", 4, _sut.length); + assertEquals("First element not correct", "A", _sut[0]); + assertEquals("Second element not correct", "B", _sut[1]); + assertEquals("First element not correct", "D", _sut[2]); + assertEquals("Second element not correct", "C", _sut[3]); + } + + [Test] + public function sortDoubleRefresh():void + { + var sort:Sort = new Sort(); + sort.fields = [new SortField()]; + addStrings(); + _sut.sort = sort; + _sut.refresh(); + _sut.sort = null; + _sut.refresh(); + + // Sort should not be in effect + assertEquals("Length is not four", 4, _sut.length); + assertEquals("First element not correct", "A", _sut[0]); + assertEquals("Second element not correct", "B", _sut[1]); + assertEquals("First element not correct", "D", _sut[2]); + assertEquals("Second element not correct", "C", _sut[3]); + } + + // RTEs in APache flex 4.9.1 + [Test] + public function sortAddAfterNullNoRefresh():void + { + addStrings(); + + var sort:Sort = new Sort(); + sort.fields = [new SortField()]; + _sut.sort = sort; + _sut.refresh(); + _sut.sort = null; + addStrings(); + + // Sort should be in effect and first 4 items sorted + // item added after are not sorted + assertEquals("Length is not eight", 8, _sut.length); + assertEquals("First element not correct", "A", _sut[0]); + assertEquals("Second element not correct", "B", _sut[1]); + assertEquals("First element not correct", "C", _sut[2]); + assertEquals("Second element not correct", "D", _sut[3]); + assertEquals("First element not correct", "A", _sut[4]); + assertEquals("Second element not correct", "B", _sut[5]); + assertEquals("First element not correct", "D", _sut[6]); + assertEquals("Second element not correct", "C", _sut[7]); + + _sut.refresh(); + + // and back to being unsorted + assertEquals("Length is not eight", 8, _sut.length); + assertEquals("First element not correct", "A", _sut[0]); + assertEquals("Second element not correct", "B", _sut[1]); + assertEquals("First element not correct", "D", _sut[2]); + assertEquals("Second element not correct", "C", _sut[3]); + assertEquals("First element not correct", "A", _sut[4]); + assertEquals("Second element not correct", "B", _sut[5]); + assertEquals("First element not correct", "D", _sut[6]); + assertEquals("Second element not correct", "C", _sut[7]); + } + + // RTEs in Apache Flex 4.9.1 + [Test] + public function sortRemoveAfterNullNoRefresh():void + { + addStrings(); + + var sort:Sort = new Sort(); + sort.fields = [new SortField(null, false, true, true)]; + _sut.sort = sort; + _sut.refresh(); + _sut.sort = null; + + assertEquals("Length is not four", 4, _sut.length); + + _sut.removeItemAt(0); // still sorted so 2 is removed leaving 1 + assertEquals("Length is not three", 3, _sut.length); + assertEquals("First element not correct", "B", _sut[0]); + + _sut.refresh(); + + assertEquals("Length is not four", 3, _sut.length); + assertEquals("First element not correct", "A", _sut[0]); + } + + [Test] + public function sortIncludingDuplicates():void + { + addStrings(); + addStrings(); + + var sort:Sort = new Sort(); + sort.fields = [new SortField()]; + _sut.sort = sort; + _sut.refresh(); + + assertEquals("Length is not eight", 8, _sut.length); + assertEquals("First element not correct", "A", _sut[0]); + assertEquals("Second element not correct", "A", _sut[1]); + assertEquals("First element not correct", "B", _sut[2]); + assertEquals("Second element not correct", "B", _sut[3]); + assertEquals("First element not correct", "C", _sut[4]); + assertEquals("Second element not correct", "C", _sut[5]); + assertEquals("First element not correct", "D", _sut[6]); + assertEquals("Second element not correct", "D", _sut[7]); + } + + } +} \ No newline at end of file