Repository: flex-sdk Updated Branches: refs/heads/develop 3f7bd745a -> 1d8d02c64
FLEX-35037 Added unit tests donated by Justin Mclean. Currently some are failing. Project: http://git-wip-us.apache.org/repos/asf/flex-sdk/repo Commit: http://git-wip-us.apache.org/repos/asf/flex-sdk/commit/192f1e30 Tree: http://git-wip-us.apache.org/repos/asf/flex-sdk/tree/192f1e30 Diff: http://git-wip-us.apache.org/repos/asf/flex-sdk/diff/192f1e30 Branch: refs/heads/develop Commit: 192f1e30b0dabf40afc6fd23be67f7c3a91686a9 Parents: 3f7bd74 Author: Mihai Chira <[email protected]> Authored: Mon Feb 22 18:00:26 2016 +0100 Committer: Mihai Chira <[email protected]> Committed: Mon Feb 22 18:00:26 2016 +0100 ---------------------------------------------------------------------- .../tests/mx/collections/AddRemoveNumbers.as | 158 +++++++++ .../tests/mx/collections/AddRemoveObjects.as | 203 ++++++++++++ .../tests/mx/collections/AddRemoveStrings.as | 167 ++++++++++ .../tests/mx/collections/FilerAndSortNumbers.as | 100 ++++++ .../tests/mx/collections/FilerAndSortStrings.as | 100 ++++++ .../tests/mx/collections/FilterNumbers.as | 298 +++++++++++++++++ .../tests/mx/collections/FilterStrings.as | 324 +++++++++++++++++++ .../tests/mx/collections/SortNumbers.as | 198 ++++++++++++ .../tests/mx/collections/SortStrings.as | 240 ++++++++++++++ 9 files changed, 1788 insertions(+) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/flex-sdk/blob/192f1e30/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 new file mode 100644 index 0000000..28354f2 --- /dev/null +++ b/frameworks/projects/framework/tests/mx/collections/AddRemoveNumbers.as @@ -0,0 +1,158 @@ +package mx.collections { + import mx.collections.ArrayCollection; + + 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", _sut.length, 1); + assertEquals("First element not correct", _sut[0], 1); + _sut.addItem(2); + assertEquals("Length is not two", _sut.length, 2); + assertEquals("Second element not correct", _sut[1], 2); + } + + [Test] + public function addDuplicate():void + { + addNumbers(); + _sut.addItem(1); + assertEquals("Length is not three", _sut.length, 3); + assertEquals("First element not correct", _sut[0], 1); + assertEquals("Second element not correct", _sut[1], 2); + assertEquals("Second element not correct", _sut[2], 1); + } + + [Test] + public function removeDuplicate():void + { + addNumbers(); + _sut.addItem(1); + _sut.removeItemAt(0); + assertEquals("Length is not two", _sut.length, 2); + assertEquals("First element not correct", _sut[0], 2); + assertEquals("Second element not correct", _sut[1], 1); + } + + [Test] + public function removeAllNumbers():void + { + addNumbers(); + _sut.removeAll(); + assertEquals("Length is not zero", _sut.length, 0); + } + + [Test] + public function removeFirstNumbers():void + { + addNumbers(); + _sut.removeItemAt(0); + assertEquals("First element not correct", _sut[0], 2); + assertEquals("Length is not one", _sut.length, 1); + _sut.removeItemAt(0); + assertEquals("Length is not zero", _sut.length, 0); + } + + [Test] + public function removeLastNumbers():void + { + addNumbers(); + _sut.removeItemAt(1); + assertEquals("First element not correct", _sut[0], 1); + assertEquals("Length is not one", _sut.length, 1); + _sut.removeItemAt(0); + assertEquals("Length is not zero", _sut.length, 0); + } + + [Test] + public function removeItemByIndex():void + { + addNumbers(); + _sut.removeItemAt(_sut.getItemIndex(1)); + assertEquals("First element not correct", _sut[0], 2); + assertEquals("Length is not one", _sut.length, 1); + _sut.removeItemAt(_sut.getItemIndex(2)); + assertEquals("Length is not zero", _sut.length, 0); + } + + [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", _sut.length, 2); + try { + _sut.removeItemAt(10); + } + catch (error:Error) + { + assertTrue("Error not range error", error is RangeError); + } + assertEquals("Length is not two", _sut.length, 2); + } + + [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", _sut.length, 2); + assertEquals("First element not correct", _sut[0], 2); + assertEquals("Second element not correct", _sut[1], 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", _sut.length, 2); + assertEquals("First element not correct", _sut[0], 2); + assertEquals("Second element not correct", _sut[1], 1); + } + + } +} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/flex-sdk/blob/192f1e30/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 new file mode 100644 index 0000000..845b97a --- /dev/null +++ b/frameworks/projects/framework/tests/mx/collections/AddRemoveObjects.as @@ -0,0 +1,203 @@ +package mx.collections { + import mx.collections.ArrayCollection; + + import org.flexunit.asserts.*; + + public class AddRemoveObjects + { + protected var ac: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 + { + ac = new ArrayCollection(); + } + + [After] + public function tearDown():void + { + ac = null; + } + + [Test] + public function empty():void + { + assertEquals(ac.length, 0); + } + + [Test] + public function addObjects():void + { + ac = new ArrayCollection(players); + assertEquals("Length is not seven", ac.length, 7); + assertEquals("First element not correct", ac[0], players[0]); + assertEquals("Second element not correct", ac[1], players[1]); + assertEquals("Third element not correct", ac[2], players[2]); + assertEquals("Fouth element not correct", ac[3], players[3]); + assertEquals("Fifth element not correct", ac[4], players[4]); + assertEquals("Sixth element not correct", ac[5], players[5]); + assertEquals("Seventh element not correct", ac[6], players[6]); + } + + [Test] + public function addDuplicate():void + { + addObjects(); + ac.addItem(players[0]); + assertEquals("Length is not eight", ac.length, 8); + assertEquals("First element not correct", ac[0], players[0]); + assertEquals("Second element not correct", ac[1], players[1]); + assertEquals("Third element not correct", ac[2], players[2]); + assertEquals("Fouth element not correct", ac[3], players[3]); + assertEquals("Fifth element not correct", ac[4], players[4]); + assertEquals("Sixth element not correct", ac[5], players[5]); + assertEquals("Seventh element not correct", ac[6], players[6]); + assertEquals("Eighth element not correct", ac[7], players[0]); + } + + [Test] + public function removeDuplicate():void + { + addObjects(); + ac.addItem(players[0]); + ac.removeItemAt(0); + assertEquals("Length is not seven", ac.length, 7); + assertEquals("First element not correct", ac[0], players[1]); + assertEquals("Second element not correct", ac[1], players[2]); + assertEquals("Third element not correct", ac[2], players[3]); + assertEquals("Fouth element not correct", ac[3], players[4]); + assertEquals("Fifth element not correct", ac[4], players[5]); + assertEquals("Sixth element not correct", ac[5], players[6]); + assertEquals("Seventh element not correct", ac[6], players[0]); + } + + [Test] + public function removeAllObjects():void + { + addObjects(); + ac.removeAll(); + assertEquals("Length is not zero", ac.length, 0); + } + + [Test] + public function removeFirstObjects():void + { + addObjects(); + ac.removeItemAt(0); + assertEquals("First element not correct", ac[0], players[1]); + assertEquals("Length is not six", ac.length, 6); + ac.removeItemAt(0); + assertEquals("Length is not five", ac.length, 5); + ac.removeItemAt(0); + assertEquals("Length is not four", ac.length, 4); + ac.removeItemAt(0); + assertEquals("Length is not three", ac.length, 3); + ac.removeItemAt(0); + assertEquals("Length is not two", ac.length, 2); + ac.removeItemAt(0); + assertEquals("Length is not one", ac.length, 1); + ac.removeItemAt(0); + assertEquals("Length is not zero", ac.length, 0); + } + + [Test] + public function removeLastNumbers():void + { + addObjects(); + ac.removeItemAt(6); + assertEquals("First element not correct", ac[0], players[0]); + assertEquals("Length is not six", ac.length, 6); + ac.removeItemAt(0); + assertEquals("Length is not five", ac.length, 5); + ac.removeItemAt(0); + assertEquals("Length is not four", ac.length, 4); + ac.removeItemAt(0); + assertEquals("Length is not three", ac.length, 3); + ac.removeItemAt(0); + assertEquals("Length is not two", ac.length, 2); + ac.removeItemAt(0); + assertEquals("Length is not one", ac.length, 1); + ac.removeItemAt(0); + assertEquals("Length is not zero", ac.length, 0); + } + + [Test] + public function removeItemByIndex():void + { + addObjects(); + ac.removeItemAt(ac.getItemIndex(players[0])); + assertEquals("First element not correct", ac[0], players[1]); + assertEquals("Length is not six", ac.length, 6); + ac.removeItemAt(ac.getItemIndex(players[2])); + assertEquals("First element not correct", ac[0], players[1]); + assertEquals("Second element not correct", ac[1], players[3]); + assertEquals("Length is not four", ac.length, 4); + } + + [Test] + public function outOfRange():void + { + addObjects(); + try { + ac.removeItemAt(-1); + } + catch (error:Error) + { + assertTrue("Error not range error", error is RangeError); + } + assertEquals("Length is not seven", ac.length, 7); + try { + ac.removeItemAt(10); + } + catch (error:Error) + { + assertTrue("Error not range error", error is RangeError); + } + assertEquals("Length is not seven", ac.length, 7); + } + + [Test] + public function swapItemsTwoThenOne():void + { + addObjects(); + + var item1:Object = ac.getItemAt(0); + var item2:Object = ac.getItemAt(1); + + ac.setItemAt(item2,0); + ac.setItemAt(item1,1); + + assertEquals("Length is not seven", ac.length, 7); + assertEquals("First element not correct", ac[0], players[1]); + assertEquals("Second element not correct", ac[1], players[0]); + } + + [Test] + public function swapItemsOneThenTwo():void + { + addObjects(); + + var item1:Object = ac.getItemAt(0); + var item2:Object = ac.getItemAt(1); + + ac.setItemAt(item1,1); + ac.setItemAt(item2,0); + + assertEquals("Length is not seven", ac.length, 7); + assertEquals("First element not correct", ac[0], players[1]); + assertEquals("Second element not correct", ac[1], players[0]); + + } + + } +} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/flex-sdk/blob/192f1e30/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 new file mode 100644 index 0000000..cc9145f --- /dev/null +++ b/frameworks/projects/framework/tests/mx/collections/AddRemoveStrings.as @@ -0,0 +1,167 @@ +package mx.collections { + import mx.collections.ArrayCollection; + + import org.flexunit.asserts.*; + + public class AddRemoveStrings + { + protected var ac:ArrayCollection; + + [Before] + public function setUp():void + { + ac = new ArrayCollection(); + } + + [After] + public function tearDown():void + { + ac = null; + } + + [Test] + public function empty():void + { + assertEquals(ac.length, 0); + } + + [Test] + public function addStrings():void + { + ac.addItem("A"); + assertEquals("Length is not one", ac.length, 1); + assertEquals("First element not correct", ac[0], "A"); + ac.addItem("B"); + assertEquals("Length is not two", ac.length, 2); + assertEquals("Second element not correct", ac[1], "B"); + ac.addItem("D"); + assertEquals("Length is not three", ac.length, 3); + assertEquals("Second element not correct", ac[2], "D"); + ac.addItem("C"); + assertEquals("Length is not four", ac.length, 4); + assertEquals("Second element not correct", ac[3], "C"); + } + + [Test] + public function addDuplicate():void + { + addStrings(); + ac.addItem("B"); + assertEquals("Length is not five", ac.length, 5); + assertEquals("First element not correct", ac[0], "A"); + assertEquals("Second element not correct", ac[1], "B"); + assertEquals("Second element not correct", ac[2], "D"); + assertEquals("Second element not correct", ac[3], "C"); + assertEquals("Second element not correct", ac[4], "B"); + } + + [Test] + public function removeDuplicate():void + { + addStrings(); + ac.addItem("B"); + ac.removeItemAt(1); + assertEquals("Length is not four", ac.length, 4); + assertEquals("First element not correct", ac[0], "A"); + assertEquals("Second element not correct", ac[1], "D"); + assertEquals("Second element not correct", ac[2], "C"); + assertEquals("Second element not correct", ac[3], "B"); + } + + [Test] + public function removeAllStrings():void + { + addStrings(); + ac.removeAll(); + assertEquals("Length is not zero", ac.length, 0); + } + + [Test] + public function removeFirstStrings():void + { + addStrings(); + ac.removeItemAt(0); + assertEquals("First element not correct", ac[0], "B"); + assertEquals("Length is not three", ac.length, 3); + ac.removeItemAt(0); + assertEquals("Length is not two", ac.length, 2); + } + + [Test] + public function removeLastStrings():void + { + addStrings(); + ac.removeItemAt(1); + assertEquals("First element not correct", ac[0], "A"); + assertEquals("Length is not three", ac.length, 3); + ac.removeItemAt(0); + assertEquals("Length is not two", ac.length, 2); + } + + [Test] + public function removeItemByIndex():void + { + addStrings(); + ac.removeItemAt(ac.getItemIndex("B")); + assertEquals("First element not correct", ac[0], "A"); + assertEquals("Length is not three", ac.length, 3); + ac.removeItemAt(ac.getItemIndex("D")); + assertEquals("Length is not two", ac.length, 2); + } + + [Test] + public function outOfRange():void + { + addStrings(); + try { + ac.removeItemAt(-1); + } + catch (error:Error) + { + assertTrue("Error not range error", error is RangeError); + } + assertEquals("Length is not four", ac.length, 4); + try { + ac.removeItemAt(10); + } + catch (error:Error) + { + assertTrue("Error not range error", error is RangeError); + } + assertEquals("Length is not two", ac.length, 4); + } + + [Test] + public function swapItemsTwoThenOne():void + { + addStrings(); + + var item1:String = ac.getItemAt(0) as String; + var item2:String = ac.getItemAt(1) as String; + + ac.setItemAt(item2, 0); + ac.setItemAt(item1, 1); + + assertEquals("Length is not four", ac.length, 4); + assertEquals("First element not correct", ac[0], "B"); + assertEquals("Second element not correct", ac[1], "A"); + } + + [Test] + public function swapItemsOneThenTwo():void + { + addStrings(); + + var item1:String = ac.getItemAt(0) as String; + var item2:String = ac.getItemAt(1) as String; + + ac.setItemAt(item1, 1); + ac.setItemAt(item2, 0); + + assertEquals("Length is not two", ac.length, 2); + assertEquals("First element not correct", ac[0], "B"); + assertEquals("Second element not correct", ac[1], "A"); + } + + } +} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/flex-sdk/blob/192f1e30/frameworks/projects/framework/tests/mx/collections/FilerAndSortNumbers.as ---------------------------------------------------------------------- diff --git a/frameworks/projects/framework/tests/mx/collections/FilerAndSortNumbers.as b/frameworks/projects/framework/tests/mx/collections/FilerAndSortNumbers.as new file mode 100644 index 0000000..1741321 --- /dev/null +++ b/frameworks/projects/framework/tests/mx/collections/FilerAndSortNumbers.as @@ -0,0 +1,100 @@ +package mx.collections { + import mx.collections.ArrayCollection; + import mx.collections.Sort; + import mx.collections.SortField; + + public class FilerAndSortNumbers + { + import org.flexunit.asserts.*; + + protected var ac:ArrayCollection; + + [Before] + public function setUp():void + { + ac = new ArrayCollection(); + } + + [After] + public function tearDown():void + { + ac = null; + } + + + protected function addNumbers():void + { + ac.addItem(6); + ac.addItem(2); + ac.addItem(3); + ac.addItem(1); + ac.addItem(5); + ac.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(); + ac.filterFunction = even; + ac.sort = new Sort(); + ac.refresh(); + + assertEquals("Length is not three", ac.length, 3); + assertEquals("First element not correct", ac[0], 2); + assertEquals("Second element not correct", ac[1], 4); + assertEquals("Third element not correct", ac[2], 6); + + ac.filterFunction = odd; + ac.refresh(); + + assertEquals("Length is not three", ac.length, 3); + assertEquals("First element not correct", ac[0], 1); + assertEquals("Second element not correct", ac[1], 3); + assertEquals("Third element not correct", ac[2], 5); + + ac.sort = new Sort(); + ac.sort.fields = [new SortField(null, false, true, true)]; + ac.refresh(); + + assertEquals("Length is not three", ac.length, 3); + assertEquals("First element not correct", ac[0], 5); + assertEquals("Second element not correct", ac[1], 3); + assertEquals("Third element not correct", ac[2], 1); + + ac.filterFunction = null; + ac.refresh(); + + assertEquals("Length is not six", ac.length, 6); + assertEquals("First element not correct", ac[0], 6); + assertEquals("Second element not correct", ac[1], 5); + assertEquals("Third element not correct", ac[2], 4); + assertEquals("Fourth element not correct", ac[3], 3); + assertEquals("Fith element not correct", ac[4], 2); + assertEquals("Six element not correct", ac[5], 1); + + ac.sort = null; + ac.refresh(); + + assertEquals("Length is not six", ac.length, 6); + assertEquals("First element not correct", ac[0], 6); + assertEquals("Second element not correct", ac[1], 2); + assertEquals("Third element not correct", ac[2], 3); + assertEquals("Fourth element not correct", ac[3], 1); + assertEquals("Fith element not correct", ac[4], 5); + assertEquals("Six element not correct", ac[5], 4); + } + + + } +} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/flex-sdk/blob/192f1e30/frameworks/projects/framework/tests/mx/collections/FilerAndSortStrings.as ---------------------------------------------------------------------- diff --git a/frameworks/projects/framework/tests/mx/collections/FilerAndSortStrings.as b/frameworks/projects/framework/tests/mx/collections/FilerAndSortStrings.as new file mode 100644 index 0000000..0d0142a --- /dev/null +++ b/frameworks/projects/framework/tests/mx/collections/FilerAndSortStrings.as @@ -0,0 +1,100 @@ +package mx.collections { + import mx.collections.ArrayCollection; + import mx.collections.Sort; + import mx.collections.SortField; + + public class FilerAndSortStrings + { + import org.flexunit.asserts.*; + + protected var ac:ArrayCollection; + + [Before] + public function setUp():void + { + ac = new ArrayCollection(); + } + + [After] + public function tearDown():void + { + ac = null; + } + + + protected function addNumbers():void + { + ac.addItem(6); + ac.addItem(2); + ac.addItem(3); + ac.addItem(1); + ac.addItem(5); + ac.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(); + ac.filterFunction = even; + ac.sort = new Sort(); + ac.refresh(); + + assertEquals("Length is not three", ac.length, 3); + assertEquals("First element not correct", ac[0], 2); + assertEquals("Second element not correct", ac[1], 4); + assertEquals("Third element not correct", ac[2], 6); + + ac.filterFunction = odd; + ac.refresh(); + + assertEquals("Length is not three", ac.length, 3); + assertEquals("First element not correct", ac[0], 1); + assertEquals("Second element not correct", ac[1], 3); + assertEquals("Third element not correct", ac[2], 5); + + ac.sort = new Sort(); + ac.sort.fields = [new SortField(null, false, true, true)]; + ac.refresh(); + + assertEquals("Length is not three", ac.length, 3); + assertEquals("First element not correct", ac[0], 5); + assertEquals("Second element not correct", ac[1], 3); + assertEquals("Third element not correct", ac[2], 1); + + ac.filterFunction = null; + ac.refresh(); + + assertEquals("Length is not six", ac.length, 6); + assertEquals("First element not correct", ac[0], 6); + assertEquals("Second element not correct", ac[1], 5); + assertEquals("Third element not correct", ac[2], 4); + assertEquals("Fourth element not correct", ac[3], 3); + assertEquals("Fith element not correct", ac[4], 2); + assertEquals("Six element not correct", ac[5], 1); + + ac.sort = null; + ac.refresh(); + + assertEquals("Length is not six", ac.length, 6); + assertEquals("First element not correct", ac[0], 6); + assertEquals("Second element not correct", ac[1], 2); + assertEquals("Third element not correct", ac[2], 3); + assertEquals("Fourth element not correct", ac[3], 1); + assertEquals("Fith element not correct", ac[4], 5); + assertEquals("Six element not correct", ac[5], 4); + } + + + } +} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/flex-sdk/blob/192f1e30/frameworks/projects/framework/tests/mx/collections/FilterNumbers.as ---------------------------------------------------------------------- diff --git a/frameworks/projects/framework/tests/mx/collections/FilterNumbers.as b/frameworks/projects/framework/tests/mx/collections/FilterNumbers.as new file mode 100644 index 0000000..34e03f2 --- /dev/null +++ b/frameworks/projects/framework/tests/mx/collections/FilterNumbers.as @@ -0,0 +1,298 @@ +package mx.collections { + import mx.collections.ArrayCollection; + import mx.collections.Sort; + import mx.collections.SortField; + + public class FilterNumbers + { + import org.flexunit.asserts.*; + + protected var ac:ArrayCollection; + + [Before] + public function setUp():void + { + ac = new ArrayCollection(); + } + + [After] + public function tearDown():void + { + ac = null; + } + + protected function addNumbers():void + { + ac.addItem(1); + ac.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(); + ac.filterFunction = null; + ac.refresh(); + + assertEquals("Length is not two", ac.length, 2); + assertEquals("First element not correct", ac[0], 1); + assertEquals("Second element not correct", ac[1], 2); + } + + [Test] + public function trueFilter():void + { + addNumbers(); + ac.filterFunction = allIn; + ac.refresh(); + + assertEquals("Length is not two", ac.length, 2); + assertEquals("First element not correct", ac[0], 1); + assertEquals("Second element not correct", ac[1], 2); + } + + [Test] + public function falseFilter():void + { + addNumbers(); + ac.filterFunction = allOut; + ac.refresh(); + + assertEquals("Length is not two", ac.length, 0); + } + + + [Test] + public function filterNoRefresh():void + { + addNumbers(); + ac.filterFunction = allOut; + + // Filter should not take effect + assertEquals("Length is not two", ac.length, 2); + assertEquals("First element not correct", ac[0], 1); + assertEquals("Second element not correct", ac[1], 2); + } + + [Test] + public function nullFilterNoRefresh():void + { + addNumbers(); + ac.filterFunction = null; + + // Filter should not take effect + assertEquals("Length is not two", ac.length, 2); + assertEquals("First element not correct", ac[0], 1); + assertEquals("Second element not correct", ac[1], 2); + } + + [Test] + public function filterDoubleRefresh():void + { + addNumbers(); + ac.filterFunction = allOut; + ac.refresh(); + + assertEquals("Length is not zero", ac.length, 0); + + ac.filterFunction = null; + ac.refresh(); + + // Filter should not take effect + assertEquals("Length is not two", ac.length, 2); + assertEquals("First element not correct", ac[0], 1); + assertEquals("Second element not correct", ac[1], 2); + } + + // RTEs in Apache Flex 4.9.1 + [Test] + public function filterAddAfterNullNoRefresh():void + { + addNumbers(); + + ac.filterFunction = allOut; + ac.refresh(); + + assertEquals("Length is not zero", ac.length, 0); + + ac.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", ac.length, 2); + assertEquals("First element not correct", ac[0], 1); + assertEquals("Second element not correct", ac[1], 2); + + ac.refresh(); + assertEquals("Length is not four", ac.length, 4); + assertEquals("First element not correct", ac[0], 1); + assertEquals("Second element not correct", ac[1], 2); + assertEquals("First element not correct", ac[2], 1); + assertEquals("Second element not correct", ac[3], 2); + } + + [Test] + public function filterRemoveAfterNullNoRefresh():void + { + addNumbers(); + + ac.filterFunction = allOut; + ac.refresh(); + ac.filterFunction = null; + + assertEquals("Length is not zero", ac.length, 0); + + try { + ac.removeItemAt(0); + } + catch (error:Error) + { + assertTrue("Error not range error", error is RangeError); + } + + assertEquals("Length is not zero", ac.length, 0); + + ac.refresh(); + assertEquals("Length is not two", ac.length, 2); + } + + [Test] + public function filterIncludingDuplicates():void + { + addNumbers(); + addNumbers(); + + ac.filterFunction = isOne; + ac.refresh(); + + assertEquals("Length is not two", ac.length, 2); + + assertEquals("First element not correct", ac[0], 1); + assertEquals("Second element not correct", ac[1], 1); + } + + // Fails in Apache Flex 4.9.1 + [Test] + public function swapItemsTwoThenOne():void + { + addNumbers(); + ac.filterFunction = allIn; + ac.refresh(); + + var item1:Number = ac.getItemAt(0) as Number; + var item2:Number = ac.getItemAt(1) as Number; + + ac.setItemAt(item2,0); + ac.setItemAt(item1,1); + + assertEquals("Length is not two", ac.length, 2); + assertEquals("First element not correct", ac[0], 2); + assertEquals("Second element not correct", ac[1], 1); + } + + [Test] + public function swapItemsOneThenTwo():void + { + addNumbers(); + ac.filterFunction = allIn; + ac.refresh(); + + var item1:Number = ac.getItemAt(0) as Number; + var item2:Number = ac.getItemAt(1) as Number; + + ac.setItemAt(item1,1); + ac.setItemAt(item2,0); + + assertEquals("Length is not two", ac.length, 2); + assertEquals("First element not correct", ac[0], 2); + assertEquals("Second element not correct", ac[1], 1); + } + + [Test] + public function removeAllAfterFiltered():void + { + addNumbers(); + ac.filterFunction = allOut; + ac.refresh(); + + assertEquals("Length is not two", ac.length, 0); + + ac.removeAll(); + + assertEquals("Length is not two", ac.length, 0); + + ac.filterFunction = null; + ac.refresh(); + + assertEquals("Length is not two", ac.length, 2); + assertEquals("First element not correct", ac[0], 1); + assertEquals("Second element not correct", ac[1], 2); + } + + [Test] + public function removeFilteredItem():void + { + addNumbers(); + ac.filterFunction = isOne; + ac.refresh(); + + assertEquals("Length is not one", ac.length, 1); + + ac.removeItemAt(ac.getItemIndex(1)); + + assertEquals("Length is not zero", ac.length, 0); + + ac.filterFunction = null; + ac.refresh(); + + assertEquals("Length is not two", ac.length, 1); + assertEquals("First element not correct", ac[0], 2); + } + + [Test] + public function removeNonFilteredItem():void + { + addNumbers(); + ac.filterFunction = isOne; + ac.refresh(); + + assertEquals("Length is not one", ac.length, 1); + + try { + // not removed as filter hids it - perhaps it should be removed? + ac.removeItemAt(ac.getItemIndex(2)); + } + catch (error:Error) + { + assertTrue("Error not range error", error is RangeError); + } + + assertEquals("Length is not one", ac.length, 1); + + ac.filterFunction = null; + ac.refresh(); + + assertEquals("Length is not two", ac.length, 2); + assertEquals("First element not correct", ac[0], 1); + assertEquals("First element not correct", ac[1], 2); + } + + + } +} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/flex-sdk/blob/192f1e30/frameworks/projects/framework/tests/mx/collections/FilterStrings.as ---------------------------------------------------------------------- diff --git a/frameworks/projects/framework/tests/mx/collections/FilterStrings.as b/frameworks/projects/framework/tests/mx/collections/FilterStrings.as new file mode 100644 index 0000000..a3be478 --- /dev/null +++ b/frameworks/projects/framework/tests/mx/collections/FilterStrings.as @@ -0,0 +1,324 @@ +package mx.collections { + import mx.collections.ArrayCollection; + import mx.collections.Sort; + import mx.collections.SortField; + + public class FilterStrings + { + import org.flexunit.asserts.*; + + protected var ac:ArrayCollection; + + [Before] + public function setUp():void + { + ac = new ArrayCollection(); + } + + [After] + public function tearDown():void + { + ac = null; + } + + protected function addStrings():void + { + ac.addItem("A"); + ac.addItem("B"); + ac.addItem("D"); + ac.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(); + ac.filterFunction = null; + ac.refresh(); + + assertEquals("Length is not four", ac.length, 4); + assertEquals("First element not correct", ac[0], "A"); + assertEquals("Second element not correct", ac[1], "B"); + assertEquals("Third element not correct", ac[2], "D"); + assertEquals("Four element not correct", ac[3], "C"); + } + + [Test] + public function trueFilter():void + { + addStrings(); + ac.filterFunction = allIn; + ac.refresh(); + + assertEquals("Length is not four", ac.length, 4); + assertEquals("First element not correct", ac[0], "A"); + assertEquals("Second element not correct", ac[1], "B"); + assertEquals("Third element not correct", ac[2], "D"); + assertEquals("Four element not correct", ac[3], "C"); + } + + [Test] + public function falseFilter():void + { + addStrings(); + ac.filterFunction = allOut; + ac.refresh(); + + assertEquals("Length is not zero", ac.length, 0); + } + + + [Test] + public function filterNoRefresh():void + { + addStrings(); + ac.filterFunction = allOut; + + // Filter should not take effect + assertEquals("Length is not four", ac.length, 4); + assertEquals("First element not correct", ac[0], "A"); + assertEquals("Second element not correct", ac[1], "B"); + assertEquals("Third element not correct", ac[2], "D"); + assertEquals("Four element not correct", ac[3], "C"); + } + + [Test] + public function nullFilterNoRefresh():void + { + addStrings(); + ac.filterFunction = null; + + // Filter should not take effect + assertEquals("Length is not four", ac.length, 4); + assertEquals("First element not correct", ac[0], "A"); + assertEquals("Second element not correct", ac[1], "B"); + assertEquals("Third element not correct", ac[2], "D"); + assertEquals("Four element not correct", ac[3], "C"); + } + + [Test] + public function filterDoubleRefresh():void + { + addStrings(); + ac.filterFunction = allOut; + ac.refresh(); + + assertEquals("Length is not zero", ac.length, 0); + + ac.filterFunction = null; + ac.refresh(); + + // Filter should not take effect + assertEquals("Length is not four", ac.length, 4); + assertEquals("First element not correct", ac[0], "A"); + assertEquals("Second element not correct", ac[1], "B"); + assertEquals("Third element not correct", ac[2], "D"); + assertEquals("Four element not correct", ac[3], "C"); + } + + // RTEs in Apache Flex 4.9.1 + [Test] + public function filterAddAfterNullNoRefresh():void + { + addStrings(); + + ac.filterFunction = allOut; + ac.refresh(); + + assertEquals("Length is not zero", ac.length, 0); + + ac.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", ac.length, 4); + assertEquals("First element not correct", ac[0], "A"); + assertEquals("Second element not correct", ac[1], "B"); + assertEquals("Third element not correct", ac[2], "D"); + assertEquals("Four element not correct", ac[3], "C"); + + ac.refresh(); + assertEquals("Length is not eight", ac.length, 8); + assertEquals("First element not correct", ac[0], "A"); + assertEquals("Second element not correct", ac[1], "B"); + assertEquals("Third element not correct", ac[2], "D"); + assertEquals("Four element not correct", ac[3], "C"); + assertEquals("First element not correct", ac[4], "A"); + assertEquals("Second element not correct", ac[5], "B"); + assertEquals("Third element not correct", ac[6], "D"); + assertEquals("Four element not correct", ac[7], "C"); + } + + [Test] + public function filterRemoveAfterNullNoRefresh():void + { + addStrings(); + + ac.filterFunction = allOut; + ac.refresh(); + ac.filterFunction = null; + + assertEquals("Length is not zero", ac.length, 0); + + try { + ac.removeItemAt(0); + } + catch (error:Error) + { + assertTrue("Error not range error", error is RangeError); + } + + assertEquals("Length is not zero", ac.length, 0); + + ac.refresh(); + assertEquals("Length is not four", ac.length, 4); + } + + [Test] + public function filterIncludingDuplicates():void + { + addStrings(); + addStrings(); + + ac.filterFunction = isA; + ac.refresh(); + + assertEquals("Length is not two", ac.length, 2); + + assertEquals("First element not correct", ac[0], "A"); + assertEquals("Second element not correct", ac[1], "A"); + } + + // Fails in Apache Flex 4.9.1 + [Test] + public function swapItemsTwoThenOne():void + { + addStrings(); + ac.filterFunction = allIn; + ac.refresh(); + + var item1:String = ac.getItemAt(0) as String; + var item2:String = ac.getItemAt(1) as String; + + ac.setItemAt(item2,0); + ac.setItemAt(item1,1); + + assertEquals("Length is not four", ac.length, 4); + assertEquals("First element not correct", ac[0], "B"); + assertEquals("Second element not correct", ac[1], "A"); + assertEquals("Third element not correct", ac[2], "D"); + assertEquals("Four element not correct", ac[3], "C"); + } + + [Test] + public function swapItemsOneThenTwo():void + { + addStrings(); + ac.filterFunction = allIn; + ac.refresh(); + + var item1:String = ac.getItemAt(0) as String; + var item2:String = ac.getItemAt(1) as String; + + ac.setItemAt(item1,1); + ac.setItemAt(item2,0); + + assertEquals("Length is not four", ac.length, 4); + assertEquals("First element not correct", ac[0], "B"); + assertEquals("Second element not correct", ac[1], "A"); + assertEquals("Third element not correct", ac[2], "D"); + assertEquals("Four element not correct", ac[3], "C"); + } + + [Test] + public function removeAllAfterFiltered():void + { + addStrings(); + ac.filterFunction = allOut; + ac.refresh(); + + assertEquals("Length is not two", ac.length, 0); + + ac.removeAll(); + + assertEquals("Length is not two", ac.length, 0); + + ac.filterFunction = null; + ac.refresh(); + + assertEquals("Length is not four", ac.length, 4); + assertEquals("First element not correct", ac[0], "A"); + assertEquals("Second element not correct", ac[1], "B"); + assertEquals("Third element not correct", ac[2], "D"); + assertEquals("Four element not correct", ac[3], "C"); + } + + [Test] + public function removeFilteredItem():void + { + addStrings(); + ac.filterFunction = isA; + ac.refresh(); + + assertEquals("Length is not one", ac.length, 1); + + ac.removeItemAt(ac.getItemIndex("A")); + + assertEquals("Length is not zero", ac.length, 0); + + ac.filterFunction = null; + ac.refresh(); + + assertEquals("Length is not three", ac.length, 3); + assertEquals("First element not correct", ac[0], "B"); + } + + [Test] + public function removeNonFilteredItem():void + { + addStrings(); + ac.filterFunction = isA; + ac.refresh(); + + assertEquals("Length is not one", ac.length, 1); + + try { + // not removed as filter hids it - perhaps it should be removed? + ac.removeItemAt(ac.getItemIndex("B")); + } + catch (error:Error) + { + assertTrue("Error not range error", error is RangeError); + } + + assertEquals("Length is not one", ac.length, 1); + + ac.filterFunction = null; + ac.refresh(); + + assertEquals("Length is not four", ac.length, 4); + assertEquals("First element not correct", ac[0], "A"); + assertEquals("Second element not correct", ac[1], "B"); + assertEquals("Third element not correct", ac[2], "D"); + assertEquals("Four element not correct", ac[3], "C"); + } + + + } +} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/flex-sdk/blob/192f1e30/frameworks/projects/framework/tests/mx/collections/SortNumbers.as ---------------------------------------------------------------------- diff --git a/frameworks/projects/framework/tests/mx/collections/SortNumbers.as b/frameworks/projects/framework/tests/mx/collections/SortNumbers.as new file mode 100644 index 0000000..ccaf6aa --- /dev/null +++ b/frameworks/projects/framework/tests/mx/collections/SortNumbers.as @@ -0,0 +1,198 @@ +package mx.collections { + import mx.collections.ArrayCollection; + import mx.collections.Sort; + import mx.collections.SortField; + + public class SortNumbers + { + import org.flexunit.asserts.*; + + protected var ac:ArrayCollection; + + [Before] + public function setUp():void + { + ac = new ArrayCollection(); + } + + [After] + public function tearDown():void + { + ac = null; + } + + protected function addNumbers():void + { + ac.addItem(1); + ac.addItem(2); + } + + [Test] + public function nullSort():void + { + addNumbers(); + ac.sort = null; + ac.refresh(); + + assertEquals("Length is not two", ac.length, 2); + assertEquals("First element not correct", ac[0], 1); + assertEquals("Second element not correct", ac[1], 2); + } + + [Test] + public function emptySort():void + { + addNumbers(); + ac.sort = new Sort(); + ac.refresh(); + + assertEquals("Length is not two", ac.length, 2); + assertEquals("First element not correct", ac[0], 1); + assertEquals("Second element not correct", ac[1], 2); + } + + [Test] + public function reverseSort():void + { + var sort:Sort = new Sort(); + sort.fields = [new SortField(null, false, true, true)]; + addNumbers(); + ac.sort = sort; + ac.refresh(); + + assertEquals("Length is not two", ac.length, 2); + assertEquals("First element not correct", ac[0], 2); + assertEquals("Second element not correct", ac[1], 1); + } + + [Test] + public function sortNoRefresh():void + { + var sort:Sort = new Sort(); + sort.fields = [new SortField(null, false, true, true)]; + addNumbers(); + ac.sort = sort; + + // Short should not take effect + assertEquals("Length is not two", ac.length, 2); + assertEquals("First element not correct", ac[0], 1); + assertEquals("Second element not correct", ac[1], 2); + } + + [Test] + public function nullSortNoRefresh():void + { + var sort:Sort = new Sort(); + sort.fields = [new SortField(null, false, true, true)]; + addNumbers(); + ac.sort = sort; + ac.refresh(); + ac.sort = null; + + // Sort should be in effect + assertEquals("Length is not two", ac.length, 2); + assertEquals("First element not correct", ac[0], 2); + assertEquals("Second element not correct", ac[1], 1); + + ac.refresh(); + + // and back to original + assertEquals("Length is not two", ac.length, 2); + assertEquals("First element not correct", ac[0], 1); + assertEquals("Second element not correct", ac[1], 2); + } + + [Test] + public function sortDoubleRefresh():void + { + var sort:Sort = new Sort(); + sort.fields = [new SortField(null, false, true, true)]; + addNumbers(); + ac.sort = sort; + ac.refresh(); + ac.sort = null; + ac.refresh(); + + // Sort should not be in effect + assertEquals("Length is not two", ac.length, 2); + assertEquals("First element not correct", ac[0], 1); + assertEquals("Second element not correct", ac[1], 2); + } + + // 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)]; + ac.sort = sort; + ac.refresh(); + ac.sort = null; + addNumbers(); + + // Sort should be in effect and first 2 items sorted + // item added after are not sorted + assertEquals("Length is not four", ac.length, 4); + assertEquals("First element not correct", ac[0], 2); + assertEquals("Second element not correct", ac[1], 1); + assertEquals("Third element not correct", ac[2], 1); + assertEquals("Fourth element not correct", ac[3], 2); + + ac.refresh(); + + // and back to being unsorted + assertEquals("Length is not four", ac.length, 4); + assertEquals("First element not correct", ac[0], 1); + assertEquals("Second element not correct", ac[1], 2); + assertEquals("Third element not correct", ac[2], 1); + assertEquals("Fourth element not correct", ac[3], 2); + } + + // 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)]; + ac.sort = sort; + ac.refresh(); + ac.sort = null; + + assertEquals("Length is not two", ac.length, 2); + + ac.removeItemAt(0); // still sorted so 2 is removed leaving 1 + assertEquals("Length is not one", ac.length, 1); + assertEquals("First element not correct", ac[0], 1); + + ac.refresh(); + + // still the same + assertEquals("Length is not one", ac.length, 1); + assertEquals("First element not correct", ac[0], 1); + } + + [Test] + public function sortIncludingDuplicates():void + { + addNumbers(); + addNumbers(); + + var sort:Sort = new Sort(); + sort.fields = [new SortField(null, false, true, true)]; + ac.sort = sort; + ac.refresh(); + + assertEquals("Length is not four", ac.length, 4); + + assertEquals("First element not correct", ac[0], 2); + assertEquals("Second element not correct", ac[1], 2); + assertEquals("Third element not correct", ac[2], 1); + assertEquals("Fourth element not correct", ac[3], 1); + } + + } +} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/flex-sdk/blob/192f1e30/frameworks/projects/framework/tests/mx/collections/SortStrings.as ---------------------------------------------------------------------- diff --git a/frameworks/projects/framework/tests/mx/collections/SortStrings.as b/frameworks/projects/framework/tests/mx/collections/SortStrings.as new file mode 100644 index 0000000..f942286 --- /dev/null +++ b/frameworks/projects/framework/tests/mx/collections/SortStrings.as @@ -0,0 +1,240 @@ +package mx.collections { + import mx.collections.ArrayCollection; + import mx.collections.Sort; + import mx.collections.SortField; + + public class SortStrings + { + import org.flexunit.asserts.*; + + protected var ac:ArrayCollection; + + [Before] + public function setUp():void + { + ac = new ArrayCollection(); + } + + [After] + public function tearDown():void + { + ac = null; + } + + protected function addStrings():void + { + ac.addItem("A"); + ac.addItem("B"); + ac.addItem("D"); + ac.addItem("C"); + } + + [Test] + public function nullSort():void + { + addStrings(); + ac.sort = null; + ac.refresh(); + + assertEquals("Length is not four", ac.length, 4); + assertEquals("First element not correct", ac[0], "A"); + assertEquals("Second element not correct", ac[1], "B"); + assertEquals("First element not correct", ac[2], "D"); + assertEquals("Second element not correct", ac[3], "C"); + } + + [Test] + public function emptySort():void + { + addStrings(); + ac.sort = new Sort(); + ac.refresh(); + + assertEquals("Length is not four", ac.length, 4); + assertEquals("First element not correct", ac[0], "A"); + assertEquals("Second element not correct", ac[1], "B"); + assertEquals("First element not correct", ac[2], "C"); + assertEquals("Second element not correct", ac[3], "D"); + } + + [Test] + public function reverseSort():void + { + var sort:Sort = new Sort(); + sort.fields = [new SortField(null, false, true)]; + addStrings(); + ac.sort = sort; + ac.refresh(); + + assertEquals("Length is not four", ac.length, 4); + assertEquals("First element not correct", ac[0], "D"); + assertEquals("Second element not correct", ac[1], "C"); + assertEquals("First element not correct", ac[2], "B"); + assertEquals("Second element not correct", ac[3], "A"); + } + + [Test] + public function forwardSort():void + { + var sort:Sort = new Sort(); + sort.fields = [new SortField()]; + addStrings(); + ac.sort = sort; + ac.refresh(); + + assertEquals("Length is not four", ac.length, 4); + assertEquals("First element not correct", ac[0], "A"); + assertEquals("Second element not correct", ac[1], "B"); + assertEquals("First element not correct", ac[2], "C"); + assertEquals("Second element not correct", ac[3], "D"); + } + + [Test] + public function sortNoRefresh():void + { + var sort:Sort = new Sort(); + sort.fields = [new SortField()]; + addStrings(); + ac.sort = sort; + + // Short should not take effect + assertEquals("Length is not four", ac.length, 4); + assertEquals("First element not correct", ac[0], "A"); + assertEquals("Second element not correct", ac[1], "B"); + assertEquals("First element not correct", ac[2], "D"); + assertEquals("Second element not correct", ac[3], "C"); + } + + [Test] + public function nullSortNoRefresh():void + { + var sort:Sort = new Sort(); + sort.fields = [new SortField()]; + addStrings(); + ac.sort = sort; + ac.refresh(); + ac.sort = null; + + // Sort should be in effect + assertEquals("Length is not four", ac.length, 4); + assertEquals("First element not correct", ac[0], "A"); + assertEquals("Second element not correct", ac[1], "B"); + assertEquals("First element not correct", ac[2], "C"); + assertEquals("Second element not correct", ac[3], "D"); + + ac.refresh(); + + // and back to original + assertEquals("Length is not four", ac.length, 4); + assertEquals("First element not correct", ac[0], "A"); + assertEquals("Second element not correct", ac[1], "B"); + assertEquals("First element not correct", ac[2], "D"); + assertEquals("Second element not correct", ac[3], "C"); + } + + [Test] + public function sortDoubleRefresh():void + { + var sort:Sort = new Sort(); + sort.fields = [new SortField()]; + addStrings(); + ac.sort = sort; + ac.refresh(); + ac.sort = null; + ac.refresh(); + + // Sort should not be in effect + assertEquals("Length is not four", ac.length, 4); + assertEquals("First element not correct", ac[0], "A"); + assertEquals("Second element not correct", ac[1], "B"); + assertEquals("First element not correct", ac[2], "D"); + assertEquals("Second element not correct", ac[3], "C"); + } + + // RTEs in APache flex 4.9.1 + [Test] + public function sortAddAfterNullNoRefresh():void + { + addStrings(); + + var sort:Sort = new Sort(); + sort.fields = [new SortField()]; + ac.sort = sort; + ac.refresh(); + ac.sort = null; + addStrings(); + + // Sort should be in effect and first 4 items sorted + // item added after are not sorted + assertEquals("Length is not eight", ac.length, 8); + assertEquals("First element not correct", ac[0], "A"); + assertEquals("Second element not correct", ac[1], "B"); + assertEquals("First element not correct", ac[2], "C"); + assertEquals("Second element not correct", ac[3], "D"); + assertEquals("First element not correct", ac[4], "A"); + assertEquals("Second element not correct", ac[5], "B"); + assertEquals("First element not correct", ac[6], "D"); + assertEquals("Second element not correct", ac[7], "C"); + + ac.refresh(); + + // and back to being unsorted + assertEquals("Length is not eight", ac.length, 8); + assertEquals("First element not correct", ac[0], "A"); + assertEquals("Second element not correct", ac[1], "B"); + assertEquals("First element not correct", ac[2], "D"); + assertEquals("Second element not correct", ac[3], "C"); + assertEquals("First element not correct", ac[4], "A"); + assertEquals("Second element not correct", ac[5], "B"); + assertEquals("First element not correct", ac[6], "D"); + assertEquals("Second element not correct", ac[7], "C"); + } + + // 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)]; + ac.sort = sort; + ac.refresh(); + ac.sort = null; + + assertEquals("Length is not four", ac.length, 4); + + ac.removeItemAt(0); // still sorted so 2 is removed leaving 1 + assertEquals("Length is not three", ac.length, 3); + assertEquals("First element not correct", ac[0], "B"); + + ac.refresh(); + + assertEquals("Length is not four", ac.length, 3); + assertEquals("First element not correct", ac[0], "A"); + } + + [Test] + public function sortIncludingDuplicates():void + { + addStrings(); + addStrings(); + + var sort:Sort = new Sort(); + sort.fields = [new SortField()]; + ac.sort = sort; + ac.refresh(); + + assertEquals("Length is not eight", ac.length, 8); + assertEquals("First element not correct", ac[0], "A"); + assertEquals("Second element not correct", ac[1], "A"); + assertEquals("First element not correct", ac[2], "B"); + assertEquals("Second element not correct", ac[3], "B"); + assertEquals("First element not correct", ac[4], "C"); + assertEquals("Second element not correct", ac[5], "C"); + assertEquals("First element not correct", ac[6], "D"); + assertEquals("Second element not correct", ac[7], "D"); + } + + } +} \ No newline at end of file
