1
exercism fetch objective-c nucleotide-count

NucleotideCountTest.m

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
#import <XCTest/XCTest.h>

#if __has_include("NucleotideCountExample.h")
# import "NucleotideCountExample.h"
# else
# import "NucleotideCount.h"
#endif

NS_ASSUME_NONNULL_BEGIN

@interface NucleotideCountTest : XCTestCase

@end

@implementation NucleotideCountTest

- (void)testEmptyDNAStringHasNoAdenosine {
  NucleotideCount *dna = [[NucleotideCount alloc] initWithStrand:@""];
  NSUInteger result = [dna count:@"A"];
  NSUInteger expected = 0;
  XCTAssertEqual(expected,result);
}

- (void)testEmptyNucleotideCountStringHasNoNucleotides {
  NucleotideCount *dna = [[NucleotideCount alloc] initWithStrand:@""];
  NSDictionary<NSString *, NSNumber *> *results = [dna nucleotideCounts];
  NSDictionary<NSString *, NSNumber *> *expected = @{ @"A": @0, @"T" : @0, @"C" : @0, @"G" : @0 };
  XCTAssertEqualObjects(results, expected);
}

- (void)testRepetitiveCytidineGetsCounted {
  NucleotideCount *dna = [[NucleotideCount alloc] initWithStrand:@"CCCCC"];
  NSUInteger result = [dna count:@"C"];
  NSUInteger expected = 5;
  XCTAssertEqual(expected,result);
}

- (void)testRepetitiveSequenceHasOnlyGuanosine {
  NucleotideCount *dna = [[NucleotideCount alloc] initWithStrand:@"GGGGGGGG"];
  NSDictionary<NSString *, NSNumber *> *results = [dna nucleotideCounts];
  NSDictionary<NSString *, NSNumber *> *expected = @{ @"A": @0, @"T" : @0, @"C" : @0, @"G" : @8 };
  XCTAssertEqualObjects(results, expected);
}

- (void)testCountsByThymidine {
  NucleotideCount *dna = [[NucleotideCount alloc] initWithStrand:@"GGGGGTAACCCGG"];
  NSUInteger result = [dna count:@"T"];
  NSUInteger expected = 1;
  XCTAssertEqual(expected,result);
}

- (void)testCountsANucleotideOnlyOnce {
  NucleotideCount *dna = [[NucleotideCount alloc] initWithStrand:@"CGATTGGG"];
  NSUInteger result = [dna count:@"T"];
  NSUInteger expected = 2;
  XCTAssertEqual(expected,result);
}

- (void)testValidatesNucleotideCount {
  XCTAssertThrows([[NucleotideCount alloc] initWithStrand:@"John"]);
}

- (void)testCountsAllNucleotides {
  NSString *longStrand = @"AGCTTTTCATTCTGACTGCAACGGGCAATATGTCTCTGTGTGGATTAAAAAAAGAGTGTCTGATAGCAGC";
  NucleotideCount *dna = [[NucleotideCount alloc] initWithStrand:longStrand];
  NSDictionary<NSString *, NSNumber *> *results = [dna nucleotideCounts];
  NSDictionary<NSString *, NSNumber *> *expected = @{ @"A": @20, @"T" : @21, @"C" : @12, @"G" : @17 };
  XCTAssertEqualObjects(results, expected);
}

@end
NS_ASSUME_NONNULL_END