//ExtendedString.h #import <Cocoa/Cocoa.h> @interface NSString (Extended) - (NSString *)invert; @end
//ExtendedString.m #import "ExtendedString.h" @implementation NSString (Extended) - (NSString *)invert { NSUInteger length = [self length]; NSMutableString *invertedString = [NSMutableString stringWithCapacity: length]; while (length > (NSUInteger)0) { unichar c = [self characterAtIndex: --length]; [invertedString appendString: [NSString stringWithCharacters: &c length: 1]]; } return invertedString; } @end
//ExtendedString_Test.h #import <SenTestingKit/SenTestingKit.h> // // , , // - : //@class MyClass; // Mylass ExtendedString_Test //, NSString @interface ExtendedString_Test : SenTestCase // - { NSString *_string; } @end
//ExtendedString_Test.m #import "ExtendedString_Test.h" #import "ExtendedString.h" // @implementation ExtendedString_Test - (void)setUp // , { _string = [[NSString alloc] initWithString: @"Hello world!"]; STAssertNotNil(_string, @"Construct error!"); // , } - (void)tearDown // , { [_string release]; } - (void)testInvertString // { STAssertEqualObjects(@"Hello world!", _string, @"String is not initialized!"); // STAssertEqualObjects(@"!dlrow olleH", [_string invert], @"String is not inverted!"); // } @end
export OBJC_DISABLE_GC=YES # Garbage Collector
arch -i386 /Developer/Tools/otest ~/InvertString/build/Debug/Tests.octest # (i386),
objc[22721]: GC: forcing GC OFF because OBJC_DISABLE_GC is set
objc[22721]: GC: forcing GC OFF because OBJC_DISABLE_GC is set
Test Suite '/Users/ium/InvertString/build/Debug/Tests.octest(Tests)' started at 2011-07-01 18:46:45 +0300
Test Suite 'ExtendedString_Test' started at 2011-07-01 18:46:45 +0300
/Users/ium/InvertString/Tests/ExtendedString_Test.m:21: error: -[ExtendedString_Test testInvertString] : 'Hello world' should be equal to 'Hello world!' String is not initialized!
2011-07-01 18:46:45.240 otest[22721:80f] !dlrow olleH
/Users/ium/InvertString/Tests/ExtendedString_Test.m:22: error: -[ExtendedString_Test testInvertString] : '!dlrow olle' should be equal to '!dlrow olleH' String is not inverted!
Test Case '-[ExtendedString_Test testInvertString]' failed (0.003 seconds).
Test Suite 'ExtendedString_Test' finished at 2011-07-01 18:46:45 +0300.
Executed 1 test, with 2 failures (0 unexpected) in 0.003 (0.003) seconds
Test Suite '/Users/ium/InvertString/build/Debug/Tests.octest(Tests)' finished at 2011-07-01 18:46:45 +0300.
Executed 1 test, with 2 failures (0 unexpected) in 0.003 (0.010) seconds
STFail(description, ...) // , , STAssertNil(a1, description, ...) STAssertNotNil(a1, description, ...) STAssertTrue(expression, description, ...) STAssertFalse(expression, description, ...) STAssertEqualObjects(a1, a2, description, ...) // , STAssertEquals(a1, a2, description, ...) // STAssertEqualsWithAccuracy(left, right, accuracy, description, ...) STAssertThrows(expression, description, ...) STAssertThrowsSpecific(expression, specificException, description, ...) STAssertThrowsSpecificNamed(expr, specificException, aName, description, ...) STAssertNoThrow(expression, description, ...) STAssertNoThrowSpecific(expression, specificException, description, ...) STAssertNoThrowSpecificNamed(expr, specificException, aName, description, ...) STAssertTrueNoThrow(expression, description, ...) STAssertFalseNoThrow(expression, description, ...)
Source: https://habr.com/ru/post/129896/
All Articles