-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #15 from Rennzie/10-add-tests-for-the-js-wrapper
10 add tests for the js wrapper
- Loading branch information
Showing
13 changed files
with
195 additions
and
921 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,22 +1,38 @@ | ||
name: Rust | ||
name: Build and Check | ||
|
||
on: | ||
push: | ||
branches: [ "master" ] | ||
branches: ['master'] | ||
pull_request: | ||
branches: [ "master" ] | ||
branches: ['master'] | ||
|
||
env: | ||
CARGO_TERM_COLOR: always | ||
|
||
jobs: | ||
build: | ||
|
||
bindings: | ||
runs-on: ubuntu-latest | ||
|
||
steps: | ||
- uses: actions/checkout@v3 | ||
- name: Build | ||
run: cargo build --verbose | ||
- name: Run tests | ||
run: cargo test --verbose | ||
- uses: actions/checkout@v3 | ||
- name: Build | ||
run: cargo build --verbose | ||
- name: Run tests | ||
run: cargo test --verbose | ||
|
||
wrapper: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@v3 | ||
- uses: oven-sh/setup-bun@v1 | ||
with: | ||
bun-version: latest | ||
- uses: jetli/[email protected] | ||
with: | ||
version: 'latest' | ||
|
||
- name: Build Dev Wrapper | ||
run: bun build:wrapper-dev | ||
|
||
- name: Run Wrapper Tests | ||
run: bun test:wrapper |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,6 +4,8 @@ version = "0.2.0--alpha1" | |
keywords = ["geospatial", "geodesy", "cartography", "geography"] | ||
categories = ["science"] | ||
authors = ["Sean Rennie <[email protected]>"] | ||
description = "A WASM wrapper around the Rust Geodesy crate" | ||
repository = "https://github.com/Rennzie/geodesy-wasm" | ||
license = "MIT OR Apache-2.0" | ||
edition = "2021" | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
import {test, describe, expect} from 'bun:test'; | ||
import {Geodesy} from './geodesy'; | ||
|
||
const DEG_TO_RAD = Math.PI / 180; | ||
const stdPipelineDefinition = ` | ||
+proj=pipeline | ||
+step +inv +proj=tmerc +lat_0=49 +lon_0=-2 +k_0=0.9996012717 +x_0=400000 +y_0=-100000 +ellps=airy | ||
+step +proj=webmerc +lat_0=0 +lon_0=0 +x_0=0 +y_0=0 +ellps=WGS84 | ||
`; | ||
|
||
const gsbPipelineDefinition = ` | ||
| tmerc inv lat_0=49 lon_0=-2 k_0=0.9996012717 x_0=400000 y_0=-100000 ellps=airy | ||
| gridshift grids=OSTN15_NTv2_OSGBtoETRS.gsb | ||
| webmerc lat_0=0 lon_0=0 x_0=0 y_0=0 ellps=WGS84 | ||
`; | ||
|
||
const COPENHAGEN_GEO_2D = [55, 12]; | ||
const LONDON_BNG_3D = [544748.5367636156, 258372.49178149243, 9.61]; | ||
|
||
describe('Geodesy', () => { | ||
describe('Transform', () => { | ||
test('Basic geographic transform', () => { | ||
const ctx = new Geodesy('utm zone=32'); | ||
const res = ctx.forward([COPENHAGEN_GEO_2D.map(v => v * DEG_TO_RAD)]); | ||
expect(res).toEqual([[6080642.1129675, 1886936.9691340544]]); | ||
ctx['ctx'].free(); | ||
}); | ||
|
||
test('Should be able to use a PROJ string', () => { | ||
const ctx = new Geodesy('+proj=utm +zone=32'); | ||
const res = ctx.forward([COPENHAGEN_GEO_2D.map(v => v * DEG_TO_RAD)]); | ||
expect(res).toEqual([[6080642.1129675, 1886936.9691340544]]); | ||
ctx['ctx'].free(); | ||
}); | ||
|
||
test('Should be able to use a PROJ pipeline', () => { | ||
const ctx = new Geodesy(stdPipelineDefinition); | ||
const res = ctx.roundTrip([LONDON_BNG_3D])[0]; | ||
|
||
for (const coord of res) { | ||
expect(coord).toBeCloseTo(0, 5); | ||
} | ||
|
||
ctx['ctx'].free(); | ||
}); | ||
|
||
test('Should be able to use an NTv2 gridshift file', async () => { | ||
// TODO: How can we use __dirname here? | ||
const file = Bun.file('./js/fixtures/OSTN15_NTv2_OSGBtoETRS.gsb'); | ||
const buf = Buffer.from(await file.arrayBuffer()); | ||
const gsb = new DataView(buf.buffer); | ||
|
||
const ctx = new Geodesy(gsbPipelineDefinition, { | ||
'OSTN15_NTv2_OSGBtoETRS.gsb': gsb, | ||
}); | ||
|
||
const res = ctx.roundTrip([LONDON_BNG_3D])[0]; | ||
|
||
for (const coord of res) { | ||
expect(coord).toBeCloseTo(0, 5); | ||
} | ||
|
||
ctx['ctx'].free(); | ||
}); | ||
}); | ||
|
||
describe('Errors', () => { | ||
test('Should error if coordinate is not 2D or 3D', () => { | ||
const ctx = new Geodesy('utm zone=32'); | ||
expect(() => ctx.forward([[1, 2, 3, 4]])).toThrow(); | ||
ctx['ctx'].free(); | ||
}); | ||
|
||
test('Should error if coordinate dimensions are not consistent', () => { | ||
const ctx = new Geodesy('utm zone=32'); | ||
expect(() => | ||
ctx.inverse([ | ||
[1, 2], | ||
[1, 2, 3], | ||
]), | ||
).toThrow(); | ||
ctx['ctx'].free(); | ||
}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.