-
-
Notifications
You must be signed in to change notification settings - Fork 38
/
Copy pathAllergiesTest.m
61 lines (49 loc) · 1.99 KB
/
AllergiesTest.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
#import <XCTest/XCTest.h>
#if __has_include("AllergiesExample.h")
# import "AllergiesExample.h"
# else
# import "Allergies.h"
#endif
@interface AllergiesTest : XCTestCase
@end
@implementation AllergiesTest
- (NSArray<NSNumber *> *)allAllergens {
return @[@(AllergenEggs), @(AllergenPeanuts), @(AllergenShellfish), @(AllergenStrawberries), @(AllergenTomatoes), @(AllergenChocolate), @(AllergenPollen), @(AllergenCats)];
}
- (void)testAllergicToEggs {
Allergies *allergies = [[Allergies alloc] initWithScore:1];
XCTAssertTrue([allergies hasAllergy:AllergenEggs]);
XCTAssertFalse([allergies hasAllergy:AllergenPeanuts]);
XCTAssertFalse([allergies hasAllergy:AllergenPollen]);
}
- (void)testAllergicToChocolate {
Allergies *allergies = [[Allergies alloc] initWithScore:32];
XCTAssertTrue([allergies hasAllergy:AllergenChocolate]);
XCTAssertFalse([allergies hasAllergy:AllergenEggs]);
XCTAssertFalse([allergies hasAllergy:AllergenTomatoes]);
}
- (void)testBob {
Allergies *allergies = [[Allergies alloc] initWithScore:34];
XCTAssertTrue([allergies hasAllergy:AllergenPeanuts], "Bob is allergic to peanuts");
XCTAssertTrue([allergies hasAllergy:AllergenChocolate], "Bob is allergic to chocolate");
XCTAssertFalse([allergies hasAllergy:AllergenCats], "Bob is not allergic to cats");
}
- (void)testEggsAndCats {
Allergies *allergies = [[Allergies alloc] initWithScore:129];
XCTAssertTrue([allergies hasAllergy:AllergenEggs]);
XCTAssertTrue([allergies hasAllergy:AllergenCats]);
XCTAssertFalse([allergies hasAllergy:AllergenChocolate]);
}
- (void)testNone {
Allergies *allergies = [[Allergies alloc] initWithScore:0];
for (NSNumber *allergen in [self allAllergens]) {
XCTAssertFalse([allergies hasAllergy:[allergen intValue]]);
}
}
- (void)testAll {
Allergies *allergies = [[Allergies alloc] initWithScore:255];
for (NSNumber *allergen in [self allAllergens]) {
XCTAssertTrue([allergies hasAllergy:[allergen intValue]]);
}
}
@end