summaryrefslogtreecommitdiff
path: root/platform/darwin/test/MGLClockDirectionFormatterTests.m
blob: 13e12ae2f213eac269db5dcffbcac68ca6142dac (plain)
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
73
74
#import <Mapbox/Mapbox.h>
#import <XCTest/XCTest.h>

static NSString * const MGLTestLocaleIdentifier = @"en-US";

@interface MGLClockDirectionFormatterTests : XCTestCase

@end

@implementation MGLClockDirectionFormatterTests

- (void)testClockDirections {
    MGLClockDirectionFormatter *shortFormatter = [[MGLClockDirectionFormatter alloc] init];
    shortFormatter.unitStyle = NSFormattingUnitStyleShort;

    MGLClockDirectionFormatter *mediumFormatter = [[MGLClockDirectionFormatter alloc] init];

    MGLClockDirectionFormatter *longFormatter = [[MGLClockDirectionFormatter alloc] init];
    longFormatter.unitStyle = NSFormattingUnitStyleLong;

    CLLocationDirection direction;

    direction = -90;
    XCTAssertEqualObjects(@"9:00", [shortFormatter stringFromDirection:direction]);
    XCTAssertEqualObjects(@"9 o’clock", [mediumFormatter stringFromDirection:direction]);
    XCTAssertEqualObjects(@"9 o’clock", [longFormatter stringFromDirection:direction]);

    direction = 0;
    XCTAssertEqualObjects(@"12:00", [shortFormatter stringFromDirection:direction]);
    XCTAssertEqualObjects(@"12 o’clock", [mediumFormatter stringFromDirection:direction]);
    XCTAssertEqualObjects(@"12 o’clock", [longFormatter stringFromDirection:direction]);

    direction = 45;
    XCTAssertEqualObjects(@"2:00", [shortFormatter stringFromDirection:direction]);
    XCTAssertEqualObjects(@"2 o’clock", [mediumFormatter stringFromDirection:direction]);
    XCTAssertEqualObjects(@"2 o’clock", [longFormatter stringFromDirection:direction]);

    direction = 90;
    XCTAssertEqualObjects(@"3:00", [shortFormatter stringFromDirection:direction]);
    XCTAssertEqualObjects(@"3 o’clock", [mediumFormatter stringFromDirection:direction]);
    XCTAssertEqualObjects(@"3 o’clock", [longFormatter stringFromDirection:direction]);

    direction = 180;
    XCTAssertEqualObjects(@"6:00", [shortFormatter stringFromDirection:direction]);
    XCTAssertEqualObjects(@"6 o’clock", [mediumFormatter stringFromDirection:direction]);
    XCTAssertEqualObjects(@"6 o’clock", [longFormatter stringFromDirection:direction]);

    direction = 270;
    XCTAssertEqualObjects(@"9:00", [shortFormatter stringFromDirection:direction]);
    XCTAssertEqualObjects(@"9 o’clock", [mediumFormatter stringFromDirection:direction]);
    XCTAssertEqualObjects(@"9 o’clock", [longFormatter stringFromDirection:direction]);

    direction = 359.34951805867024;
    XCTAssertEqualObjects(@"12:00", [shortFormatter stringFromDirection:direction]);
    XCTAssertEqualObjects(@"12 o’clock", [mediumFormatter stringFromDirection:direction]);
    XCTAssertEqualObjects(@"12 o’clock", [longFormatter stringFromDirection:direction]);

    direction = 360;
    XCTAssertEqualObjects(@"12:00", [shortFormatter stringFromDirection:direction]);
    XCTAssertEqualObjects(@"12 o’clock", [mediumFormatter stringFromDirection:direction]);
    XCTAssertEqualObjects(@"12 o’clock", [longFormatter stringFromDirection:direction]);

    direction = 360.1;
    XCTAssertEqualObjects(@"12:00", [shortFormatter stringFromDirection:direction]);
    XCTAssertEqualObjects(@"12 o’clock", [mediumFormatter stringFromDirection:direction]);
    XCTAssertEqualObjects(@"12 o’clock", [longFormatter stringFromDirection:direction]);

    direction = 720;
    XCTAssertEqualObjects(@"12:00", [shortFormatter stringFromDirection:direction]);
    XCTAssertEqualObjects(@"12 o’clock", [mediumFormatter stringFromDirection:direction]);
    XCTAssertEqualObjects(@"12 o’clock", [longFormatter stringFromDirection:direction]);
}

@end