|
@@ -0,0 +1,45 @@
|
|
|
+import { SPoint } from "../../src";
|
|
|
+
|
|
|
+test("构造函数", () => {
|
|
|
+ expect(new SPoint().toJson()).toBe("{\"x\":0,\"y\":0}");
|
|
|
+ expect(new SPoint(10, 10).toJson()).toBe("{\"x\":10,\"y\":10}");
|
|
|
+});
|
|
|
+
|
|
|
+test("属性修改", () => {
|
|
|
+ const p = new SPoint();
|
|
|
+ expect(p.toJson()).toBe("{\"x\":0,\"y\":0}");
|
|
|
+
|
|
|
+ p.y = 10;
|
|
|
+ expect(p.toJson()).toBe("{\"x\":0,\"y\":10}");
|
|
|
+ p.x = -10;
|
|
|
+ expect(p.toJson()).toBe("{\"x\":-10,\"y\":10}");
|
|
|
+
|
|
|
+ p.setPoint(-100, -30);
|
|
|
+ expect(p.toJson()).toBe("{\"x\":-100,\"y\":-30}");
|
|
|
+
|
|
|
+ p.setPoint(new SPoint(-5, -12));
|
|
|
+ expect(p.toJson()).toBe("{\"x\":-5,\"y\":-12}");
|
|
|
+});
|
|
|
+
|
|
|
+test("setPoint()", () => {
|
|
|
+ const p = new SPoint();
|
|
|
+ p.setPoint(-100, -30);
|
|
|
+ expect(p.toJson()).toBe("{\"x\":-100,\"y\":-30}");
|
|
|
+
|
|
|
+ p.setPoint(new SPoint(-5, -12));
|
|
|
+ expect(p.toJson()).toBe("{\"x\":-5,\"y\":-12}");
|
|
|
+});
|
|
|
+
|
|
|
+test("manhattanLength()", () => {
|
|
|
+ const p = new SPoint(10, 20);
|
|
|
+ expect(p.manhattanLength()).toBe(30);
|
|
|
+
|
|
|
+ p.setPoint(-10, 20);
|
|
|
+ expect(p.manhattanLength()).toBe(30);
|
|
|
+
|
|
|
+ p.setPoint(10, -20);
|
|
|
+ expect(p.manhattanLength()).toBe(30);
|
|
|
+
|
|
|
+ p.setPoint(-10, -20);
|
|
|
+ expect(p.manhattanLength()).toBe(30);
|
|
|
+});
|