1
- import { createFlatMatrix , createMatrix } from "./matrix" ;
1
+ import {
2
+ createFlatMatrix ,
3
+ createMatrix ,
4
+ getTileCoordinates , getTileFromCoordinates ,
5
+ getTileRowAndColumn ,
6
+ } from "./matrix" ;
2
7
3
8
describe ( 'createMatrix' , ( ) => {
4
9
test ( 'createMatrix(1, 1)' , ( ) => {
5
- const m = createMatrix ( 1 , 1 ) ;
10
+ const m = createMatrix ( { width : 1 , height : 1 , tileSize : 16 } ) ;
6
11
expect ( m ) . toEqual ( [ [ 0 ] ] ) ;
7
12
} ) ;
8
13
9
14
test ( 'createMatrix(1, 2)' , ( ) => {
10
- const m = createMatrix ( 1 , 2 ) ;
15
+ const m = createMatrix ( { width : 1 , height : 2 , tileSize : 16 } ) ;
11
16
expect ( m ) . toEqual ( [ [ 0 ] , [ 0 ] ] ) ;
12
17
} ) ;
13
18
14
19
test ( 'createMatrix(3, 3)' , ( ) => {
15
- const m = createMatrix ( 3 , 3 ) ;
20
+ const m = createMatrix ( { width : 3 , height : 3 , tileSize : 16 } ) ;
16
21
expect ( m ) . toEqual ( [ [ 0 , 0 , 0 ] , [ 0 , 0 , 0 ] , [ 0 , 0 , 0 ] ] ) ;
17
22
} ) ;
18
23
19
24
test ( 'createMatrix(3, 4)' , ( ) => {
20
- const m = createMatrix ( 3 , 4 ) ;
25
+ const m = createMatrix ( { width : 3 , height : 4 , tileSize : 16 } ) ;
21
26
expect ( m ) . toEqual ( [ [ 0 , 0 , 0 ] , [ 0 , 0 , 0 ] , [ 0 , 0 , 0 ] , [ 0 , 0 , 0 ] ] ) ;
22
27
} ) ;
23
28
} ) ;
24
29
25
30
describe ( 'createFlatMatrix' , ( ) => {
26
31
test ( 'createFlatMatrix(1, 1)' , ( ) => {
27
- const m = createFlatMatrix ( 1 , 1 ) ;
32
+ const m = createFlatMatrix ( { width : 1 , height : 1 , tileSize : 16 } ) ;
28
33
expect ( m ) . toEqual ( [ 0 ] ) ;
29
34
} ) ;
30
35
31
36
test ( 'createFlatMatrix(1, 2)' , ( ) => {
32
- const m = createFlatMatrix ( 1 , 2 ) ;
37
+ const m = createFlatMatrix ( { width : 1 , height : 2 , tileSize : 16 } ) ;
33
38
expect ( m ) . toEqual ( [ 0 , 0 ] ) ;
34
39
} ) ;
35
40
36
41
test ( 'createFlatMatrix(3, 3)' , ( ) => {
37
- const m = createFlatMatrix ( 3 , 3 ) ;
42
+ const m = createFlatMatrix ( { width : 3 , height : 3 , tileSize : 16 } ) ;
38
43
expect ( m ) . toEqual ( [ 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 ] ) ;
39
44
} )
45
+ } ) ;
46
+
47
+ describe ( 'tile' , ( ) => {
48
+
49
+ test ( 'getTileRowAndColumn' , ( ) => {
50
+ const matrixConfig = { width : 40 , height : 30 , tileSize : 16 } ;
51
+
52
+ expect ( getTileRowAndColumn ( 0 , matrixConfig ) ) . toEqual ( { row : 0 , column : 0 } ) ; // first tile.
53
+ expect ( getTileRowAndColumn ( 129 , matrixConfig ) ) . toEqual ( { row : 3 , column : 9 } ) ;
54
+ expect ( getTileRowAndColumn ( 1199 , matrixConfig ) ) . toEqual ( { row : 29 , column : 39 } ) ; // last tile.
55
+ } ) ;
56
+
57
+ test ( 'getTileCoordinates' , ( ) => {
58
+ const matrixConfig = { width : 40 , height : 30 , tileSize : 16 } ;
59
+
60
+ expect ( getTileCoordinates ( 0 , matrixConfig ) ) . toEqual ( { x : 0 , y : 0 } ) ;
61
+ expect ( getTileCoordinates ( 129 , matrixConfig ) ) . toEqual ( { x : 144 , y : 48 } ) ;
62
+ expect ( getTileCoordinates ( 1199 , matrixConfig ) ) . toEqual ( { x : 624 , y : 464 } ) ;
63
+ } ) ;
64
+
65
+ test ( 'getTileFromCoordinates' , ( ) => {
66
+ const matrixConfig = { width : 40 , height : 30 , tileSize : 16 } ;
67
+
68
+ expect ( getTileFromCoordinates ( 0 , 0 , matrixConfig ) ) . toEqual ( 0 ) ;
69
+ expect ( getTileFromCoordinates ( 144 , 48 , matrixConfig ) ) . toEqual ( 129 ) ;
70
+ expect ( getTileFromCoordinates ( 624 , 464 , matrixConfig ) ) . toEqual ( 1199 ) ;
71
+ } ) ;
72
+
40
73
} ) ;
0 commit comments