diff --git a/src/ByPropertyIdArray.php b/src/ByPropertyIdArray.php index 37a7d64c..ce2a6c13 100644 --- a/src/ByPropertyIdArray.php +++ b/src/ByPropertyIdArray.php @@ -2,135 +2,68 @@ namespace Wikibase\DataModel; +use InvalidArgumentException; use OutOfBoundsException; -use RuntimeException; use Wikibase\DataModel\Entity\PropertyId; /** - * Helper for managing objects indexed by property id. - * - * This is a light weight alternative approach to using something - * like GenericArrayObject with the advantages that no extra interface - * is needed and that indexing does not happen automatically. - * - * Lack of automatic indexing means that you will need to call the - * buildIndex method before doing any look-ups. - * - * Since no extra interface is used, the user is responsible for only - * adding objects that have a getPropertyId method that returns either - * a string or integer when called with no arguments. - * - * Objects may be added or moved within the structure. Absolute indices (indices according to the - * flat list of objects) may be specified to add or move objects. These management operations take - * the property grouping into account. Adding or moving objects outside their "property groups" - * shifts the whole group towards that index. - * - * Example of moving an object within its "property group": - * o1 (p1) o1 (p1) - * o2 (p2) /-> o3 (p2) - * o3 (p2) ---> move to index 1 -/ o2 (p2) - * - * Example of moving an object that triggers moving the whole "property group": - * o1 (p1) /-> o3 (p2) - * o2 (p2) | o2 (p2) - * o3 (p2) ---> move to index 0 -/ o1 (p1) + * Helper for managing objects grouped by property id. * * @since 0.2 * - * @licence GNU GPL v2+ - * @author H. Snater < mediawiki@snater.com > + * @license GNU GPL v2+ + * @author Bene* < benestar.wikimedia@gmail.com > */ -class ByPropertyIdArray extends \ArrayObject { +class ByPropertyIdArray { /** - * @since 0.2 - * - * @var array[]|null + * @var ByPropertyIdGrouper */ - private $byId = null; + private $byPropertyIdGrouper; /** - * @see \ArrayObject::__construct - * - * @param array|object $input + * @var PropertyIdProvider[] */ - public function __construct( $input = null ) { - parent::__construct( (array)$input ); - } + private $flatArray; /** - * Builds the index for doing look-ups by property id. - * - * @since 0.2 + * @param PropertyIdProvider[] $propertyIdProviders + * @throws InvalidArgumentException */ - public function buildIndex() { - $this->byId = array(); - - foreach ( $this as $object ) { - $propertyId = $object->getPropertyId()->getSerialization(); - - if ( !array_key_exists( $propertyId, $this->byId ) ) { - $this->byId[$propertyId] = array(); - } + public function __construct( $propertyIdProviders = array() ) { + $this->byPropertyIdGrouper = new ByPropertyIdGrouper( $propertyIdProviders ); + $this->flatArray = array(); - $this->byId[$propertyId][] = $object; + foreach ( $this->byPropertyIdGrouper->getPropertyIds() as $propertyId ) { + $propertyIdProviders = $this->byPropertyIdGrouper->getByPropertyId( $propertyId ); + $this->flatArray = array_merge( $this->flatArray, $propertyIdProviders ); } } /** - * Checks whether id indexed array has been generated. - * @since 0.5 - * - * @throws RuntimeException - */ - private function assertIndexIsBuild() { - if ( $this->byId === null ) { - throw new RuntimeException( 'Index not build, call buildIndex first' ); - } - } - - /** - * Returns the property ids used for indexing. - * * @since 0.2 - * - * @return PropertyId[] - * @throws RuntimeException + * @deprecated since 1.2 */ - public function getPropertyIds() { - $this->assertIndexIsBuild(); - - return array_map( - function( $serializedPropertyId ) { - return new PropertyId( $serializedPropertyId ); - }, - array_keys( $this->byId ) - ); - } + public function buildIndex() {} /** - * Returns the objects featuring the provided property id in the index. - * * @since 0.2 + * @deprecated since 1.2 * * @param PropertyId $propertyId + * @return PropertyIdProvider[] * - * @return object[] - * @throws RuntimeException|OutOfBoundsException + * @throws OutOfBoundsException */ public function getByPropertyId( PropertyId $propertyId ) { - $this->assertIndexIsBuild(); - - if ( !( array_key_exists( $propertyId->getSerialization(), $this->byId ) ) ) { - throw new OutOfBoundsException( 'Property id array key does not exist.' ); - } - - return $this->byId[$propertyId->getSerialization()]; + return $this->byPropertyIdGrouper->getByPropertyId( $propertyId ); } /** * Returns the absolute index of an object or false if the object could not be found. + * * @since 0.5 + * @deprecated since 1.2 * * @param object $object * @return bool|int @@ -138,363 +71,257 @@ public function getByPropertyId( PropertyId $propertyId ) { * @throws RuntimeException */ public function getFlatArrayIndexOfObject( $object ) { - $this->assertIndexIsBuild(); + return array_search( $object, $this->flatArray, true ); + } - $i = 0; - foreach( $this as $o ) { - if( $o === $object ) { - return $i; - } - $i++; - } - return false; + /** + * @since 0.2 + * @deprecated since 1.2 + * + * @return PropertyId[] + */ + public function getPropertyIds() { + return $this->byPropertyIdGrouper->getPropertyIds(); } /** - * Returns the objects in a flat array (using the indexed form for generating the array). - * @since 0.5 + * Returns a list of all PropertyIdProvider instances grouped by their PropertyId. * - * @return object[] + * @since 0.2 * - * @throws RuntimeException + * @return PropertyIdProvider[] */ public function toFlatArray() { - $this->assertIndexIsBuild(); - - $array = array(); - foreach( $this->byId as $objects ) { - $array = array_merge( $array, $objects ); - } - return $array; + return $this->flatArray; } /** - * Returns the absolute numeric indices of objects featuring the same property id. - * @since 0.5 + * Returns the index of the given PropertyIdPovider in the flat array. * - * @param PropertyId $propertyId - * @return int[] + * @since 1.2 * - * @throws RuntimeException + * @param PropertyIdProvider $propertyIdProvider + * @return int + * + * @throws OutOfBoundsException */ - private function getFlatArrayIndices( PropertyId $propertyId ) { - $this->assertIndexIsBuild(); - - $propertyIndices = array(); - $i = 0; - - foreach( $this->byId as $serializedPropertyId => $objects ) { - if( $serializedPropertyId === $propertyId->getSerialization() ) { - $propertyIndices = range( $i, $i + count( $objects ) - 1 ); - break; - } else { - $i += count( $objects ); - } + public function getIndex( PropertyIdProvider $propertyIdProvider ) { + $index = array_search( $propertyIdProvider, $this->flatArray, true ); + + if ( $index === false ) { + throw new OutOfBoundsException( 'The given PropertyIdProvider was not found.' ); } - return $propertyIndices; + return $index; } /** - * Moves an object within its "property group". - * @since 0.5 + * Adds the given PropertyIdProvider to the array at the given index. * - * @param object $object - * @param int $toIndex Absolute index within a "property group". + * @since 0.2 * + * @param PropertyIdProvider $propertyIdProvider + * @param int $index + * + * @throws InvalidArgumentException * @throws OutOfBoundsException */ - private function moveObjectInPropertyGroup( $object, $toIndex ) { - $currentIndex = $this->getFlatArrayIndexOfObject( $object ); - - if( $toIndex === $currentIndex ) { - return; - } - - $propertyId = $object->getPropertyId(); + public function addObjectAtIndex( PropertyIdProvider $propertyIdProvider, $index ) { + $this->assertValidIndex( $index, false ); - $numericIndices = $this->getFlatArrayIndices( $propertyId ); - $lastIndex = $numericIndices[count( $numericIndices ) - 1]; + $groupIndices = $this->getFlatArrayGroupIndices(); + $propertyId = $propertyIdProvider->getPropertyId(); + $idSerialization = $propertyId->getSerialization(); - if( $toIndex > $lastIndex + 1 || $toIndex < $numericIndices[0] ) { - throw new OutOfBoundsException( 'Object cannot be moved to ' . $toIndex ); - } - - if( $toIndex >= $lastIndex ) { - $this->moveObjectToEndOfPropertyGroup( $object ); + if ( isset( $groupIndices[$idSerialization] ) ) { + $groupIndex = $groupIndices[$idSerialization]; + $count = count( $this->byPropertyIdGrouper->getByPropertyId( $propertyId ) ); } else { - $this->removeObject( $object ); - - $propertyGroup = array_combine( - $this->getFlatArrayIndices( $propertyId ), - $this->getByPropertyId( $propertyId ) - ); + $groupIndex = 0; + $count = 0; + } - $insertBefore = $propertyGroup[$toIndex]; - $this->insertObjectAtIndex( $object, $this->getFlatArrayIndexOfObject( $insertBefore ) ); + // if not inside of group also move property group + if ( $index < $groupIndex || $groupIndex + $count <= $index ) { + // find real index to insert + $index = $index === 0 ? 0 : $this->findNextIndex( $index ); + $this->moveGroupInFlatArray( $groupIndex, $count, $index ); } + + $this->addtoFlatArray( $propertyIdProvider, $index ); + $this->byPropertyIdGrouper = new ByPropertyIdGrouper( $this->flatArray ); } /** - * Moves an object to the end of its "property group". - * @since 0.5 + * Removes the PropertyIdProvider at the given index and returns it. * - * @param object $object + * @since 1.2 + * + * @param int $index + * @return PropertyIdProvider + * + * @throws InvalidArgumentException + * @throws OutOfBoundsException */ - private function moveObjectToEndOfPropertyGroup( $object ) { - $this->removeObject( $object ); - - /** @var PropertyId $propertyId */ - $propertyId = $object->getPropertyId(); - $propertyIdSerialization = $propertyId->getSerialization(); + public function removeAtIndex( $index ) { + $this->assertValidIndex( $index ); - $propertyGroup = in_array( $propertyIdSerialization, $this->getPropertyIds() ) - ? $this->getByPropertyId( $propertyId ) - : array(); + $object = $this->removeFromFlatArray( $index ); + $this->byPropertyIdGrouper = new ByPropertyIdGrouper( $this->flatArray ); - $propertyGroup[] = $object; - $this->byId[$propertyIdSerialization] = $propertyGroup; - - $this->exchangeArray( $this->toFlatArray() ); + return $object; } /** - * Removes an object from the array structures. - * @since 0.5 + * Removes the given PropertyIdProvider and returns it. * - * @param object $object + * @since 1.2 + * + * @param PropertyIdProvider $propertyIdProvider + * @return PropertyIdProvider + * + * @throws InvalidArgumentException + * @throws OutOfBoundsException */ - private function removeObject( $object ) { - $flatArray = $this->toFlatArray(); - $this->exchangeArray( $flatArray ); - $this->offsetUnset( array_search( $object, $flatArray ) ); - $this->buildIndex(); + public function removeObject( PropertyIdProvider $propertyIdProvider ) { + return $this->removeAtIndex( $this->getIndex( $propertyIdProvider ) ); } /** - * Inserts an object at a specific index. - * @since 0.5 + * Moves a PropertyIdProvider from the old to the new index and returns it. * - * @param object $object - * @param int $index Absolute index within the flat list of objects. + * @since 1.2 + * + * @param int $oldIndex + * @param int $newIndex + * @return PropertyIdProvider + * + * @throws InvalidArgumentException + * @throws OutOfBoundsException */ - private function insertObjectAtIndex( $object, $index ) { - $flatArray = $this->toFlatArray(); + public function moveToIndex( $oldIndex, $newIndex ) { + $this->assertValidIndex( $oldIndex ); + $this->assertValidIndex( $newIndex ); - $this->exchangeArray( array_merge( - array_slice( $flatArray, 0, $index ), - array( $object ), - array_slice( $flatArray, $index ) - ) ); + $object = $this->removeAtIndex( $oldIndex ); + $this->addObjectAtIndex( $object, $newIndex ); - $this->buildIndex(); + return $object; } /** - * @since 0.5 + * Moves the given PropertyIdProvider to the new index and returns it. * - * @param PropertyId $propertyId - * @param int $toIndex + * @since 0.2 + * + * @param PropertyIdProvider $propertyIdProvider + * @param int $index + * @return PropertyIdProvider + * + * @throws InvalidArgumentException + * @throws OutOfBoundsException */ - private function movePropertyGroup( PropertyId $propertyId, $toIndex ) { - if( $this->getPropertyGroupIndex( $propertyId ) === $toIndex ) { - return; - } - - /** - * @var PropertyId - */ - $insertBefore = null; - - $oldIndex = $this->getPropertyGroupIndex( $propertyId ); - $byIdClone = $this->byId; - - // Remove "property group" to calculate the groups new index: - unset( $this->byId[$propertyId->getSerialization()] ); - - if( $toIndex > $oldIndex ) { - // If the group shall be moved towards the bottom, the number of objects within the - // group needs to be subtracted from the absolute toIndex: - $toIndex -= count( $byIdClone[$propertyId->getSerialization()] ); - } - - foreach( $this->getPropertyIds() as $pId ) { - // Accepting other than the exact index by using <= letting the "property group" "latch" - // in the next slot. - if( $toIndex <= $this->getPropertyGroupIndex( $pId ) ) { - $insertBefore = $pId; - break; - } - } - - $serializedPropertyId = $propertyId->getSerialization(); - $this->byId = array(); - - foreach( $byIdClone as $serializedPId => $objects ) { - $pId = new PropertyId( $serializedPId ); - if( $pId->equals( $propertyId ) ) { - continue; - } elseif( $pId->equals( $insertBefore ) ) { - $this->byId[$serializedPropertyId] = $byIdClone[$serializedPropertyId]; - } - $this->byId[$serializedPId] = $objects; - } - - if( is_null( $insertBefore ) ) { - $this->byId[$serializedPropertyId] = $byIdClone[$serializedPropertyId]; - } - - $this->exchangeArray( $this->toFlatArray() ); + public function moveObjectToIndex( PropertyIdProvider $propertyIdProvider, $index ) { + return $this->moveToIndex( $this->getIndex( $propertyIdProvider ), $index ); } /** - * Returns the index of a "property group" (the first object in the flat array that features - * the specified property). Returns false if property id could not be found. - * @since 0.5 + * Adds the object at the given index. + * @see array_splice * - * @param PropertyId $propertyId - * @return bool|int + * @param PropertyIdProvider $propertyIdProvider + * @param int $index */ - private function getPropertyGroupIndex( PropertyId $propertyId ) { - $i = 0; - - foreach( $this->byId as $serializedPropertyId => $objects ) { - $pId = new PropertyId( $serializedPropertyId ); - if( $pId->equals( $propertyId ) ) { - return $i; - } - $i += count( $objects ); - } - - return false; + private function addtoFlatArray( PropertyIdProvider $propertyIdProvider, $index ) { + array_splice( $this->flatArray, $index, 0, array( $propertyIdProvider ) ); } /** - * Moves an existing object to a new index. Specifying an index outside the object's "property - * group" will move the object to the edge of the "property group" and shift the whole group - * to achieve the designated index for the object to move. - * @since 0.5 + * Removes the object at the given index and returns it. + * @see array_splice * - * @param object $object - * @param int $toIndex Absolute index where to move the object to. + * @param int $index + * @return PropertyIdProvider + */ + private function removeFromFlatArray( $index ) { + $objects = array_splice( $this->flatArray, $index, 1 ); + return $objects[0]; + } + + /** + * Moves a list of objects with the given length from the start to the target index. + * @see array_splice * - * @throws RuntimeException|OutOfBoundsException + * @param int $start + * @param int $length + * @param int $target */ - public function moveObjectToIndex( $object, $toIndex ) { - $this->assertIndexIsBuild(); - - if( !in_array( $object, $this->toFlatArray() ) ) { - throw new OutOfBoundsException( 'Object not present in array' ); - } elseif( $toIndex < 0 || $toIndex > count( $this ) ) { - throw new OutOfBoundsException( 'Specified index is out of bounds' ); - } elseif( $this->getFlatArrayIndexOfObject( $object ) === $toIndex ) { - return; + private function moveGroupInFlatArray( $start, $length, $target ) { + // make sure we do not exceed the limits + if ( $start < $target ) { + $target = $target - $length; } - // Determine whether to simply reindex the object within its "property group": - $propertyIndices = $this->getFlatArrayIndices( $object->getPropertyId() ); + $objects = array_splice( $this->flatArray, $start, $length ); + array_splice( $this->flatArray, $target, 0, $objects ); + } - if( in_array( $toIndex, $propertyIndices ) ) { - $this->moveObjectInPropertyGroup( $object, $toIndex ); - } else { - $edgeIndex = ( $toIndex <= $propertyIndices[0] ) - ? $propertyIndices[0] - : $propertyIndices[count( $propertyIndices ) - 1]; + /** + * Finds the next index in the flat array which starts a new PropertyId group. + * + * @param int $index + * @return int + */ + private function findNextIndex( $index ) { + $groupIndices = $this->getFlatArrayGroupIndices(); - $this->moveObjectInPropertyGroup( $object, $edgeIndex ); - $this->movePropertyGroup( $object->getPropertyId(), $toIndex ); + foreach ( $groupIndices as $groupIndex ) { + if ( $groupIndex >= $index ) { + return $groupIndex; + } } - $this->exchangeArray( $this->toFlatArray() ); + return count( $this->flatArray ); } /** - * Adds an object at a specific index. If no index is specified, the object will be append to - * the end of its "property group" or - if no objects featuring the same property exist - to the - * absolute end of the array. - * Specifying an index outside a "property group" will place the new object at the specified - * index with the existing "property group" objects being shifted towards the new new object. - * @since 0.5 - * - * @param object $object - * @param int $index Absolute index where to place the new object. + * Finds all indeces where a new PropertyId group starts. * - * @throws RuntimeException + * @return int[] */ - public function addObjectAtIndex( $object, $index = null ) { - $this->assertIndexIsBuild(); - - $propertyId = $object->getPropertyId(); - $validIndices = $this->getFlatArrayIndices( $propertyId ); - - if( count( $this ) === 0 ) { - // Array is empty, just append object. - $this->append( $object ); - - } elseif( count( $validIndices ) === 0 ) { - // No objects featuring that property exist. The object may be inserted at a place - // between existing "property groups". - $this->append( $object ); - if( !is_null( $index ) ) { - $this->buildIndex(); - $this->moveObjectToIndex( $object, $index ); - } + private function getFlatArrayGroupIndices() { + $indices = array(); + $index = 0; - } else { - // Objects featuring the same property as the object which is about to be added already - // exist in the array. - $this->addObjectToPropertyGroup( $object, $index ); + foreach ( $this->byPropertyIdGrouper->getPropertyIds() as $propertyId ) { + $indices[$propertyId->getSerialization()] = $index; + $index += count( $this->byPropertyIdGrouper->getByPropertyId( $propertyId ) ); } - $this->buildIndex(); + return $indices; } - /* - * Adds an object to an existing property group at the specified absolute index. - * @since 0.5 + /** + * Asserts that the given paramter is a valid index. * - * @param object $object * @param int $index + * @param bool $checkForEquality * + * @throws InvalidArgumentException * @throws OutOfBoundsException */ - private function addObjectToPropertyGroup( $object, $index = null ) { - /** @var PropertyId $propertyId */ - $propertyId = $object->getPropertyId(); - $validIndices = $this->getFlatArrayIndices( $propertyId ); - - if( count( $validIndices ) === 0 ) { - throw new OutOfBoundsException( 'No objects featuring the object\'s property exist' ); + private function assertValidIndex( $index, $checkForEquality = true ) { + if ( !is_int( $index ) ) { + throw new InvalidArgumentException( 'Only integer indices are supported.' ); } - // Add index to allow placing object after the last object of the "property group": - $validIndices[] = $validIndices[count( $validIndices ) - 1] + 1; - - if( is_null( $index ) ) { - // If index is null, append object to "property group". - $index = $validIndices[count( $validIndices ) - 1]; + if ( $index < 0 || $index > count( $this->flatArray ) ) { + throw new OutOfBoundsException( 'The index exceeds the array dimensions.' ); } - if( in_array( $index, $validIndices ) ) { - // Add object at index within "property group". - $this->byId[$propertyId->getSerialization()][] = $object; - $this->exchangeArray( $this->toFlatArray() ); - $this->moveObjectToIndex( $object, $index ); - - } else { - // Index is out of the "property group"; The whole group needs to be moved. - $this->movePropertyGroup( $propertyId, $index ); - - // Move new object to the edge of the "property group" to receive its designated - // index: - if( $index < $validIndices[0] ) { - array_unshift( $this->byId[$propertyId->getSerialization()], $object ); - } else { - $this->byId[$propertyId->getSerialization()][] = $object; - } + if ( $index === count( $this->flatArray ) && $checkForEquality ) { + throw new OutOfBoundsException( 'The index exceeds the array dimensions.' ); } - - $this->exchangeArray( $this->toFlatArray() ); } } diff --git a/tests/unit/ByPropertyIdArrayTest.php b/tests/unit/ByPropertyIdArrayTest.php index 15dfa64f..f31653f9 100644 --- a/tests/unit/ByPropertyIdArrayTest.php +++ b/tests/unit/ByPropertyIdArrayTest.php @@ -28,23 +28,6 @@ */ class ByPropertyIdArrayTest extends \PHPUnit_Framework_TestCase { - public function testArrayObjectNotConstructedFromObject() { - $claim1 = new Claim( new PropertyNoValueSnak( 1 ) ); - $claim1->setGuid( '1' ); - $claim2 = new Claim( new PropertyNoValueSnak( 2 ) ); - $claim2->setGuid( '2' ); - - $claims = new Claims(); - $claims->append( $claim1 ); - - $byPropertyIdArray = new ByPropertyIdArray( $claims ); - // According to the documentation append() "cannot be called when the ArrayObject was - // constructed from an object." This test makes sure it was not constructed from an object. - $byPropertyIdArray->append( $claim2 ); - - $this->assertCount( 2, $byPropertyIdArray ); - } - /** * Returns an accessible ReflectionMethod of ByPropertyIdArray. * @@ -206,20 +189,6 @@ public function testGetByNotSetIdThrowsException() { $indexedArray->getByPropertyId( PropertyId::newFromNumber( 9000 ) ); } - public function testNotBuildExceptionIsThrownForByPropertyId() { - $indexedArray = new ByPropertyIdArray(); - - $this->setExpectedException( 'RuntimeException' ); - $indexedArray->getByPropertyId( PropertyId::newFromNumber( 9000 ) ); - } - - public function testNotBuildExceptionIsThrownForGetPropertyIds() { - $indexedArray = new ByPropertyIdArray(); - - $this->setExpectedException( 'RuntimeException' ); - $indexedArray->getPropertyIds(); - } - /** * @dataProvider listProvider * @param array $objects @@ -257,43 +226,43 @@ public function moveProvider() { $argLists[] = array( $c, $c[0], 0, $c ); $argLists[] = array( $c, $c[0], 1, array( $c[1], $c[0], $c[2], $c[3], $c[4], $c[5] ) ); - $argLists[] = array( $c, $c[0], 2, array( $c[1], $c[0], $c[2], $c[3], $c[4], $c[5] ) ); + $argLists[] = array( $c, $c[0], 2, array( $c[2], $c[3], $c[4], $c[1], $c[0], $c[5] ) ); $argLists[] = array( $c, $c[0], 3, array( $c[2], $c[3], $c[4], $c[1], $c[0], $c[5] ) ); $argLists[] = array( $c, $c[0], 4, array( $c[2], $c[3], $c[4], $c[1], $c[0], $c[5] ) ); - $argLists[] = array( $c, $c[0], 5, array( $c[2], $c[3], $c[4], $c[1], $c[0], $c[5] ) ); - $argLists[] = array( $c, $c[0], 6, array( $c[2], $c[3], $c[4], $c[5], $c[1], $c[0] ) ); + $argLists[] = array( $c, $c[0], 5, array( $c[2], $c[3], $c[4], $c[5], $c[1], $c[0] ) ); + #$argLists[] = array( $c, $c[0], 6, array( $c[2], $c[3], $c[4], $c[5], $c[1], $c[0] ) ); $argLists[] = array( $c, $c[1], 0, array( $c[1], $c[0], $c[2], $c[3], $c[4], $c[5] ) ); $argLists[] = array( $c, $c[1], 1, $c ); - $argLists[] = array( $c, $c[1], 2, $c ); + $argLists[] = array( $c, $c[1], 2, array( $c[2], $c[3], $c[4], $c[0], $c[1], $c[5] ) ); $argLists[] = array( $c, $c[1], 3, array( $c[2], $c[3], $c[4], $c[0], $c[1], $c[5] ) ); // $argLists[] = array( $c, $c[1], 4, array( $c[2], $c[3], $c[4], $c[0], $c[1], $c[5] ) ); - $argLists[] = array( $c, $c[1], 5, array( $c[2], $c[3], $c[4], $c[0], $c[1], $c[5] ) ); - $argLists[] = array( $c, $c[1], 6, array( $c[2], $c[3], $c[4], $c[5], $c[0], $c[1] ) ); + $argLists[] = array( $c, $c[1], 5, array( $c[2], $c[3], $c[4], $c[5], $c[0], $c[1] ) ); + #$argLists[] = array( $c, $c[1], 6, array( $c[2], $c[3], $c[4], $c[5], $c[0], $c[1] ) ); $argLists[] = array( $c, $c[2], 0, array( $c[2], $c[3], $c[4], $c[0], $c[1], $c[5] ) ); $argLists[] = array( $c, $c[2], 1, $c ); $argLists[] = array( $c, $c[2], 2, $c ); $argLists[] = array( $c, $c[2], 3, array( $c[0], $c[1], $c[3], $c[2], $c[4], $c[5] ) ); $argLists[] = array( $c, $c[2], 4, array( $c[0], $c[1], $c[3], $c[4], $c[2], $c[5] ) ); - $argLists[] = array( $c, $c[2], 5, array( $c[0], $c[1], $c[3], $c[4], $c[2], $c[5] ) ); - $argLists[] = array( $c, $c[2], 6, array( $c[0], $c[1], $c[5], $c[3], $c[4], $c[2] ) ); + $argLists[] = array( $c, $c[2], 5, array( $c[0], $c[1], $c[5], $c[3], $c[4], $c[2] ) ); + #$argLists[] = array( $c, $c[2], 6, array( $c[0], $c[1], $c[5], $c[3], $c[4], $c[2] ) ); $argLists[] = array( $c, $c[3], 0, array( $c[3], $c[2], $c[4], $c[0], $c[1], $c[5] ) ); $argLists[] = array( $c, $c[3], 1, array( $c[0], $c[1], $c[3], $c[2], $c[4], $c[5] ) ); $argLists[] = array( $c, $c[3], 2, array( $c[0], $c[1], $c[3], $c[2], $c[4], $c[5] ) ); $argLists[] = array( $c, $c[3], 3, $c ); $argLists[] = array( $c, $c[3], 4, array( $c[0], $c[1], $c[2], $c[4], $c[3], $c[5] ) ); - $argLists[] = array( $c, $c[3], 5, array( $c[0], $c[1], $c[2], $c[4], $c[3], $c[5] ) ); - $argLists[] = array( $c, $c[3], 6, array( $c[0], $c[1], $c[5], $c[2], $c[4], $c[3] ) ); + $argLists[] = array( $c, $c[3], 5, array( $c[0], $c[1], $c[5], $c[2], $c[4], $c[3] ) ); + #$argLists[] = array( $c, $c[3], 6, array( $c[0], $c[1], $c[5], $c[2], $c[4], $c[3] ) ); $argLists[] = array( $c, $c[4], 0, array( $c[4], $c[2], $c[3], $c[0], $c[1], $c[5] ) ); $argLists[] = array( $c, $c[4], 1, array( $c[0], $c[1], $c[4], $c[2], $c[3], $c[5] ) ); $argLists[] = array( $c, $c[4], 2, array( $c[0], $c[1], $c[4], $c[2], $c[3], $c[5] ) ); $argLists[] = array( $c, $c[4], 3, array( $c[0], $c[1], $c[2], $c[4], $c[3], $c[5] ) ); $argLists[] = array( $c, $c[4], 4, $c ); - $argLists[] = array( $c, $c[4], 5, $c ); - $argLists[] = array( $c, $c[4], 6, array( $c[0], $c[1], $c[5], $c[2], $c[3], $c[4] ) ); + $argLists[] = array( $c, $c[4], 5, array( $c[0], $c[1], $c[5], $c[2], $c[3], $c[4] ) ); + #$argLists[] = array( $c, $c[4], 6, array( $c[0], $c[1], $c[5], $c[2], $c[3], $c[4] ) ); $argLists[] = array( $c, $c[5], 0, array( $c[5], $c[0], $c[1], $c[2], $c[3], $c[4] ) ); $argLists[] = array( $c, $c[5], 1, array( $c[0], $c[1], $c[5], $c[2], $c[3], $c[4] ) ); @@ -301,7 +270,7 @@ public function moveProvider() { $argLists[] = array( $c, $c[5], 3, $c ); $argLists[] = array( $c, $c[5], 4, $c ); $argLists[] = array( $c, $c[5], 5, $c ); - $argLists[] = array( $c, $c[5], 6, $c ); + #$argLists[] = array( $c, $c[5], 6, $c ); return $argLists; } @@ -324,12 +293,7 @@ public function testMoveObjectToIndex( $indexedArray->moveObjectToIndex( $object, $toIndex ); - // Not using $indexedArray->toFlatArray() here to test whether native array has been - // exchanged: - $reindexedArray = array(); - foreach( $indexedArray as $o ) { - $reindexedArray[] = $o; - } + $reindexedArray = $indexedArray->toFlatArray(); $this->assertEquals( $objectsDestination, $reindexedArray ); } @@ -359,8 +323,7 @@ public function addProvider() { $argLists = array(); - $argLists[] = array( array(), $c[0], null, array( $c[0] ) ); - $argLists[] = array( array(), $c[0], 1, array( $c[0] ) ); + $argLists[] = array( array(), $c[0], 0, array( $c[0] ) ); $argLists[] = array( array( $c[0] ), $c[2], 0, array( $c[2], $c[0] ) ); $argLists[] = array( array( $c[2], $c[1] ), $c[0], 0, array( $c[0], $c[1], $c[2] ) ); $argLists[] = array( @@ -378,8 +341,8 @@ public function addProvider() { $argLists[] = array( array( $c[0], $c[1], $c[2], $c[3], $c[5] ), $c[4], - null, - array( $c[0], $c[1], $c[2], $c[3], $c[4], $c[5] ) + 0, + array( $c[4], $c[2], $c[3], $c[0], $c[1], $c[5] ) ); return $argLists;