1
exercism fetch objective-c triangle

TriangleTest.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
#import <XCTest/XCTest.h>

#if __has_include("TriangleExample.h")
# import "TriangleExample.h"
# else
# import "Triangle.h"
#endif

@interface TriangleTest : XCTestCase

@end

@implementation TriangleTest

- (void)testEquilateralTrianglesHaveEqualSides {
    XCTAssertEqual(TriangleKindEquilateral, [Triangle kindForSides:2 :2 :2]);
}

- (void)testLargerEquilateralTrianglesAlsoHaveEqualSides {
    XCTAssertEqual(TriangleKindEquilateral, [Triangle kindForSides:10 :10 :10]);
}

- (void)testIsoscelesTrianglesHaveLastTwoSidesEqual {
    XCTAssertEqual(TriangleKindIsosceles, [Triangle kindForSides:3 :4 :4]);
}

- (void)testIsoscelesTrianglesHaveFirstAndLastSidesEqual {
    XCTAssertEqual(TriangleKindIsosceles, [Triangle kindForSides:4 :3 :4]);
}

- (void)testIsoscelesTrianglesHaveTwoFirstSidesEqual {
    XCTAssertEqual(TriangleKindIsosceles, [Triangle kindForSides:4 :4 :3]);
}

- (void)testIsoscelesTrianglesHaveInFactExactlyTwoSidesEqual {
    XCTAssertEqual(TriangleKindIsosceles, [Triangle kindForSides:10 :10 :2]);
}

- (void)testScaleneTrianglesHaveNoEqualSides {
    XCTAssertEqual(TriangleKindScalene, [Triangle kindForSides:3 :4 :5]);
}

- (void)testScaleneTrianglesHaveNoEqualSidesAtALargerScaleToo {
    XCTAssertEqual(TriangleKindScalene, [Triangle kindForSides:10 :11 :12]);
}

- (void)testScaleneTrianglesHaveNoEqualSidesInDescendingOrderEither {
    XCTAssertEqual(TriangleKindScalene, [Triangle kindForSides:5 :4 :2]);
}

- (void)testVerySmallTrianglesAreLegal {
    XCTAssertEqual(TriangleKindScalene, [Triangle kindForSides:0.4 :0.6 :0.3]);
}

- (void)testTrianglesWithNoSizeAreIllegal {
    XCTAssertThrows([Triangle kindForSides:0 :0 :0]);
}

- (void)testTrianglesWithNegativeSidesAreIllegal {
    XCTAssertThrows([Triangle kindForSides:3 :4 :-5]);
}

- (void)testTrianglesViolatingTriangleInequalityAreIllegal {
    XCTAssertThrows([Triangle kindForSides:1 :1 :3]);
}

- (void)testTrianglesViolatingTriangleInequalityAreIllegal3 {
    XCTAssertThrows([Triangle kindForSides:7 :3 :2]);
}

@end