Index: new_tests/Makefile ================================================================== --- new_tests/Makefile +++ new_tests/Makefile @@ -15,10 +15,12 @@ SRCS = OFArrayTests.m \ OFCharacterSetTests.m \ OFColorTests.m \ OFConcreteArrayTests.m \ OFConcreteMutableArrayTests.m \ + OFConcreteMutableSetTests.m \ + OFConcreteSetTests.m \ OFCryptographicHashTests.m \ OFDateTests.m \ OFHMACTests.m \ OFINIFileTests.m \ OFIRITests.m \ @@ -25,14 +27,16 @@ OFInvocationTests.m \ OFJSONTests.m \ OFMatrix4x4Tests.m \ OFMethodSignatureTests.m \ OFMutableArrayTests.m \ + OFMutableSetTests.m \ OFNumberTests.m \ OFPBKDF2Tests.m \ OFPropertyListTests.m \ OFScryptTests.m \ + OFSetTests.m \ ${USE_SRCS_PLUGINS} \ ${USE_SRCS_SOCKETS} \ ${USE_SRCS_SUBPROCESSES} \ ${USE_SRCS_THREADS} \ testfile_bin.m \ ADDED new_tests/OFConcreteMutableSetTests.m Index: new_tests/OFConcreteMutableSetTests.m ================================================================== --- new_tests/OFConcreteMutableSetTests.m +++ new_tests/OFConcreteMutableSetTests.m @@ -0,0 +1,63 @@ +/* + * Copyright (c) 2008-2024 Jonathan Schleifer + * + * All rights reserved. + * + * This file is part of ObjFW. It may be distributed under the terms of the + * Q Public License 1.0, which can be found in the file LICENSE.QPL included in + * the packaging of this file. + * + * Alternatively, it may be distributed under the terms of the GNU General + * Public License, either version 2 or 3, which can be found in the file + * LICENSE.GPLv2 or LICENSE.GPLv3 respectively included in the packaging of this + * file. + */ + +#include "config.h" + +#import "OFMutableSetTests.h" + +#import "OFConcreteMutableSet.h" + +@interface OFConcreteMutableSetTests: OFMutableSetTests +@end + +@implementation OFConcreteMutableSetTests +- (Class)setClass +{ + return [OFConcreteMutableSet class]; +} + +- (void)testDetectMutationDuringEnumeration +{ + OFEnumerator *enumerator = [_mutableSet objectEnumerator]; + + [_mutableSet removeObject: @"foo"]; + + OTAssertThrowsSpecific([enumerator nextObject], + OFEnumerationMutationException); +} + +- (void)testDetectMutationDuringFastEnumeration +{ + bool detected = false; + @try { + for (OFString *object in _mutableSet) + [_mutableSet removeObject: object]; + } @catch (OFEnumerationMutationException *e) { + detected = true; + } + OTAssertTrue(detected); +} + +#ifdef OF_HAVE_BLOCKS +- (void)testDetectMutationDuringEnumerateObjectsUsingBlock +{ + OTAssertThrowsSpecific( + [_mutableSet enumerateObjectsUsingBlock: ^ (id object, bool *stop) { + [_mutableSet removeObject: object]; + }], + OFEnumerationMutationException); +} +#endif +@end ADDED new_tests/OFConcreteSetTests.m Index: new_tests/OFConcreteSetTests.m ================================================================== --- new_tests/OFConcreteSetTests.m +++ new_tests/OFConcreteSetTests.m @@ -0,0 +1,30 @@ +/* + * Copyright (c) 2008-2024 Jonathan Schleifer + * + * All rights reserved. + * + * This file is part of ObjFW. It may be distributed under the terms of the + * Q Public License 1.0, which can be found in the file LICENSE.QPL included in + * the packaging of this file. + * + * Alternatively, it may be distributed under the terms of the GNU General + * Public License, either version 2 or 3, which can be found in the file + * LICENSE.GPLv2 or LICENSE.GPLv3 respectively included in the packaging of this + * file. + */ + +#include "config.h" + +#import "OFSetTests.h" + +#import "OFConcreteSet.h" + +@interface OFConcreteSetTests: OFSetTests +@end + +@implementation OFConcreteSetTests +- (Class)setClass +{ + return [OFConcreteSet class]; +} +@end Index: new_tests/OFIRITests.m ================================================================== --- new_tests/OFIRITests.m +++ new_tests/OFIRITests.m @@ -315,11 +315,11 @@ OTAssertEqualObjects(_IRI[9].fragment, @"frag"); } - (void)testCopy { - OTAssertEqualObjects(_IRI[0], [[_IRI[0] copy] autorelease]); + OTAssertEqualObjects([[_IRI[0] copy] autorelease], _IRI[0]); } - (void)testIsEqual { OTAssertEqualObjects(_IRI[0], [OFIRI IRIWithString: IRI0String]); Index: new_tests/OFMatrix4x4Tests.m ================================================================== --- new_tests/OFMatrix4x4Tests.m +++ new_tests/OFMatrix4x4Tests.m @@ -76,15 +76,24 @@ { 0, 0, 1, 0 }, { 0, 0, 0, 1 } }])); } -/* TODO: testHash */ +- (void)testHash +{ + OTAssertEqual([[OFMatrix4x4 identityMatrix] hash], + [([OFMatrix4x4 matrixWithValues: (const float [4][4]){ + { 1, 0, 0, 0 }, + { 0, 1, 0, 0 }, + { 0, 0, 1, 0 }, + { 0, 0, 0, 1 } + }]) hash]); +} - (void)testCopy { - OTAssertEqualObjects(_matrix, [[_matrix copy] autorelease]); + OTAssertEqualObjects([[_matrix copy] autorelease], _matrix); } - (void)testMultiplyWithMatrix { OFMatrix4x4 *matrix; ADDED new_tests/OFMutableSetTests.h Index: new_tests/OFMutableSetTests.h ================================================================== --- new_tests/OFMutableSetTests.h +++ new_tests/OFMutableSetTests.h @@ -0,0 +1,22 @@ +/* + * Copyright (c) 2008-2024 Jonathan Schleifer + * + * All rights reserved. + * + * This file is part of ObjFW. It may be distributed under the terms of the + * Q Public License 1.0, which can be found in the file LICENSE.QPL included in + * the packaging of this file. + * + * Alternatively, it may be distributed under the terms of the GNU General + * Public License, either version 2 or 3, which can be found in the file + * LICENSE.GPLv2 or LICENSE.GPLv3 respectively included in the packaging of this + * file. + */ + +#import "OFSetTests.h" + +@interface OFMutableSetTests: OFSetTests +{ + OFMutableSet *_mutableSet; +} +@end ADDED new_tests/OFMutableSetTests.m Index: new_tests/OFMutableSetTests.m ================================================================== --- new_tests/OFMutableSetTests.m +++ new_tests/OFMutableSetTests.m @@ -0,0 +1,184 @@ +/* + * Copyright (c) 2008-2024 Jonathan Schleifer + * + * All rights reserved. + * + * This file is part of ObjFW. It may be distributed under the terms of the + * Q Public License 1.0, which can be found in the file LICENSE.QPL included in + * the packaging of this file. + * + * Alternatively, it may be distributed under the terms of the GNU General + * Public License, either version 2 or 3, which can be found in the file + * LICENSE.GPLv2 or LICENSE.GPLv3 respectively included in the packaging of this + * file. + */ + +#include "config.h" + +#import "OFMutableSetTests.h" + +@interface CustomMutableSet: OFMutableSet +{ + OFMutableSet *_set; +} +@end + +@implementation OFMutableSetTests +- (Class)setClass +{ + return [CustomMutableSet class]; +} + +- (void)setUp +{ + [super setUp]; + + _mutableSet = [[OFMutableSet alloc] + initWithObjects: @"foo", @"bar", @"baz", nil]; +} + +- (void)dealloc +{ + [_mutableSet release]; + + [super dealloc]; +} + +- (void)testAddObject +{ + [_mutableSet addObject: @"x"]; + + OTAssertEqualObjects(_mutableSet, + ([OFSet setWithObjects: @"foo", @"bar", @"baz", @"x", nil])); +} + +- (void)testRemoveObject +{ + [_mutableSet removeObject: @"foo"]; + + OTAssertEqualObjects(_mutableSet, + ([OFSet setWithObjects: @"bar", @"baz", nil])); +} + +- (void)testMinusSet +{ + [_mutableSet minusSet: [OFSet setWithObjects: @"foo", @"bar", nil]]; + + OTAssertEqualObjects(_mutableSet, + ([OFSet setWithObjects: @"baz", nil])); +} + +- (void)testIntersectSet +{ + [_mutableSet intersectSet: [OFSet setWithObjects: @"foo", @"qux", nil]]; + + OTAssertEqualObjects(_mutableSet, + ([OFSet setWithObjects: @"foo", nil])); +} + +- (void)testUnionSet +{ + [_mutableSet unionSet: [OFSet setWithObjects: @"x", @"y", nil]]; + + OTAssertEqualObjects(_mutableSet, + ([OFSet setWithObjects: @"foo", @"bar", @"baz", @"x", @"y", nil])); +} + +- (void)testRemoveAllObjects +{ + [_mutableSet removeAllObjects]; + + OTAssertEqual(_mutableSet.count, 0); +} +@end + +@implementation CustomMutableSet +- (instancetype)init +{ + self = [super init]; + + @try { + _set = [[OFMutableSet alloc] init]; + } @catch (id e) { + [self release]; + @throw e; + } + + return self; +} + +- (instancetype)initWithSet: (OFSet *)set +{ + self = [super init]; + + @try { + _set = [[OFMutableSet alloc] initWithSet: set]; + } @catch (id e) { + [self release]; + @throw e; + } + + return self; +} + +- (instancetype)initWithArray: (OFArray *)array +{ + self = [super init]; + + @try { + _set = [[OFMutableSet alloc] initWithArray: array]; + } @catch (id e) { + [self release]; + @throw e; + } + + return self; +} + +- (instancetype)initWithObject: (id)firstObject arguments: (va_list)arguments +{ + self = [super init]; + + @try { + _set = [[OFMutableSet alloc] initWithObject: firstObject + arguments: arguments]; + } @catch (id e) { + [self release]; + @throw e; + } + + return self; +} + +- (void)dealloc +{ + [_set release]; + + [super dealloc]; +} + +- (size_t)count +{ + return _set.count; +} + +- (bool)containsObject: (id)object +{ + return [_set containsObject: object]; +} + +- (OFEnumerator *)objectEnumerator +{ + return [_set objectEnumerator]; +} + +- (void)addObject: (id)object +{ + [_set addObject: object]; +} + +- (void)removeObject: (id)object +{ + [_set removeObject: object]; +} +@end ADDED new_tests/OFSetTests.h Index: new_tests/OFSetTests.h ================================================================== --- new_tests/OFSetTests.h +++ new_tests/OFSetTests.h @@ -0,0 +1,25 @@ +/* + * Copyright (c) 2008-2024 Jonathan Schleifer + * + * All rights reserved. + * + * This file is part of ObjFW. It may be distributed under the terms of the + * Q Public License 1.0, which can be found in the file LICENSE.QPL included in + * the packaging of this file. + * + * Alternatively, it may be distributed under the terms of the GNU General + * Public License, either version 2 or 3, which can be found in the file + * LICENSE.GPLv2 or LICENSE.GPLv3 respectively included in the packaging of this + * file. + */ + +#import "ObjFW.h" +#import "ObjFWTest.h" + +@interface OFSetTests: OTTestCase +{ + OFSet *_set; +} + +@property (readonly, nonatomic) Class setClass; +@end ADDED new_tests/OFSetTests.m Index: new_tests/OFSetTests.m ================================================================== --- new_tests/OFSetTests.m +++ new_tests/OFSetTests.m @@ -0,0 +1,269 @@ +/* + * Copyright (c) 2008-2024 Jonathan Schleifer + * + * All rights reserved. + * + * This file is part of ObjFW. It may be distributed under the terms of the + * Q Public License 1.0, which can be found in the file LICENSE.QPL included in + * the packaging of this file. + * + * Alternatively, it may be distributed under the terms of the GNU General + * Public License, either version 2 or 3, which can be found in the file + * LICENSE.GPLv2 or LICENSE.GPLv3 respectively included in the packaging of this + * file. + */ + +#include "config.h" + +#import "OFSetTests.h" + +@interface CustomSet: OFSet +{ + OFMutableSet *_set; +} +@end + +@implementation OFSetTests +- (Class)setClass +{ + return [CustomSet class]; +} + +- (void)setUp +{ + [super setUp]; + + _set = [[OFSet alloc] initWithObjects: @"foo", @"bar", @"baz", nil]; +} + +- (void)dealloc +{ + [_set release]; + + [super dealloc]; +} + +- (void)testSetWithArray +{ + OTAssertEqualObjects([self.setClass setWithArray: + ([OFArray arrayWithObjects: @"foo", @"bar", @"baz", @"foo", nil])], + _set); +} + +- (void)testIsEqual +{ + OTAssertEqualObjects(_set, + ([OFSet setWithObjects: @"foo", @"bar", @"baz", nil])); +} + +- (void)testHash +{ + OTAssertEqual(_set.hash, + [([OFSet setWithObjects: @"foo", @"bar", @"baz", nil]) hash]); +} + +- (void)testDescription +{ + OFString *description = _set.description; + + OTAssert( + [description isEqual: @"{(\n\tfoo,\n\tbar,\n\tbaz\n)}"] || + [description isEqual: @"{(\n\tfoo,\n\tbaz,\n\tbar\n)}"] || + [description isEqual: @"{(\n\tbar,\n\tfoo,\n\tbaz\n)}"] || + [description isEqual: @"{(\n\tbar,\n\tbaz,\n\tfoo\n)}"] || + [description isEqual: @"{(\n\tbaz,\n\tfoo,\n\tbar\n)}"] || + [description isEqual: @"{(\n\tbaz,\n\tbar,\n\tfoo\n)}"]); +} + +- (void)testCopy +{ + OTAssertEqualObjects([[_set copy] autorelease], _set); +} + +- (void)testIsSubsetOfSet +{ + OTAssertTrue([([OFSet setWithObjects: @"foo", nil]) + isSubsetOfSet: _set]); + OTAssertFalse([([OFSet setWithObjects: @"foo", @"Foo", nil]) + isSubsetOfSet: _set]); +} + +- (void)testIntersectsSet +{ + OTAssertTrue([([OFSet setWithObjects: @"foo", @"Foo", nil]) + intersectsSet: _set]); + OTAssertFalse([([OFSet setWithObjects: @"Foo", nil]) + intersectsSet: _set]); +} + +- (void)testEnumerator +{ + OFEnumerator *enumerator = [_set objectEnumerator]; + bool seenFoo = false, seenBar = false, seenBaz = false; + OFString *object; + + while ((object = [enumerator nextObject]) != nil) { + if ([object isEqual: @"foo"]) { + OTAssertFalse(seenFoo); + seenFoo = true; + } else if ([object isEqual: @"bar"]) { + OTAssertFalse(seenBar); + seenBar = true; + } else if ([object isEqual: @"baz"]) { + OTAssertFalse(seenBaz); + seenBaz = true; + } else + OTAssert(false, @"Unexpected object seen: %@", object); + } + + OTAssert(seenFoo && seenBar && seenBaz); +} + +- (void)testFastEnumeration +{ + bool seenFoo = false, seenBar = false, seenBaz = false; + + for (OFString *object in _set) { + if ([object isEqual: @"foo"]) { + OTAssertFalse(seenFoo); + seenFoo = true; + } else if ([object isEqual: @"bar"]) { + OTAssertFalse(seenBar); + seenBar = true; + } else if ([object isEqual: @"baz"]) { + OTAssertFalse(seenBaz); + seenBaz = true; + } else + OTAssert(false, @"Unexpected object seen: %@", object); + } + + OTAssert(seenFoo && seenBar && seenBaz); +} + +#ifdef OF_HAVE_BLOCKS +- (void)testEnumerateObjectsUsingBlock +{ + __block bool seenFoo = false, seenBar = false, seenBaz = false; + + [_set enumerateObjectsUsingBlock: ^ (id object, bool *stop) { + if ([object isEqual: @"foo"]) { + OTAssertFalse(seenFoo); + seenFoo = true; + } else if ([object isEqual: @"bar"]) { + OTAssertFalse(seenBar); + seenBar = true; + } else if ([object isEqual: @"baz"]) { + OTAssertFalse(seenBaz); + seenBaz = true; + } else + OTAssert(false, @"Unexpected object seen: %@", object); + }]; + + OTAssert(seenFoo && seenBar && seenBaz); +} + +- (void)testFilteredSetUsingBlock +{ + OFSet *filteredSet = [_set filteredSetUsingBlock: ^ (id object) { + return [object hasPrefix: @"ba"]; + }]; + + OTAssertEqualObjects(filteredSet, + ([OFSet setWithObjects: @"bar", @"baz", nil])); +} +#endif + +- (void)testValueForKey +{ + OFSet *set = [[self.setClass setWithObjects: + @"a", @"ab", @"abc", @"b", nil] valueForKey: @"length"]; + + OTAssertEqualObjects(set, ([OFSet setWithObjects: + [OFNumber numberWithInt: 1], [OFNumber numberWithInt: 2], + [OFNumber numberWithInt: 3], nil])); + + OTAssertEqualObjects([set valueForKey: @"@count"], + [OFNumber numberWithInt: 3]); +} +@end + +@implementation CustomSet +- (instancetype)init +{ + self = [super init]; + + @try { + _set = [[OFMutableSet alloc] init]; + } @catch (id e) { + [self release]; + @throw e; + } + + return self; +} + +- (instancetype)initWithSet: (OFSet *)set +{ + self = [super init]; + + @try { + _set = [[OFMutableSet alloc] initWithSet: set]; + } @catch (id e) { + [self release]; + @throw e; + } + + return self; +} + +- (instancetype)initWithArray: (OFArray *)array +{ + self = [super init]; + + @try { + _set = [[OFMutableSet alloc] initWithArray: array]; + } @catch (id e) { + [self release]; + @throw e; + } + + return self; +} + +- (instancetype)initWithObject: (id)firstObject arguments: (va_list)arguments +{ + self = [super init]; + + @try { + _set = [[OFMutableSet alloc] initWithObject: firstObject + arguments: arguments]; + } @catch (id e) { + [self release]; + @throw e; + } + + return self; +} + +- (void)dealloc +{ + [_set release]; + + [super dealloc]; +} + +- (size_t)count +{ + return _set.count; +} + +- (bool)containsObject: (id)object +{ + return [_set containsObject: object]; +} + +- (OFEnumerator *)objectEnumerator +{ + return [_set objectEnumerator]; +} +@end Index: tests/Makefile ================================================================== --- tests/Makefile +++ tests/Makefile @@ -20,11 +20,10 @@ OFListTests.m \ OFLocaleTests.m \ OFMemoryStreamTests.m \ OFNotificationCenterTests.m \ OFObjectTests.m \ - OFSetTests.m \ OFStreamTests.m \ OFStringTests.m \ OFSystemInfoTests.m \ OFValueTests.m \ OFXMLElementBuilderTests.m \ DELETED tests/OFSetTests.m Index: tests/OFSetTests.m ================================================================== --- tests/OFSetTests.m +++ tests/OFSetTests.m @@ -1,295 +0,0 @@ -/* - * Copyright (c) 2008-2024 Jonathan Schleifer - * - * All rights reserved. - * - * This file is part of ObjFW. It may be distributed under the terms of the - * Q Public License 1.0, which can be found in the file LICENSE.QPL included in - * the packaging of this file. - * - * Alternatively, it may be distributed under the terms of the GNU General - * Public License, either version 2 or 3, which can be found in the file - * LICENSE.GPLv2 or LICENSE.GPLv3 respectively included in the packaging of this - * file. - */ - -#include "config.h" - -#import "TestsAppDelegate.h" - -#import "OFSet.h" -#import "OFConcreteSet.h" -#import "OFConcreteMutableSet.h" - -static OFString *module; - -@interface SimpleSet: OFSet -{ - OFMutableSet *_set; -} -@end - -@interface SimpleMutableSet: OFMutableSet -{ - OFMutableSet *_set; - unsigned long _mutations; -} -@end - -@implementation SimpleSet -- (instancetype)init -{ - self = [super init]; - - @try { - _set = [[OFMutableSet alloc] init]; - } @catch (id e) { - [self release]; - @throw e; - } - - return self; -} - -- (instancetype)initWithSet: (OFSet *)set -{ - self = [super init]; - - @try { - _set = [[OFMutableSet alloc] initWithSet: set]; - } @catch (id e) { - [self release]; - @throw e; - } - - return self; -} - -- (instancetype)initWithArray: (OFArray *)array -{ - self = [super init]; - - @try { - _set = [[OFMutableSet alloc] initWithArray: array]; - } @catch (id e) { - [self release]; - @throw e; - } - - return self; -} - -- (instancetype)initWithObject: (id)firstObject arguments: (va_list)arguments -{ - self = [super init]; - - @try { - _set = [[OFMutableSet alloc] initWithObject: firstObject - arguments: arguments]; - } @catch (id e) { - [self release]; - @throw e; - } - - return self; -} - -- (void)dealloc -{ - [_set release]; - - [super dealloc]; -} - -- (size_t)count -{ - return _set.count; -} - -- (bool)containsObject: (id)object -{ - return [_set containsObject: object]; -} - -- (OFEnumerator *)objectEnumerator -{ - return [_set objectEnumerator]; -} -@end - -@implementation SimpleMutableSet -+ (void)initialize -{ - if (self == [SimpleMutableSet class]) - [self inheritMethodsFromClass: [SimpleSet class]]; -} - -- (void)addObject: (id)object -{ - bool existed = [self containsObject: object]; - - [_set addObject: object]; - - if (existed) - _mutations++; -} - -- (void)removeObject: (id)object -{ - bool existed = [self containsObject: object]; - - [_set removeObject: object]; - - if (existed) - _mutations++; -} - -- (int)countByEnumeratingWithState: (OFFastEnumerationState *)state - objects: (id *)objects - count: (int)count -{ - int ret = [_set countByEnumeratingWithState: state - objects: objects - count: count]; - - state->mutationsPtr = &_mutations; - - return ret; -} -@end - -@implementation TestsAppDelegate (OFSetTests) -- (void)setTestsWithClass: (Class)setClass mutableClass: (Class)mutableSetClass -{ - void *pool = objc_autoreleasePoolPush(); - OFSet *set1, *set2; - OFMutableSet *mutableSet; - bool ok; - size_t i; - - TEST(@"+[setWithArray:]", - (set1 = [setClass setWithArray: [OFArray arrayWithObjects: @"foo", - @"bar", @"baz", @"foo", @"x", nil]])) - - TEST(@"+[setWithObjects:]", - (set2 = [setClass setWithObjects: @"foo", @"bar", @"baz", @"bar", - @"x", nil])) - - TEST(@"-[isEqual:]", [set1 isEqual: set2]) - - TEST(@"-[hash]", set1.hash == set2.hash) - - TEST(@"-[description]", - [set1.description - isEqual: @"{(\n\tx,\n\tbar,\n\tfoo,\n\tbaz\n)}"] && - [set1.description isEqual: set2.description]) - - TEST(@"-[copy]", [set1 isEqual: [[set1 copy] autorelease]]) - - TEST(@"-[mutableCopy]", - [set1 isEqual: [[set1 mutableCopy] autorelease]]); - - mutableSet = [mutableSetClass setWithSet: set1]; - - TEST(@"-[addObject:]", - R([mutableSet addObject: @"baz"]) && [mutableSet isEqual: set2] && - R([mutableSet addObject: @"y"]) && [mutableSet isEqual: - [setClass setWithObjects: @"foo", @"bar", @"baz", @"x", @"y", nil]]) - - TEST(@"-[removeObject:]", - R([mutableSet removeObject: @"y"]) && [mutableSet isEqual: set1]) - - TEST(@"-[isSubsetOfSet:]", - R([mutableSet removeObject: @"foo"]) && - [mutableSet isSubsetOfSet: set1] && - ![set1 isSubsetOfSet: mutableSet]); - - TEST(@"-[intersectsSet:]", - [(set2 = [setClass setWithObjects: @"x", nil]) - intersectsSet: set1] && [set1 intersectsSet: set2] && - ![[setClass setWithObjects: @"1", nil] intersectsSet: set1]); - - TEST(@"-[minusSet:]", - R([mutableSet minusSet: [setClass setWithObjects: @"x", nil]]) && - [mutableSet isEqual: [setClass setWithObjects: - @"baz", @"bar", nil]]) - - TEST(@"-[intersectSet:]", - R([mutableSet intersectSet: [setClass setWithObjects: - @"baz", nil]]) && [mutableSet isEqual: [setClass setWithObjects: - @"baz", nil]]) - - TEST(@"-[unionSet:]", - R([mutableSet unionSet: [setClass setWithObjects: - @"x", @"bar", nil]]) && [mutableSet isEqual: - [setClass setWithObjects: @"baz", @"bar", @"x", nil]]) - - TEST(@"-[removeAllObjects]", - R([mutableSet removeAllObjects]) && - [mutableSet isEqual: [setClass set]]) - - ok = true; - i = 0; - - for (OFString *s in set1) { - switch (i) { - case 0: - if (![s isEqual: @"x"]) - ok = false; - break; - case 1: - if (![s isEqual: @"bar"]) - ok = false; - break; - case 2: - if (![s isEqual: @"foo"]) - ok = false; - break; - case 3: - if (![s isEqual: @"baz"]) - ok = false; - break; - } - - i++; - } - - if (i != 4) - ok = false; - - TEST(@"Fast enumeration", ok) - - ok = false; - [mutableSet addObject: @"foo"]; - [mutableSet addObject: @"bar"]; - @try { - for (OFString *s in mutableSet) - [mutableSet removeObject: s]; - } @catch (OFEnumerationMutationException *e) { - ok = true; - } - - TEST(@"Detection of mutation during Fast Enumeration", ok); - - TEST(@"-[valueForKey:]", - [(set1 = [[setClass setWithObjects: @"a", @"ab", @"abc", @"b", nil] - valueForKey: @"length"]) isEqual: [setClass setWithObjects: - [OFNumber numberWithInt: 1], [OFNumber numberWithInt: 2], - [OFNumber numberWithInt: 3], nil]] && - [[set1 valueForKey: @"@count"] isEqual: - [OFNumber numberWithInt: 3]]) - - objc_autoreleasePoolPop(pool); -} - -- (void)setTests -{ - module = @"OFSet"; - [self setTestsWithClass: [SimpleSet class] - mutableClass: [SimpleMutableSet class]]; - - module = @"OFConcreteSet"; - [self setTestsWithClass: [OFConcreteSet class] - mutableClass: [OFConcreteMutableSet class]]; -} -@end Index: tests/TestsAppDelegate.h ================================================================== --- tests/TestsAppDelegate.h +++ tests/TestsAppDelegate.h @@ -137,14 +137,10 @@ @interface TestsAppDelegate (OFSPXStreamSocketTests) - (void)SPXStreamSocketTests; @end -@interface TestsAppDelegate (OFSetTests) -- (void)setTests; -@end - @interface TestsAppDelegate (OFSystemInfoTests) - (void)systemInfoTests; @end @interface TestsAppDelegate (OFStreamTests) Index: tests/TestsAppDelegate.m ================================================================== --- tests/TestsAppDelegate.m +++ tests/TestsAppDelegate.m @@ -381,11 +381,10 @@ #endif [self stringTests]; [self dataTests]; [self dictionaryTests]; [self listTests]; - [self setTests]; [self valueTests]; [self streamTests]; [self memoryStreamTests]; [self notificationCenterTests]; #ifdef OF_HAVE_SOCKETS