-
-
Notifications
You must be signed in to change notification settings - Fork 5.7k
Fix/742 migrate doctest for Vector2.js #752
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 1 commit
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
adf6981
Migrate doctest for Vector2.js
FabianKielmann 6aa9997
Remove eslint disabling for no-unused-vars since now the class is exp…
FabianKielmann 6f7f48e
Group all related tests to own jest describe blocks
FabianKielmann 5df4edd
Improve the doc-comment by fixing it's formatting
FabianKielmann File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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,58 @@ | ||
import { Vector2 } from './Vector2.js' | ||
|
||
describe('Tests for Vector2 data scructure implementation', () => { | ||
test('tests equalsExactly-method', () => { | ||
FabianKielmann marked this conversation as resolved.
Show resolved
Hide resolved
|
||
expect(new Vector2(1, 0).equalsExactly(new Vector2(1, 0))).toBe(true) | ||
expect(new Vector2(1.23, 4.56).equalsExactly(new Vector2(0, 0))).toBe(false) | ||
}) | ||
|
||
test('tests equalsApproximately-method', () => { | ||
expect(new Vector2(1, 0).equalsApproximately(new Vector2(1, 0.0000001), 0.000001)).toBe(true) | ||
expect(new Vector2(1.23, 4.56).equalsApproximately(new Vector2(1.24, 4.56), 0.000001)).toBe(false) | ||
}) | ||
|
||
test('tests add-method', () => { | ||
expect(new Vector2(1, 0).add(new Vector2(0, 1)).equalsApproximately(new Vector2(1, 1), 0.000001)).toBe(true) | ||
expect(new Vector2(-3.3, -9).add(new Vector2(-2.2, 3)).equalsApproximately(new Vector2(-5.5, -6), 0.000001)).toBe(true) | ||
}) | ||
|
||
test('tests subtract-method', () => { | ||
expect(new Vector2(1, 0).subtract(new Vector2(0, 1)).equalsApproximately(new Vector2(1, -1), 0.000001)).toBe(true) | ||
expect(new Vector2(234.5, 1.7).subtract(new Vector2(3.3, 2.7)).equalsApproximately(new Vector2(231.2, -1), 0.000001)).toBe(true) | ||
}) | ||
|
||
test('tests multiply-method', () => { | ||
expect(new Vector2(1, 0).multiply(5).equalsApproximately(new Vector2(5, 0), 0.000001)).toBe(true) | ||
expect(new Vector2(3.41, -7.12).multiply(-3.1).equalsApproximately(new Vector2(-10.571, 22.072), 0.000001)).toBe(true) | ||
}) | ||
|
||
test('tests length-method', () => { | ||
expect(new Vector2(1, 0).length()).toBe(1) | ||
expect(new Vector2(-1, 1).length()).toBe(Math.sqrt(2)) | ||
}) | ||
|
||
test('tests normalize-method', () => { | ||
expect(new Vector2(1, 0).normalize().equalsApproximately(new Vector2(1, 0), 0.000001)).toBe(true) | ||
expect(new Vector2(1, -1).normalize().equalsApproximately(new Vector2(Math.sqrt(2) / 2, -Math.sqrt(2) / 2), 0.000001)).toBe(true) | ||
}) | ||
|
||
test('tests distance-method', () => { | ||
expect(new Vector2(0, 0).distance(new Vector2(0, -1))).toBe(1) | ||
expect(new Vector2(1, 0).distance(new Vector2(0, 1))).toBe(Math.sqrt(2)) | ||
}) | ||
|
||
test('tests dotProduct-method', () => { | ||
expect(new Vector2(1, 0).dotProduct(new Vector2(0, 1))).toBe(0) | ||
expect(new Vector2(1, 2).dotProduct(new Vector2(3, 4))).toBe(1 * 3 + 2 * 4) | ||
}) | ||
|
||
test('tests rotate-method', () => { | ||
expect(new Vector2(0, -1).rotate(Math.PI / 2).equalsApproximately(new Vector2(1, 0), 0.000001)).toBe(true) | ||
expect(new Vector2(1.23, -4.56).rotate(Math.PI).equalsApproximately(new Vector2(-1.23, 4.56), 0.000001)).toBe(true) | ||
}) | ||
|
||
test('tests angleBetween-method', () => { | ||
expect(new Vector2(1, 0).angleBetween(new Vector2(0, 1))).toBe(Math.PI / 2) | ||
expect(new Vector2(1, 0).angleBetween(new Vector2(1, -1))).toBe(-Math.PI / 4) | ||
}) | ||
}) |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.