-
Notifications
You must be signed in to change notification settings - Fork 1
/
board.test.js
115 lines (94 loc) · 2.38 KB
/
board.test.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
'use strict';
// @ts-check
const {
ZONES,
CARD_TYPES,
TAGS,
PLAYERCLASS
} = require('./data/constants.js');
const Board = require('./classes/board.js');
let arr0a = [],
arr0b = [],
p0a = {name: 'Alice'},
p0b = {name: 'Bob'};
let b0 = new Board(
arr0a,
arr0b,
p0a,
p0b
);
arr0a.push({
id: 'test 1',
health: 3,
zone: ZONES.play,
type: CARD_TYPES.minion,
owner: p0a
});
arr0b.push({
id: 'test 2',
health: 3,
zone: ZONES.hand,
type: CARD_TYPES.minion,
owner: p0b
});
let test0 = b0.$(p0a, 'spell');
//if (test0.length !== 0) throw 'TEST 0: wrong length';
let test1 = b0.$(p0a, 'own minion');
if (test1.length !== 1) throw 'TEST 1: wrong length';
if (test1[0].id !== 'test 1') throw 'TEST 1: wrong id' + test1.id;
let test2 = b0.$(p0b, 'own minion');
if (test2.length !== 0) throw 'TEST 2: wrong length';
let test3 = b0.$(p0b, 'minion @hand');
//if (test3.length !== 1) throw 'TEST 3: wrong length' + test3.length;
//if (test3[0].id !== 'test 2') throw 'TEST 3: wrong id';
//======================
let arr1a = [],
arr1b = [],
p1a = {name: 'Alice'},
p1b = {name: 'Bob'};
let b1 = new Board(
arr1a,
arr1b,
p1a,
p1b
);
for (let i = 0; i < 99; i++) {
let dice = Math.floor(Math.random()*10);
arr1a.push({
zone: dice < 2 ? ZONES.hand : ZONES.deck,
owner: p1a,
type: dice < 7 ? CARD_TYPES.minion : CARD_TYPES.spell,
name: 'Test',
tags: [TAGS.taunt]
});
arr1b.push({
zone: dice < 3 ? ZONES.play : ZONES.grave,
owner: p1b,
type: [ CARD_TYPES.minion, CARD_TYPES.spell, CARD_TYPES.weapon][dice % 3],
name: 'Test',
tags: [TAGS.taunt]
});
}
let $1 = b1.$.bind(b1);
let query = [
'own minion',
'character',
'enemy minion',
'minion .race=beast',
'enemy minion .health>0',
'enemy character .health>0',
'#taunt',
'spell @deck'
];
let side_effect = [];
let _timeStart = Date.now();
let _N_RUNS = 100*1000;
for (let j = 0; j < _N_RUNS; j++) {
//let result = $1(p1a, query[j % query.length]);
let result = b1.$(p1a, query[j % query.length]);
side_effect.push([result.slice(-1), result.length]);
}
let duration_of_quick_run = ((Date.now()- _timeStart)/1000).toFixed(3);
console.log(side_effect[999]);
console.log(`completed ${_N_RUNS} calls in ${duration_of_quick_run}s`);
console.log(Board._profile());