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.180 tracks/objective-c/exercises/binary-search/BinarySearchTest.m
trackler-2.2.1.179 tracks/objective-c/exercises/binary-search/BinarySearchTest.m
trackler-2.2.1.178 tracks/objective-c/exercises/binary-search/BinarySearchTest.m
trackler-2.2.1.177 tracks/objective-c/exercises/binary-search/BinarySearchTest.m
trackler-2.2.1.176 tracks/objective-c/exercises/binary-search/BinarySearchTest.m
trackler-2.2.1.175 tracks/objective-c/exercises/binary-search/BinarySearchTest.m
trackler-2.2.1.174 tracks/objective-c/exercises/binary-search/BinarySearchTest.m
trackler-2.2.1.173 tracks/objective-c/exercises/binary-search/BinarySearchTest.m
trackler-2.2.1.172 tracks/objective-c/exercises/binary-search/BinarySearchTest.m
trackler-2.2.1.171 tracks/objective-c/exercises/binary-search/BinarySearchTest.m
trackler-2.2.1.170 tracks/objective-c/exercises/binary-search/BinarySearchTest.m
trackler-2.2.1.169 tracks/objective-c/exercises/binary-search/BinarySearchTest.m
trackler-2.2.1.167 tracks/objective-c/exercises/binary-search/BinarySearchTest.m
trackler-2.2.1.166 tracks/objective-c/exercises/binary-search/BinarySearchTest.m
trackler-2.2.1.165 tracks/objective-c/exercises/binary-search/BinarySearchTest.m
trackler-2.2.1.164 tracks/objective-c/exercises/binary-search/BinarySearchTest.m
trackler-2.2.1.163 tracks/objective-c/exercises/binary-search/BinarySearchTest.m
trackler-2.2.1.162 tracks/objective-c/exercises/binary-search/BinarySearchTest.m
trackler-2.2.1.161 tracks/objective-c/exercises/binary-search/BinarySearchTest.m
trackler-2.2.1.160 tracks/objective-c/exercises/binary-search/BinarySearchTest.m