summaryrefslogtreecommitdiff
path: root/platform/darwin/test
diff options
context:
space:
mode:
authorFredrik Karlsson <bjorn.fredrik.karlsson@gmail.com>2017-01-04 16:18:17 +0100
committerFredrik Karlsson <bjorn.fredrik.karlsson@gmail.com>2017-01-27 19:41:13 +0100
commit2ab3af4b1b5dabf7087e6fabfb84617f4ff4b55d (patch)
tree179312c48bf929914acec1ad9eafcbb2d7d2bd4e /platform/darwin/test
parent4d358260140c9d52103cc95631a8519b969bc408 (diff)
downloadqtlocation-mapboxgl-2ab3af4b1b5dabf7087e6fabfb84617f4ff4b55d.tar.gz
[ios, macos] added a distance formatter
Diffstat (limited to 'platform/darwin/test')
-rw-r--r--platform/darwin/test/MGLDistanceFormatterTests.m30
1 files changed, 30 insertions, 0 deletions
diff --git a/platform/darwin/test/MGLDistanceFormatterTests.m b/platform/darwin/test/MGLDistanceFormatterTests.m
new file mode 100644
index 0000000000..f15ad9d313
--- /dev/null
+++ b/platform/darwin/test/MGLDistanceFormatterTests.m
@@ -0,0 +1,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