cm-chessboard 4.5.1 → 4.5.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +1 -1
- package/test/TestBoard.js +2 -2
- package/test/TestChessboard.js +7 -7
- package/test/TestMarkers.js +13 -13
- package/test/TestPiecesAnimation.js +23 -23
- package/test/TestPosition.js +10 -10
package/package.json
CHANGED
package/test/TestBoard.js
CHANGED
|
@@ -23,9 +23,9 @@ describe("TestBoard", () => {
|
|
|
23
23
|
sprite: {url: "../assets/images/chessboard-sprite.svg"},
|
|
24
24
|
position: "start"
|
|
25
25
|
})
|
|
26
|
-
assert.
|
|
26
|
+
assert.equal(chessboard.view.context.childNodes.length, 1)
|
|
27
27
|
chessboard.destroy()
|
|
28
|
-
assert.
|
|
28
|
+
assert.equal(chessboard.state, undefined)
|
|
29
29
|
})
|
|
30
30
|
|
|
31
31
|
})
|
package/test/TestChessboard.js
CHANGED
|
@@ -14,7 +14,7 @@ describe("TestChessboard", () => {
|
|
|
14
14
|
sprite: {url: "../assets/images/chessboard-sprite.svg"},
|
|
15
15
|
position: "start"
|
|
16
16
|
})
|
|
17
|
-
assert.
|
|
17
|
+
assert.equal(chessboard.getPosition(), "rnbqkbnr/pppppppp/8/8/8/8/PPPPPPPP/RNBQKBNR")
|
|
18
18
|
chessboard.destroy()
|
|
19
19
|
})
|
|
20
20
|
|
|
@@ -22,7 +22,7 @@ describe("TestChessboard", () => {
|
|
|
22
22
|
const chessboard = new Chessboard(document.getElementById("TestPosition"),
|
|
23
23
|
{sprite: {url: "../assets/images/chessboard-sprite.svg"},})
|
|
24
24
|
chessboard.setPosition("rn2k1r1/ppp1pp1p/3p2p1/5bn1/P7/2N2B2/1PPPPP2/2BNK1RR w Gkq - 4 11", false).then(() => {
|
|
25
|
-
assert.
|
|
25
|
+
assert.equal(chessboard.getPosition(), "rn2k1r1/ppp1pp1p/3p2p1/5bn1/P7/2N2B2/1PPPPP2/2BNK1RR")
|
|
26
26
|
chessboard.destroy()
|
|
27
27
|
})
|
|
28
28
|
})
|
|
@@ -32,9 +32,9 @@ describe("TestChessboard", () => {
|
|
|
32
32
|
sprite: {url: "../assets/images/chessboard-sprite.svg"},
|
|
33
33
|
position: "start"
|
|
34
34
|
})
|
|
35
|
-
assert.
|
|
36
|
-
assert.
|
|
37
|
-
assert.
|
|
35
|
+
assert.equal(chessboard.getPiece("d1"), "wq")
|
|
36
|
+
assert.equal(chessboard.getPiece("d8"), "bq")
|
|
37
|
+
assert.equal(chessboard.getPiece("a2"), "wp")
|
|
38
38
|
chessboard.destroy()
|
|
39
39
|
})
|
|
40
40
|
|
|
@@ -44,9 +44,9 @@ describe("TestChessboard", () => {
|
|
|
44
44
|
sprite: {url: "../assets/images/chessboard-sprite.svg"},
|
|
45
45
|
})
|
|
46
46
|
chessboard.setPiece("a1", PIECE.bk)
|
|
47
|
-
assert.
|
|
47
|
+
assert.equal(chessboard.getPiece("a1"), "bk")
|
|
48
48
|
chessboard.setPiece("e5", PIECE.wk)
|
|
49
|
-
assert.
|
|
49
|
+
assert.equal(chessboard.getPiece("e5"), "wk")
|
|
50
50
|
chessboard.destroy()
|
|
51
51
|
})
|
|
52
52
|
|
package/test/TestMarkers.js
CHANGED
|
@@ -17,24 +17,24 @@ describe("TestMarkers", () => {
|
|
|
17
17
|
chessboard.addMarker("e5", MARKER_TYPE.square)
|
|
18
18
|
chessboard.addMarker("b6", MARKER_TYPE.frame)
|
|
19
19
|
chessboard.addMarker("h6", MARKER_TYPE.frame)
|
|
20
|
-
assert.
|
|
20
|
+
assert.equal(chessboard.getMarkers().length,3)
|
|
21
21
|
const markersE5 = chessboard.getMarkers("e5")
|
|
22
|
-
assert.
|
|
23
|
-
assert.
|
|
24
|
-
assert.
|
|
25
|
-
assert.
|
|
26
|
-
assert.
|
|
27
|
-
assert.
|
|
28
|
-
assert.
|
|
29
|
-
assert.
|
|
22
|
+
assert.equal(markersE5.length, 1)
|
|
23
|
+
assert.equal(markersE5[0].square, "e5")
|
|
24
|
+
assert.equal(markersE5[0].type.slice, "markerSquare")
|
|
25
|
+
assert.equal(chessboard.getMarkers(undefined, MARKER_TYPE.square).length, 1)
|
|
26
|
+
assert.equal(chessboard.getMarkers("a4").length, 0)
|
|
27
|
+
assert.equal(chessboard.getMarkers(undefined, MARKER_TYPE.frame).length, 2)
|
|
28
|
+
assert.equal(chessboard.getMarkers("b6", MARKER_TYPE.frame).length, 1)
|
|
29
|
+
assert.equal(chessboard.getMarkers("h6", MARKER_TYPE.frame).length, 1)
|
|
30
30
|
chessboard.removeMarkers("h6")
|
|
31
|
-
assert.
|
|
31
|
+
assert.equal(chessboard.getMarkers("h6", MARKER_TYPE.frame).length, 0)
|
|
32
32
|
chessboard.addMarker("h6", MARKER_TYPE.frame)
|
|
33
|
-
assert.
|
|
33
|
+
assert.equal(chessboard.getMarkers("h6", MARKER_TYPE.frame).length, 1)
|
|
34
34
|
chessboard.removeMarkers("h6", MARKER_TYPE.square)
|
|
35
|
-
assert.
|
|
35
|
+
assert.equal(chessboard.getMarkers("h6", MARKER_TYPE.frame).length, 1)
|
|
36
36
|
chessboard.removeMarkers("h6", MARKER_TYPE.frame)
|
|
37
|
-
assert.
|
|
37
|
+
assert.equal(chessboard.getMarkers("h6", MARKER_TYPE.frame).length, 0)
|
|
38
38
|
chessboard.destroy()
|
|
39
39
|
})
|
|
40
40
|
|
|
@@ -10,14 +10,14 @@ import {PositionsAnimation} from "../src/cm-chessboard/view/PositionAnimationsQu
|
|
|
10
10
|
|
|
11
11
|
describe("TestPiecesAnimation", () => {
|
|
12
12
|
it("should calculate square distances", () => {
|
|
13
|
-
assert.
|
|
14
|
-
assert.
|
|
15
|
-
assert.
|
|
16
|
-
assert.
|
|
17
|
-
assert.
|
|
18
|
-
assert.
|
|
19
|
-
assert.
|
|
20
|
-
assert.
|
|
13
|
+
assert.equal(PositionsAnimation.squareDistance(0, 0), 0)
|
|
14
|
+
assert.equal(PositionsAnimation.squareDistance(0, 1), 1)
|
|
15
|
+
assert.equal(PositionsAnimation.squareDistance(0, 7), 7)
|
|
16
|
+
assert.equal(PositionsAnimation.squareDistance(0, 8), 1)
|
|
17
|
+
assert.equal(PositionsAnimation.squareDistance(10, 20), 2)
|
|
18
|
+
assert.equal(PositionsAnimation.squareDistance(0, 63), 7)
|
|
19
|
+
assert.equal(PositionsAnimation.squareDistance(8, 24), 2)
|
|
20
|
+
assert.equal(PositionsAnimation.squareDistance(14, 24), 6)
|
|
21
21
|
})
|
|
22
22
|
|
|
23
23
|
it("should seek changes", () => {
|
|
@@ -29,24 +29,24 @@ describe("TestPiecesAnimation", () => {
|
|
|
29
29
|
const newBoard1 = state2.position.squares
|
|
30
30
|
const changes = PositionsAnimation.seekChanges(previousBoard1, newBoard1)
|
|
31
31
|
|
|
32
|
-
assert.
|
|
33
|
-
assert.
|
|
34
|
-
assert.
|
|
35
|
-
assert.
|
|
32
|
+
assert.equal(changes[0].type,0 )
|
|
33
|
+
assert.equal(changes[0].piece, "wn")
|
|
34
|
+
assert.equal(changes[0].atIndex, 1)
|
|
35
|
+
assert.equal(changes[0].toIndex,3)
|
|
36
36
|
|
|
37
|
-
assert.
|
|
38
|
-
assert.
|
|
39
|
-
assert.
|
|
40
|
-
assert.
|
|
37
|
+
assert.equal(changes[2].type, 0)
|
|
38
|
+
assert.equal(changes[2].piece, "wn")
|
|
39
|
+
assert.equal(changes[2].atIndex, 6)
|
|
40
|
+
assert.equal(changes[2].toIndex, 18)
|
|
41
41
|
|
|
42
|
-
assert.
|
|
43
|
-
assert.
|
|
44
|
-
assert.
|
|
45
|
-
assert.
|
|
42
|
+
assert.equal(changes[4].type,0 )
|
|
43
|
+
assert.equal(changes[4].piece, "wp")
|
|
44
|
+
assert.equal(changes[4].atIndex, 8)
|
|
45
|
+
assert.equal(changes[4].toIndex, 24)
|
|
46
46
|
|
|
47
|
-
assert.
|
|
48
|
-
assert.
|
|
49
|
-
assert.
|
|
47
|
+
assert.equal(changes[13].type, 2)
|
|
48
|
+
assert.equal(changes[13].piece, "bq")
|
|
49
|
+
assert.equal(changes[13].atIndex, 59)
|
|
50
50
|
})
|
|
51
51
|
|
|
52
52
|
})
|
package/test/TestPosition.js
CHANGED
|
@@ -9,17 +9,17 @@ import {Position} from "../src/cm-chessboard/model/Position.js"
|
|
|
9
9
|
|
|
10
10
|
describe("TestPosition", () => {
|
|
11
11
|
it("should convert square to index", () => {
|
|
12
|
-
assert.
|
|
13
|
-
assert.
|
|
14
|
-
assert.
|
|
15
|
-
assert.
|
|
16
|
-
assert.
|
|
12
|
+
assert.equal(Position.squareToIndex("a1"), 0)
|
|
13
|
+
assert.equal(Position.squareToIndex("h1"), 7)
|
|
14
|
+
assert.equal(Position.squareToIndex("a8"), 56)
|
|
15
|
+
assert.equal(Position.squareToIndex("g5"), 38)
|
|
16
|
+
assert.equal(Position.squareToIndex("h8"), 63)
|
|
17
17
|
})
|
|
18
18
|
it("should convert index to square", () => {
|
|
19
|
-
assert.
|
|
20
|
-
assert.
|
|
21
|
-
assert.
|
|
22
|
-
assert.
|
|
23
|
-
assert.
|
|
19
|
+
assert.equal(Position.indexToSquare(0), "a1")
|
|
20
|
+
assert.equal(Position.indexToSquare(7), "h1")
|
|
21
|
+
assert.equal(Position.indexToSquare(56), "a8")
|
|
22
|
+
assert.equal(Position.indexToSquare(38), "g5")
|
|
23
|
+
assert.equal(Position.indexToSquare(63), "h8")
|
|
24
24
|
})
|
|
25
25
|
})
|