Add new test, fix replaceObjectsAtIndexes:withObjects:

This commit is contained in:
Gregory John Casamento 2019-06-13 06:00:40 -04:00
parent 0a2f885456
commit 3278eaa2ca
2 changed files with 48 additions and 7 deletions

View file

@ -64,7 +64,6 @@ static Class NSOrderedSet_concrete_class;
static Class NSMutableOrderedSet_concrete_class; static Class NSMutableOrderedSet_concrete_class;
static SEL addSel; static SEL addSel;
static SEL appSel;
static SEL countSel; static SEL countSel;
static SEL eqSel; static SEL eqSel;
static SEL oaiSel; static SEL oaiSel;
@ -90,7 +89,6 @@ static SEL rlSel;
[self setVersion: 1]; [self setVersion: 1];
addSel = @selector(addObject:); addSel = @selector(addObject:);
appSel = @selector(appendString:);
countSel = @selector(count); countSel = @selector(count);
eqSel = @selector(isEqual:); eqSel = @selector(isEqual:);
oaiSel = @selector(objectAtIndex:); oaiSel = @selector(objectAtIndex:);
@ -1575,15 +1573,36 @@ static SEL rlSel;
- (void) replaceObjectsAtIndexes: (NSIndexSet *)indexes - (void) replaceObjectsAtIndexes: (NSIndexSet *)indexes
withObjects: (NSArray *)objects withObjects: (NSArray *)objects
{ {
NSUInteger count = [indexes count]; NSUInteger count = [indexes count], i = 0;
NSUInteger indexArray[count]; NSUInteger indexArray[count];
NSUInteger c = [self count];
NSRange range = NSMakeRange(0,c);
GS_BEGINIDBUF(objs, count);
// Get the indexes
[indexes getIndexes: indexArray [indexes getIndexes: indexArray
maxCount: count maxCount: count
inIndexRange: NULL]; inIndexRange: NULL];
[self _removeObjectsFromIndices: indexArray // Get the objects from this set
numIndices: count]; [self getObjects: objs range: range];
// Iterate over the indexes and replace the objs
for (i = 0; i < count; i++)
{
id obj = [objects objectAtIndex: i];
NSUInteger indx = indexArray[i];
objs[indx] = obj;
}
// Remove all objects in this set...
[self removeAllObjects];
// Rebuild set...
[self addObjects: objs count: c];
GS_ENDIDBUF();
} }
- (void) replaceObjectsInRange: (NSRange)aRange - (void) replaceObjectsInRange: (NSRange)aRange

View file

@ -202,6 +202,28 @@ int main()
[[mutableTest5 objectAtIndex: 2] isEqual:@"Now"] == YES, [[mutableTest5 objectAtIndex: 2] isEqual:@"Now"] == YES,
"Exchanges indexes properly"); "Exchanges indexes properly");
//NSLog(@"RESULT: %@",mutableTest4); //NSLog(@"RESULT: %@",mutableTest4);
mutableTest4 = [NSMutableOrderedSet orderedSet];
[mutableTest4 addObject:@"Now"];
[mutableTest4 addObject:@"is"];
[mutableTest4 addObject:@"the"];
[mutableTest4 addObject:@"time"];
[mutableTest4 addObject:@"for"];
[mutableTest4 addObject:@"all"];
[mutableTest4 addObject:@"Good"];
[mutableTest4 addObject:@"men"];
[mutableTest4 addObject:@"to"];
[mutableTest4 addObject:@"come to"];
[mutableTest4 addObject:@"the aid"];
[mutableTest4 addObject:@"of their country"];
NSMutableIndexSet *is = [NSMutableIndexSet indexSetWithIndex:6];
[is addIndex: 9];
NSMutableArray *array = [NSMutableArray arrayWithObjects:@"Horrible", @"Flee From", nil];
[mutableTest4 replaceObjectsAtIndexes: is
withObjects: array];
[testObjs addObject: mutableTest4];
PASS([[mutableTest4 objectAtIndex: 9] isEqual:@"Flee From"] == YES,
"replaceObjectsAtIndexes: adds to correct indexes");
test_NSObject(@"NSOrderedSet", testObjs); test_NSObject(@"NSOrderedSet", testObjs);
test_NSCoding(testObjs); test_NSCoding(testObjs);