mirror of
https://github.com/bitburner-official/bitburner-src.git
synced 2024-11-23 16:13:49 +01:00
90 lines
2.2 KiB
Plaintext
90 lines
2.2 KiB
Plaintext
//Tests for multidimensional arrays
|
|
import {test} from "tb_basic.script";
|
|
|
|
runSuccess = (args.length === 1 && args[0] === "OK");
|
|
test("run", runSuccess);
|
|
|
|
arr = [];
|
|
arr[0] = [];
|
|
arr[1] = [];
|
|
arr.push([]);
|
|
|
|
test("multiarr1", arr.toString() === ",,");
|
|
test("multiarr2", arr.length === 3);
|
|
arr[0].push(0);
|
|
arr[0].push(0);
|
|
arr[0].push(0);
|
|
test("multiarr3", arr[0].length === 3);
|
|
test("multiarr4", arr[0].toString() === "0,0,0");
|
|
arr[1] = [0, 0, 0];
|
|
test("multiarr5", arr.length === 3);
|
|
test("multiarr6", arr[1].length === 3);
|
|
test("multiarr7", arr[1].toString() === "0,0,0");
|
|
arr.pop();
|
|
arr.push([0,0,0]);
|
|
test("multiarr8", arr.length === 3);
|
|
test("multiarr9", arr[2].length === 3);
|
|
test("multiarr10", "0,0,0,0,0,0,0,0,0" === arr.toString());
|
|
for (r = 0; r < arr.length; ++r) {
|
|
for (c = 0; c < arr[r].length; ++c) {
|
|
arr[r][c] = r * 3 + c + 1;
|
|
}
|
|
}
|
|
test("multiarr11", "1,2,3,4,5,6,7,8,9" === arr.toString());
|
|
|
|
arr = [[0,0,0,0], [0,0,0,0], [0,0,0,0], [0,0,0,0]];
|
|
test("multiarr12", 4 === arr.length);
|
|
for (i = 0; i < arr.length; ++i) {
|
|
test("multiarr" + (13 + i), arr[i].length === 4);
|
|
}
|
|
|
|
for (r = 0; r < arr.length; ++r) {
|
|
for (c = 0; c < arr[r].length; ++c) {
|
|
arr[r][c] = r * 10 + c + 1;
|
|
}
|
|
}
|
|
|
|
test("multiarr17", arr.toString() === "1,2,3,4,11,12,13,14,21,22,23,24,31,32,33,34");
|
|
|
|
|
|
//3D array
|
|
arr = [[], [], [], []];
|
|
arr[0].push([0, 0, 0]);
|
|
arr[0].push([0, 0, 0]);
|
|
arr[0].push([0, 0, 0]);
|
|
|
|
arr[1].push([0, 0, 0]);
|
|
arr[1].push([0, 0, 0]);
|
|
arr[1].push([0, 0, 0]);
|
|
|
|
arr[2].push([0, 0, 0]);
|
|
arr[2].push([0, 0, 0]);
|
|
arr[2].push([0, 0, 0]);
|
|
|
|
arr[3].push([0, 0, 0]);
|
|
arr[3].push([0, 0, 0]);
|
|
arr[3].push([0, 0, 0]);
|
|
|
|
i = 0;
|
|
|
|
for (r = 0; r < arr.length; ++r) {
|
|
for (c = 0; c < arr[r].length; ++c) {
|
|
for (d = 0; d < arr[r][c].length; ++d) {
|
|
arr[r][c][d] = i;
|
|
++i;
|
|
}
|
|
}
|
|
}
|
|
|
|
test("multiarr18", "0,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" === arr.toString());
|
|
ref = 0;
|
|
for (r = 0; r < arr.length; ++r) {
|
|
for (c = 0; c < arr[r].length; ++c) {
|
|
for (d = 0; d < arr[r][c].length; ++d) {
|
|
test("multiarr" + (19 + ref), arr[r][c][d] === ref);
|
|
++ref;
|
|
}
|
|
}
|
|
}
|
|
|
|
write("tb_results.txt", ",tb_multiarray"); |