summaryrefslogtreecommitdiff
path: root/platform/darwin/test/MGLDistanceFormatterTests.m
blob: f15ad9d31344f4d8d9e56c1cc9fee359fe40c6b9 (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
#import <Mapbox/Mapbox.h>
#import <XCTest/XCTest.h>

@interface MGLDistanceFormatterTests : XCTestCase

@end

@implementation MGLDistanceFormatterTests

- (void)testAbbreviatedMetricUnits {
    MGLDistanceFormatter *formatter = [[MGLDistanceFormatter alloc] init];
    formatter.numberFormatter.locale = [NSLocale localeWithLocaleIdentifier:@"en_CA"];
    for (CLLocationDistance distance=0; distance <= 10000; distance+=5) {
        NSString *unit = [[formatter stringFromDistance:distance] componentsSeparatedByString:@" "][1];
        NSPredicate *predicate = [NSPredicate predicateWithFormat:@"SELF IN %@", @[@"mm", @"cm", @"m", @"km"]];
        XCTAssert([predicate evaluateWithObject:unit], @"Should only contain metric units");
    }
}

- (void)testAbbreviatedImperialUnits {
    MGLDistanceFormatter *formatter = [[MGLDistanceFormatter alloc] init];
    formatter.numberFormatter.locale = [NSLocale localeWithLocaleIdentifier:@"en_US"];
    for (CLLocationDistance distance=0; distance <= 10000; distance+=5) {
        NSString *unit = [[formatter stringFromDistance:distance] componentsSeparatedByString:@" "][1];
        NSPredicate *predicate = [NSPredicate predicateWithFormat:@"SELF IN %@", @[@"ft", @"mi"]];
        XCTAssert([predicate evaluateWithObject:unit], @"Should only contain imperial units");
    }
}

@end