Skip to content

Commit

Permalink
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add additional tests to Vector2
Browse files Browse the repository at this point in the history
Flashky committed Dec 1, 2023
1 parent 6453c11 commit 385ea9c
Showing 1 changed file with 50 additions and 1 deletion.
51 changes: 50 additions & 1 deletion src/test/java/com/adventofcode/flashk/common/Vector2Test.java
Original file line number Diff line number Diff line change
@@ -9,6 +9,8 @@

import nl.jqno.equalsverifier.EqualsVerifier;

import java.text.DecimalFormat;

class Vector2Test {

// Constructors tests
@@ -29,7 +31,7 @@ void testVector2Vector2() {
assertEquals(expected, result);
assertNotSame(expected, result);
}

@Test
void testVector2String() {
Vector2 result = new Vector2("2,3");
@@ -129,7 +131,54 @@ void testUpDownLeft(){
}

// Transform tests

@Test
void testDistance() {
Vector2 v1 = new Vector2(2,3);
Vector2 v2 = new Vector2(3,5);

double value = Vector2.distance(v1, v2);
// 2.23607
DecimalFormat numberFormat = new DecimalFormat("#.00000");

assertEquals("2,23607", numberFormat.format(value));
}

@Test
void testTransformScalar() {
Vector2 startPos = new Vector2(2,5);
startPos.transform(3);

assertEquals(5, startPos.getX());
assertEquals(8, startPos.getY());
}

@Test
void testTransformX() {
Vector2 startPos = new Vector2(2, 5);
startPos.transformX(3);

assertEquals(5, startPos.getX());
}

@Test
void testTransformY() {
Vector2 startPos = new Vector2(2, 5);
startPos.transformY(3);

assertEquals(8, startPos.getY());
}

@Test
void testTransformStatic() {
Vector2 startPos = new Vector2(2,5);
Vector2 endPos = new Vector2(3,7);
Vector2 result = Vector2.transform(startPos, endPos);

assertEquals(5, result.getX());
assertEquals(12, result.getY());
}

@Test
void testTransform() {

0 comments on commit 385ea9c

Please sign in to comment.