-
-
Notifications
You must be signed in to change notification settings - Fork 1
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 #6 from celestiary/dev
Updates to Time
- Loading branch information
Showing
20 changed files
with
323 additions
and
203 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
import {readFileSync} from 'fs' | ||
|
||
import AsterismsCatalog from './AsterismsCatalog.js' | ||
import StarsCatalog from './StarsCatalog.js' | ||
import {toArrayBuffer} from './utils.js' | ||
|
||
|
||
describe('AsterismsCatalog', () => { | ||
it('constructor loads data', () => { | ||
const starsCatalog = new StarsCatalog() | ||
starsCatalog.read(toArrayBuffer(readFileSync('./public/data/stars.dat'))) | ||
expect(starsCatalog.numStars).toEqual(106747) | ||
const asterisms = new AsterismsCatalog(starsCatalog) | ||
asterisms.read(readFileSync('./public/data/asterisms.dat', 'utf-8')) | ||
expect(asterisms.byName.size).toEqual(89) | ||
}) | ||
}) | ||
|
This file was deleted.
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 |
---|---|---|
@@ -0,0 +1,55 @@ | ||
import {readFileSync} from 'fs' | ||
|
||
import StarsCatalog from './StarsCatalog.js' | ||
import {toArrayBuffer} from './utils.js' | ||
|
||
|
||
const STARS_DAT = './public/data/stars.dat' | ||
const STAR_NAMES_DAT = './public/data/starnames.dat' | ||
|
||
const TEST_STAR = { | ||
x: 0, | ||
y: 0, | ||
z: 0, | ||
hipId: 0, | ||
absMag: 1, | ||
kind: 'M', | ||
spectralType: '0', | ||
sub: '0', | ||
lumClass: 1, | ||
lumRelSun: 1, | ||
radius: 1, | ||
} | ||
|
||
|
||
describe('StarsCatalog', () => { | ||
it('minimal catalog loads', () => { | ||
const starByHip = {0: TEST_STAR} | ||
const hipByName = {Sun: 0} | ||
const namesByHip = {0: ['Sun']} | ||
const minMag = 10 | ||
const maxMag = 1 | ||
const catalog = new StarsCatalog(1, starByHip, hipByName, namesByHip, minMag, maxMag) | ||
expect(catalog.numStars).toEqual(1) | ||
}) | ||
|
||
it('StarsCatalog#read', () => { | ||
const catalog = new StarsCatalog() | ||
catalog.read(toArrayBuffer(readFileSync(STARS_DAT))) | ||
expect(catalog.numStars).toEqual(106747) | ||
}) | ||
|
||
it('StarsCatalog#downsample', () => { | ||
let catalog = new StarsCatalog() | ||
catalog = catalog.read(toArrayBuffer(readFileSync(STARS_DAT))).downsample(1000) | ||
expect(catalog.numStars).toEqual(1000) | ||
}) | ||
|
||
it('StarsCatalog#readNames', () => { | ||
const catalog = new StarsCatalog() | ||
catalog.read(toArrayBuffer(readFileSync(STARS_DAT))) | ||
catalog.readNames(readFileSync(STAR_NAMES_DAT, 'utf-8')) | ||
// TODO(pablo): was 5699 | ||
expect(catalog.hipByName.size).toEqual(5672) | ||
}) | ||
}) |
This file was deleted.
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 |
---|---|---|
@@ -0,0 +1,19 @@ | ||
import {timeToDateStr} from './Time' | ||
|
||
|
||
describe('Time', () => { | ||
describe('timeToDateStr', () => { | ||
it('handles start of unix epoch', () => { | ||
expect(timeToDateStr(0).toString()).toEqual('1970 Jan 1 at 12:00:00 AM') | ||
}) | ||
|
||
it('handles future', () => { | ||
expect(timeToDateStr(1000000000000000).toString()).toEqual('33,658 Sep 27 at 1:46:40 AM') | ||
}) | ||
|
||
it('handles past', () => { | ||
expect(timeToDateStr(-1000000000000000).toString()).toEqual('-29,719 Apr 5 at 10:13:20 PM') | ||
}) | ||
}) | ||
}) | ||
|
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,81 @@ | ||
import { | ||
G, | ||
step, | ||
// updateAccelerations, | ||
} from './gravity.js' | ||
|
||
|
||
describe('gravity', () => { | ||
it('particle at rest', () => { | ||
const pos = [0, 0, 0] | ||
const vel = [0, 0, 0] | ||
const acc = [null, null, null] | ||
const mass = [1] | ||
|
||
const zeros = [0, 0, 0] | ||
applyAndAssert( | ||
pos, vel, acc, mass, | ||
zeros, pos, | ||
zeros, vel, | ||
zeros, acc) | ||
expect(mass[0]).toEqual(1) | ||
}) | ||
|
||
|
||
it('particle in motion', () => { | ||
const pos = [0, 0, 0] | ||
const vel = [1, 2, 3] | ||
const acc = [null, null, null] | ||
const mass = [1] | ||
applyAndAssert( | ||
pos, vel, acc, mass, | ||
[1, 2, 3], pos, | ||
[1, 2, 3], vel, | ||
[0, 0, 0], acc) | ||
}) | ||
|
||
|
||
it('two particles', () => { | ||
const pos = [0, 0, 0, 1, 0, 0] | ||
const vel = [0, 0, 0, 0, 0, 0] | ||
const acc = [null, null, null, null, null, null] | ||
const mass = [1, 1] | ||
applyAndAssert( | ||
pos, vel, acc, mass, | ||
[0, 0, 0, 1, 0, 0], pos, | ||
[G / 2, 0, 0, -G / 2, 0, 0], vel, | ||
[G, 0, 0, -G, 0, 0], acc, | ||
'on first step') | ||
/* tests.applyAndAssert(pos, vel, acc, mass, | ||
[G, 0, 0, 1-G, 0, 0], pos, | ||
[G, 0, 0, -G, 0, 0], vel, | ||
[2*G, 0, 0, -2*G, 0, 0], acc, | ||
'on second step')*/ | ||
}) | ||
}) | ||
|
||
|
||
/** Expect vectors and components to be equal */ | ||
function assertVectorsEqual(vec1, vec2, appendMsg = '') { | ||
if (vec1.length !== vec2.length) { | ||
throw new Error('vector lengths must be equal') | ||
} | ||
for (let i = 0; i < vec1.length; i++) { | ||
expect(vec1[i]).toEqual(vec2[i]) | ||
} | ||
} | ||
|
||
|
||
/** Apply step and test vectors */ | ||
function applyAndAssert( | ||
pos, vel, acc, mass, | ||
expPos, actPos, | ||
expVel, actVel, | ||
expAcc, actAcc, | ||
appendMsg = '') { | ||
const dt = 1 | ||
step(pos, vel, acc, mass, dt) | ||
assertVectorsEqual(expPos, actPos, `for pos ${appendMsg}`) | ||
assertVectorsEqual(expVel, actVel, `for vel ${appendMsg}`) | ||
assertVectorsEqual(expAcc, actAcc, `for acclerations ${appendMsg}`) | ||
} |
Oops, something went wrong.