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.98 tracks/objective-c/exercises/binary-search/BinarySearchTest.m
trackler-2.2.1.97 tracks/objective-c/exercises/binary-search/BinarySearchTest.m
trackler-2.2.1.96 tracks/objective-c/exercises/binary-search/BinarySearchTest.m
trackler-2.2.1.95 tracks/objective-c/exercises/binary-search/BinarySearchTest.m
trackler-2.2.1.94 tracks/objective-c/exercises/binary-search/BinarySearchTest.m
trackler-2.2.1.93 tracks/objective-c/exercises/binary-search/BinarySearchTest.m
trackler-2.2.1.92 tracks/objective-c/exercises/binary-search/BinarySearchTest.m
trackler-2.2.1.91 tracks/objective-c/exercises/binary-search/BinarySearchTest.m
trackler-2.2.1.90 tracks/objective-c/exercises/binary-search/BinarySearchTest.m
trackler-2.2.1.89 tracks/objective-c/exercises/binary-search/BinarySearchTest.m
trackler-2.2.1.88 tracks/objective-c/exercises/binary-search/BinarySearchTest.m
trackler-2.2.1.87 tracks/objective-c/exercises/binary-search/BinarySearchTest.m
trackler-2.2.1.86 tracks/objective-c/exercises/binary-search/BinarySearchTest.m
trackler-2.2.1.85 tracks/objective-c/exercises/binary-search/BinarySearchTest.m
trackler-2.2.1.84 tracks/objective-c/exercises/binary-search/BinarySearchTest.m
trackler-2.2.1.83 tracks/objective-c/exercises/binary-search/BinarySearchTest.m
trackler-2.2.1.82 tracks/objective-c/exercises/binary-search/BinarySearchTest.m
trackler-2.2.1.81 tracks/objective-c/exercises/binary-search/BinarySearchTest.m
trackler-2.2.1.80 tracks/objective-c/exercises/binary-search/BinarySearchTest.m
trackler-2.2.1.79 tracks/objective-c/exercises/binary-search/BinarySearchTest.m