1 | import { expect } from 'chai';
|
2 |
|
3 | import computeDeltas from '../computeDeltas';
|
4 |
|
5 | describe("computeDeltas", () => {
|
6 | it("should return a dx and a dy of 0 when the positions are the same", () => {
|
7 | const position = {x: 100, y: 100};
|
8 | expect(computeDeltas(position, position)).to.eql({dx: 0, dy: 0});
|
9 | });
|
10 |
|
11 | it("should return a negative dx when the position moves left", () => {
|
12 | const initial = {x: 100, y: 100};
|
13 | const current = {x: 80, y: 100};
|
14 | expect(computeDeltas(initial, current)).to.eql({dx: -20, dy: 0});
|
15 | });
|
16 |
|
17 | it("should return a positve dx when the position moves right", () => {
|
18 | const initial = {x: 100, y: 100};
|
19 | const current = {x: 120, y: 100};
|
20 | expect(computeDeltas(initial, current)).to.eql({dx: 20, dy: 0});
|
21 | });
|
22 |
|
23 | it("should return a positive dy when the position moves down", () => {
|
24 | const initial = {x: 100, y: 100};
|
25 | const current = {x: 100, y: 120};
|
26 | expect(computeDeltas(initial, current)).to.eql({dx: 0, dy: 20});
|
27 | });
|
28 |
|
29 | it("should return a negative dy when the position moves up", () => {
|
30 | const initial = {x: 100, y: 100};
|
31 | const current = {x: 100, y: 80};
|
32 | expect(computeDeltas(initial, current)).to.eql({dx: 0, dy: -20});
|
33 | });
|
34 |
|
35 | it("should return non-zero deltas when the position moves in two directions", () => {
|
36 | const initial = {x: 100, y: 100};
|
37 | const current = {x: 120, y: 120};
|
38 | expect(computeDeltas(initial, current)).to.eql({dx: 20, dy: 20});
|
39 | });
|
40 | });
|