Skip to content

Commit

Permalink
first test
Browse files Browse the repository at this point in the history
  • Loading branch information
lounsbrough committed Aug 22, 2024
1 parent 28bfe3f commit db1d9a1
Show file tree
Hide file tree
Showing 10 changed files with 193 additions and 22 deletions.
16 changes: 13 additions & 3 deletions eslint.config.mjs
Original file line number Diff line number Diff line change
@@ -1,14 +1,24 @@
// @ts-check

import eslint from '@eslint/js';
import tseslint from 'typescript-eslint';
import eslint from '@eslint/js'
import tseslint from 'typescript-eslint'
import jest from 'eslint-plugin-jest'

export default tseslint.config(
eslint.configs.recommended,
...tseslint.configs.recommended,
{
files: ['test/**'],
...jest.configs['flat/recommended']
},
{
ignores: [
'lib/'
]
},
{
rules: {
'semi': ['error', 'never']
}
}
);
)
8 changes: 8 additions & 0 deletions jest.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
/** @type {import('ts-jest').JestConfigWithTsJest} **/
// eslint-disable-next-line no-undef
module.exports = {
testEnvironment: "node",
transform: {
"^.+.tsx?$": ["ts-jest", {}],
},
}
5 changes: 4 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
"build-demo": "pnpm --prefix demo build",
"deploy-demo": "pnpm build-demo && gh-pages -d demo/build",
"lint": "eslint",
"test": "jest --passWithNoTests"
"test": "jest"
},
"keywords": [
"body",
Expand All @@ -43,11 +43,14 @@
"@eslint/js": "^9.9.0",
"@rollup/plugin-typescript": "^11.1.6",
"@types/eslint__js": "^8.42.3",
"@types/jest": "^29.5.12",
"@types/node": "^22.5.0",
"eslint": "^9.9.0",
"eslint-plugin-jest": "^28.8.0",
"gh-pages": "^6.1.1",
"jest": "^29.7.0",
"rollup": "^4.21.0",
"ts-jest": "^29.2.4",
"ts-node": "^10.9.2",
"tslib": "^2.6.3",
"typescript": "^5.5.4",
Expand Down
133 changes: 133 additions & 0 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion rollup.config.mjs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import fs from 'fs'
import typescript from '@rollup/plugin-typescript'

const packageJson = JSON.parse(fs.readFileSync('./package.json'));
const packageJson = JSON.parse(fs.readFileSync('./package.json'))

export default {
input: 'src/index.ts',
Expand Down
17 changes: 17 additions & 0 deletions src/Body.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import Body from "./Body"
import Vector from "./Vector"

describe('Body', () => {
describe('moveBodyThroughTime', () => {
it('should move body through delta time', () => {
const body = new Body({
position: new Vector(0, 0, 0),
velocity: new Vector(1, 2, -3)
})

body.moveBodyThroughTime(1)

expect(body.velocity).toEqual(new Vector(1, 2, -3))
})
})
})
6 changes: 3 additions & 3 deletions src/Body.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import Vector from './Vector';
import Vector from './Vector'

export default class Body {
mass: number
Expand Down Expand Up @@ -37,7 +37,7 @@ export default class Body {
}

setExternalForces(externalForces: Vector[]) {
this.externalForces = externalForces;
this.externalForces = externalForces

this.netExternalForce = this.externalForces.reduce((total, force) => {
total.x += force.x
Expand All @@ -59,7 +59,7 @@ export default class Body {
const deltaPosition = this.velocity.scaleBy(deltaTime)
this.position = this.position.sum(deltaPosition)
if (this.pastPositions.length >= this.tailLength) {
this.pastPositions.pop();
this.pastPositions.pop()
}
this.pastPositions.unshift(this.position)
}
Expand Down
Loading

0 comments on commit db1d9a1

Please sign in to comment.