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.78 tracks/objective-c/exercises/binary-search/BinarySearchTest.m
trackler-2.2.1.77 tracks/objective-c/exercises/binary-search/BinarySearchTest.m
trackler-2.2.1.76 tracks/objective-c/exercises/binary-search/BinarySearchTest.m
trackler-2.2.1.75 tracks/objective-c/exercises/binary-search/BinarySearchTest.m
trackler-2.2.1.74 tracks/objective-c/exercises/binary-search/BinarySearchTest.m
trackler-2.2.1.73 tracks/objective-c/exercises/binary-search/BinarySearchTest.m
trackler-2.2.1.72 tracks/objective-c/exercises/binary-search/BinarySearchTest.m
trackler-2.2.1.71 tracks/objective-c/exercises/binary-search/BinarySearchTest.m
trackler-2.2.1.70 tracks/objective-c/exercises/binary-search/BinarySearchTest.m
trackler-2.2.1.69 tracks/objective-c/exercises/binary-search/BinarySearchTest.m
trackler-2.2.1.68 tracks/objective-c/exercises/binary-search/BinarySearchTest.m
trackler-2.2.1.67 tracks/objective-c/exercises/binary-search/BinarySearchTest.m
trackler-2.2.1.66 tracks/objective-c/exercises/binary-search/BinarySearchTest.m
trackler-2.2.1.65 tracks/objective-c/exercises/binary-search/BinarySearchTest.m
trackler-2.2.1.64 tracks/objective-c/exercises/binary-search/BinarySearchTest.m
trackler-2.2.1.63 tracks/objective-c/exercises/binary-search/BinarySearchTest.m
trackler-2.2.1.62 tracks/objective-c/exercises/binary-search/BinarySearchTest.m
trackler-2.2.1.61 tracks/objective-c/exercises/binary-search/BinarySearchTest.m
trackler-2.2.1.60 tracks/objective-c/exercises/binary-search/BinarySearchTest.m
trackler-2.2.1.59 tracks/objective-c/exercises/binary-search/BinarySearchTest.m