Sha256: 9f3f53772074ac80ec80d43e2497da9cd6c1364cf4e808cb8b34a8d4bc3a7c88

Contents?: true

Size: 1.62 KB

Versions: 270

Compression:

Stored size: 1.62 KB

Contents

#import <XCTest/XCTest.h>

#if __has_include("BinarySearchExample.h")
# import "BinarySearchExample.h"
# else
# import "BinarySearch.h"
#endif

@interface BinarySearchTest : XCTestCase

@end

@implementation BinarySearchTest

- (void)testHasListData {
    NSArray *array = @[@1, @3, @4, @6, @8, @9, @11];
    BinarySearch *binary = [[BinarySearch alloc] initWithArray:array];
    XCTAssertEqualObjects(binary.list, array);
}

- (void)testNilForUnsortedList {
    BinarySearch *binary = [[BinarySearch alloc] initWithArray:@[@2, @1, @4, @3, @6]];
    XCTAssertNil(binary);
}

- (void)testNotFoundForDataNotInList {
    BinarySearch *binary = [[BinarySearch alloc] initWithArray:@[@1, @3, @6]];
    XCTAssertEqual([binary searchFor:2], NSNotFound);
}

- (void)testFindsPositionOfMiddleItem {
    BinarySearch *binary = [[BinarySearch alloc] initWithArray:@[@1, @3, @4, @6, @8, @9, @11]];
    XCTAssertEqual(3, [binary middle]);
}

- (void)testFindsPositionOfSearchData {
    BinarySearch *binary = [[BinarySearch alloc] initWithArray:@[@1, @3, @4, @6, @8, @9, @11]];
    XCTAssertEqual(5, [binary searchFor:9]);
}

- (void)testFindsPositionInALargerList {
    BinarySearch *binary = [[BinarySearch alloc] initWithArray:@[@1, @3, @5, @8, @13, @21, @34, @55, @89, @144]];
    XCTAssertEqual(1, [binary searchFor:3]);
    XCTAssertEqual(7, [binary searchFor:55]);
}

- (void)testFindsCorrectPositionInAListWithAnEvenNumberOfElements {
    BinarySearch *binary = [[BinarySearch alloc] initWithArray:@[@1, @3, @5, @8, @13, @21, @34, @55, @89, @144, @233, @377]];
    XCTAssertEqual(5, [binary searchFor:21]);
    XCTAssertEqual(6, [binary searchFor:34]);
}

@end

Version data entries

270 entries across 270 versions & 1 rubygems

Version Path
trackler-2.2.1.58 tracks/objective-c/exercises/binary-search/BinarySearchTest.m
trackler-2.2.1.57 tracks/objective-c/exercises/binary-search/BinarySearchTest.m
trackler-2.2.1.56 tracks/objective-c/exercises/binary-search/BinarySearchTest.m
trackler-2.2.1.55 tracks/objective-c/exercises/binary-search/BinarySearchTest.m
trackler-2.2.1.54 tracks/objective-c/exercises/binary-search/BinarySearchTest.m
trackler-2.2.1.53 tracks/objective-c/exercises/binary-search/BinarySearchTest.m
trackler-2.2.1.52 tracks/objective-c/exercises/binary-search/BinarySearchTest.m
trackler-2.2.1.51 tracks/objective-c/exercises/binary-search/BinarySearchTest.m
trackler-2.2.1.50 tracks/objective-c/exercises/binary-search/BinarySearchTest.m
trackler-2.2.1.49 tracks/objective-c/exercises/binary-search/BinarySearchTest.m
trackler-2.2.1.48 tracks/objective-c/exercises/binary-search/BinarySearchTest.m
trackler-2.2.1.47 tracks/objective-c/exercises/binary-search/BinarySearchTest.m
trackler-2.2.1.46 tracks/objective-c/exercises/binary-search/BinarySearchTest.m
trackler-2.2.1.45 tracks/objective-c/exercises/binary-search/BinarySearchTest.m
trackler-2.2.1.44 tracks/objective-c/exercises/binary-search/BinarySearchTest.m
trackler-2.2.1.43 tracks/objective-c/exercises/binary-search/BinarySearchTest.m
trackler-2.2.1.42 tracks/objective-c/exercises/binary-search/BinarySearchTest.m
trackler-2.2.1.41 tracks/objective-c/exercises/binary-search/BinarySearchTest.m
trackler-2.2.1.40 tracks/objective-c/exercises/binary-search/BinarySearchTest.m
trackler-2.2.1.39 tracks/objective-c/exercises/binary-search/BinarySearchTest.m