Skip to content

Commit

Permalink
feat: test the getMoveDirection
Browse files Browse the repository at this point in the history
  • Loading branch information
RoxaneBurri committed Mar 13, 2023
1 parent 7d925a3 commit 7b1ab39
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 4 deletions.
2 changes: 0 additions & 2 deletions src/App.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import "./App.css";
import {
futurPosition,
getArea,
getBoundingRect,
placeWordOnOuterCircle,
Word,
Expand Down Expand Up @@ -71,7 +70,6 @@ const Wordcloud = () => {
...word,
rect: newPositions[idx],
}));

});
};

Expand Down
44 changes: 43 additions & 1 deletion src/utils.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
import { describe, expect, it } from "vitest";
import { areCentersTooClose, Coordinate, Rectangle } from "./utils";
import {
areCentersTooClose,
Coordinate,
getBoundingRect,
Rectangle,
getMoveDirection,
} from "./utils";

const origin: Coordinate = {
x: 0,
Expand Down Expand Up @@ -28,3 +34,39 @@ describe("areCentersTooClose", () => {
expect(areCentersTooClose({ x: -2, y: -2 }, origin, 2.5, 2.5)).toBe(true);
});
});

describe("Get move direction", () => {
it("Test with three rectangle", () => {
const rect = { id: "word-1", text: " Big word ", coef: 0.99 };

expect(
getMoveDirection(
[
{
x: 4,
y: 6,
width: 4,
height: 4,
},
{
x: 8,
y: 5,
width: 7,
height: 7,
},
],
{
x: 3,
y: 4,
width: 3,
height: 3,
}
)
).toEqual({
x: 6,
y: 3,
width: 3,
height: 3,
});
});
});
2 changes: 1 addition & 1 deletion src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ export const placeWordOnOuterCircle = (w: Rectangle) => {
return newPosition;
};

const getMoveDirection = (
export const getMoveDirection = (
pastWords: Rectangle[],
currentWord: Rectangle
): Coordinate => {
Expand Down

0 comments on commit 7b1ab39

Please sign in to comment.