-
Notifications
You must be signed in to change notification settings - Fork 3
/
coordinate-converter.test.js
65 lines (50 loc) · 3.2 KB
/
coordinate-converter.test.js
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
import {CoordinateConverter, GeographicCoordinateConverter} from "./coordinate-converter";
describe("GeographicCoordinateConverterBuilder build suite", () => {
it("should build a GeographicCoordinateConverter instance fromDecimal array", () => {
expect(CoordinateConverter.fromDecimal([-36.01011, -2.34856]).lat).toBe(-36.01011);
expect(CoordinateConverter.fromDecimal([-36.01011, -2.34856]).lng).toBe(-2.34856);
});
it("should build a GeographicCoordinateConverter instance fromDecimal", () => {
expect(CoordinateConverter.fromDecimal("-36.01011 -2.34856").lat).toBe(-36.01011);
expect(CoordinateConverter.fromDecimal("-36.01011 -2.34856").lng).toBe(-2.34856);
});
it("should build a GeographicCoordinateConverter instance fromDegreeMinutes", () => {
expect(CoordinateConverter.fromDegreeMinutes("36º 00.607' S 002º 20.914' W").lat).toBe(-36.01012);
expect(CoordinateConverter.fromDegreeMinutes("36º 00.607' S 002º 20.914' W").lng).toBe(-2.34857);
});
it("should build a GeographicCoordinateConverter instance fromDegreeMinutesSeconds", () => {
expect(CoordinateConverter.fromDegreeMinutesSeconds("36º 00' 36.4'' S 002º 20' 54.8'' W").lat).toBe(-36.01011);
expect(CoordinateConverter.fromDegreeMinutesSeconds("36º 00' 36.4'' S 002º 20' 54.8'' W").lng).toBe(-2.34856);
});
it("should build a GeographicCoordinateConverter instance fromDegreeMinutes without spaces", () => {
expect(CoordinateConverter.fromDegreeMinutes("36º00.607'S 002º20.914'W").lat).toBe(-36.01012);
expect(CoordinateConverter.fromDegreeMinutes("36º00.607'S 002º20.914'W").lng).toBe(-2.34857);
});
it("should build a GeographicCoordinateConverter instance fromDegreeMinutesSeconds without spaces", () => {
expect(CoordinateConverter.fromDegreeMinutesSeconds("36º00'36.4''S 002º20'54.8''W").lat).toBe(-36.01011);
expect(CoordinateConverter.fromDegreeMinutesSeconds("36º00'36.4''S 002º20'54.8''W").lng).toBe(-2.34856);
});
});
describe("GeographicCoordinateConverter conversion suite", () => {
it("should convert to negative decimal ", () => {
expect(new GeographicCoordinateConverter(-36.01011, -2.34856).toDecimal()).toBe("-36.01011 -2.34856");
});
it("should convert to decimal", () => {
expect(new GeographicCoordinateConverter(36.01011, 2.34856).toDecimal()).toBe("36.01011 2.34856");
});
it("should convert decimal array ", () => {
expect(new GeographicCoordinateConverter(-36.01011, -2.34856).toDecimalArray()).toEqual([-36.01011, -2.34856]);
});
it("should convert to degree minutes (south, west)", () => {
expect(new GeographicCoordinateConverter(-36.01011, -2.34856).toDegreeMinutes()).toBe("36º 00.607' S 002º 20.914' W");
});
it("should convert to degree minutes", () => {
expect(new GeographicCoordinateConverter(36.01011, 2.34856).toDegreeMinutes()).toBe("36º 00.607' N 002º 20.914' E");
});
it("should convert to degree minutes seconds (south, west)", () => {
expect(new GeographicCoordinateConverter(-36.01011, -2.34856).toDegreeMinutesSeconds()).toBe("36º 00' 36.4'' S 002º 20' 54.8'' W");
});
it("should convert to degree minutes seconds", () => {
expect(new GeographicCoordinateConverter(36.01011, 2.34856).toDegreeMinutesSeconds()).toBe("36º 00' 36.4'' N 002º 20' 54.8'' E");
});
});