Skip to content

Commit

Permalink
2023-09-11T15:05:17.905Z
Browse files Browse the repository at this point in the history
  • Loading branch information
mattpocock committed Sep 11, 2023
1 parent f3cf1af commit 7018934
Show file tree
Hide file tree
Showing 7 changed files with 80 additions and 0 deletions.
Empty file.
Empty file.
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import { describe, expect, it } from "vitest";

class CanvasNode {
x = 0;
y = 0;

move(x: number, y: number) {
this.x = x;
this.y = y;
}
}

const positionFromCanvasNode = (node) => {
return {
x: node.x,
y: node.y,
};
};

describe("positionFromCanvasNode", () => {
it("Should return the position of the node", () => {
const canvasNode = new CanvasNode();

expect(positionFromCanvasNode(canvasNode)).toEqual({ x: 0, y: 0 });

canvasNode.move(10, 20);

expect(positionFromCanvasNode(canvasNode)).toEqual({ x: 10, y: 20 });
});
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import { describe, expect, it } from "vitest";

class CanvasNode {
x = 0;
y = 0;

move(x: number, y: number) {
this.x = x;
this.y = y;
}
}

// Look at typeof CanvasNode
const positionFromCanvasNode = (node: CanvasNode) => {
return {
x: node.x,
y: node.y,
};
};

describe("positionFromCanvasNode", () => {
it("Should return the position of the node", () => {
const canvasNode = new CanvasNode();

expect(positionFromCanvasNode(canvasNode)).toEqual({ x: 0, y: 0 });

canvasNode.move(10, 20);

expect(positionFromCanvasNode(canvasNode)).toEqual({ x: 10, y: 20 });
});
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
class CanvasNode {
x: number;
y: number;

constructor(x: number, y: number) {
this.x = x;
this.y = y;
}

move(x: number, y: number): this {
this.x += x;
this.y += y;
return this;
}
}

const node = new CanvasNode(0, 0).move(10, 20).move(30, 40);

type test = Expect<Equal<typeof node, CanvasNode>>;
Empty file.
Empty file.

0 comments on commit 7018934

Please sign in to comment.