當前位置: 首頁>>代碼示例>>TypeScript>>正文


TypeScript Array2D.get方法代碼示例

本文整理匯總了TypeScript中Imports/Core/Arrays.Array2D.get方法的典型用法代碼示例。如果您正苦於以下問題:TypeScript Array2D.get方法的具體用法?TypeScript Array2D.get怎麽用?TypeScript Array2D.get使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在Imports/Core/Arrays.Array2D的用法示例。


在下文中一共展示了Array2D.get方法的4個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的TypeScript代碼示例。

示例1: Array2D

QUnit.test(name("Overlapping birth"), assert => {
    const t = GameOfLifeTransformer.create([], [0]);
    const w = new Array2D(3, 4, false);
    const nextWorld = new Array2D(3, 4, false);

    t.transform(w, nextWorld);

    assert.strictEqual(nextWorld.get(1, 2), true);
    assert.strictEqual(nextWorld.get(1, 3), true);
});
開發者ID:cfuehrmann,項目名稱:GameOfLife,代碼行數:10,代碼來源:GameOfLifeTransformer_test.ts

示例2: checkInt

 fillRect: (x, y, w, h) => {
     checkInt("x", x);
     checkInt("y", y);
     assert.ok(x >= 0);
     assert.ok(y >= 0);
     assert.strictEqual(w, pointSize);
     assert.strictEqual(h, pointSize);
     const row = Math.floor(y / pointSize);
     const column = Math.floor(x / pointSize);
     assert.ok(world.get(row, column));
     world.set(row, column, false);
 }
開發者ID:cfuehrmann,項目名稱:GameOfLife,代碼行數:12,代碼來源:RectRenderer_test.ts

示例3: render

    render(world: Array2D<T>) {
        checkDefinedAndNotNull("world", world);

        this.context.clearRect(0, 0,
            world.width * this.pointSize, world.height * this.pointSize);

        for (let row = 0; row < world.height; row++) {
            for (let column = 0; column < world.width; column++) {
                if (world.get(row, column)) {
                    this.context.fillRect(column * this.pointSize, row * this.pointSize,
                        this.pointSize, this.pointSize);
                }
            }
        }
    }
開發者ID:cfuehrmann,項目名稱:GameOfLife,代碼行數:15,代碼來源:RectRenderer.ts

示例4: TestContext

QUnit.test(name("ContextCallSequence"), assert => {
    // PREPARE

    const context = new TestContext();
    const pointSize = 4;
    const renderer = RectRenderer.create(context, pointSize);
    const width = 5;
    const height = 3;
    const world = new Array2D(height, width, false);

    world.set(0, 0, true);
    world.set(0, 1, false);
    world.set(0, 2, true);
    world.set(0, 3, false);
    world.set(0, 4, true);

    world.set(1, 0, false);
    world.set(1, 1, true);
    world.set(1, 2, false);
    world.set(1, 3, true);
    world.set(1, 4, false);

    world.set(2, 0, true);
    world.set(2, 1, false);
    world.set(2, 2, true);
    world.set(2, 3, false);
    world.set(2, 4, true);

    // ACT

    renderer.render(world);

    // ASSERT 

    // The first call must be clearRect with the proper parameters:
    assert.ok(context.calls[0].match({
        clearRect: (x, y, w, h) => x === 0 && y === 0 &&
            w === width * pointSize && h === height * pointSize,
        fillRect: () => false
    }));

    // The subsequent calls must be fillRects with proper parameters.
    // In particular, each fillRect call must correspond to coordinates
    // where "world" is true, and no such coordinates must occur twice:
    for (let i = 1; i < context.calls.length; i++) {
        context.calls[i].match({
            clearRect: () => assert.ok(false),
            fillRect: (x, y, w, h) => {
                checkInt("x", x);
                checkInt("y", y);
                assert.ok(x >= 0);
                assert.ok(y >= 0);
                assert.strictEqual(w, pointSize);
                assert.strictEqual(h, pointSize);
                const row = Math.floor(y / pointSize);
                const column = Math.floor(x / pointSize);
                assert.ok(world.get(row, column));
                world.set(row, column, false);
            }
        });
    }

    // The calls to fillRect must exhaust all coordinates where world is true:
    for (let row = 0; row < height; row++) {
        for (let column = 0; column < width; column++) {
            assert.strictEqual(world.get(row, column), false);
        }
    }
});
開發者ID:cfuehrmann,項目名稱:GameOfLife,代碼行數:69,代碼來源:RectRenderer_test.ts


注:本文中的Imports/Core/Arrays.Array2D.get方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。