-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
241 additions
and
120 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,36 +1,72 @@ | ||
import { expect } from "chai"; | ||
import { beacon, isNearby, isOnCourse } from "./beacon"; | ||
import { beacon, isNearby, isOnCourse, relativePosition } from "./beacon"; | ||
import { myLocation } from '../state/location'; | ||
|
||
describe("beacon", () => { | ||
it("should calculate on/off course", () => { | ||
describe("Beacon", () => { | ||
beforeEach(() => { | ||
// Set beacon to Washington monument | ||
beacon.set("Washington Monument", 38.889444, -77.035278); | ||
beacon.enable(); | ||
|
||
// US Capitol (due east of monument) | ||
// Set our location to US Capitol (due east of monument) | ||
myLocation.setLocation(38.889722, -77.008889); | ||
// Various heading roughly facing west | ||
[-90.0, -95.0, -85.0].forEach(heading => { | ||
myLocation.setHeading(heading); | ||
expect(isOnCourse.value).to.be.true; | ||
}); | ||
|
||
describe('relativePosition', () => { | ||
[-90.0, -179.0, -1.0].forEach(heading => { | ||
it(`should be in front at heading ${heading}`, () => { | ||
// Beacon is in front of us | ||
myLocation.setHeading(heading); | ||
expect(relativePosition.value!.y).to.be.greaterThan(0); | ||
}); | ||
}); | ||
|
||
[90.0, 179.0, 1.0].forEach(heading => { | ||
it(`should be behind at heading ${heading}`, () => { | ||
myLocation.setHeading(heading); | ||
expect(relativePosition.value!.y).to.be.lessThan(0); | ||
}); | ||
}); | ||
|
||
[-89.0, 0.0, 89.0].forEach(heading => { | ||
it(`should be to the left at heading ${heading}`, () => { | ||
myLocation.setHeading(heading); | ||
expect(relativePosition.value!.x).to.be.lessThan(0); | ||
}); | ||
}); | ||
|
||
[-91.0, 180.0, 91.0].forEach(heading => { | ||
it(`should be to the right at heading ${heading}`, () => { | ||
myLocation.setHeading(heading); | ||
expect(relativePosition.value!.x).to.be.greaterThan(0); | ||
}); | ||
}); | ||
}); | ||
|
||
// Various headings facing any other direction | ||
describe('isOnCourse', () => { | ||
[-90.0, -95.0, -85.0].forEach(heading => { | ||
it(`should be on course at heading ${heading}`, () => { | ||
myLocation.setHeading(heading); | ||
expect(isOnCourse.value).to.be.true; | ||
}); | ||
}); | ||
|
||
[0.0, 90.0, 180.0, -130.0, -50.0].forEach(heading => { | ||
myLocation.setHeading(heading); | ||
expect(isOnCourse.value).to.be.false; | ||
it(`should be off course at heading ${heading}`, () => { | ||
myLocation.setHeading(heading); | ||
expect(isOnCourse.value).to.be.false; | ||
}); | ||
}); | ||
}); | ||
|
||
it("should recognize nearby threshold", () => { | ||
beacon.set("Washington Monument", 38.889444, -77.035278); | ||
beacon.enable(); | ||
|
||
// US Capitol (due east of monument) | ||
myLocation.setLocation(38.889722, -77.008889); | ||
expect(isNearby.value).to.be.false; | ||
|
||
myLocation.setLocation(beacon.latitude!, beacon.longitude!); | ||
expect(isNearby.value).to.be.true; | ||
describe('isNearby', () => { | ||
it("should be false when far away", () => { | ||
expect(isNearby.value).to.be.false; | ||
}); | ||
|
||
it("should be true when nearby", () => { | ||
myLocation.setLocation(beacon.latitude!, beacon.longitude!); | ||
expect(isNearby.value).to.be.true; | ||
}); | ||
}); | ||
}); |
Oops, something went wrong.