Пример #1
0
    // -------------- Private functions --------------

    private static List <Blueprint> InitDesignNotebook()
    {
        List <Blueprint> notebook = new List <Blueprint>();

        // Single block
        Blueprint starting_block = new Blueprint(1, 1, 1);

        starting_block.AddBlock(new Discrete3DCoord(0, 0, 0), 1);
        notebook.Add(starting_block);

        // 2x1 brick
        Blueprint brick2 = new Blueprint(2, 1, 1);

        brick2.AddBlock(new Discrete3DCoord(0, 0, 0), 1);
        brick2.AddBlock(new Discrete3DCoord(1, 0, 0), 1);
        notebook.Add(brick2);

        // 3x1 brick
        Blueprint brick3 = new Blueprint(3, 1, 1);

        brick3.AddBlock(new Discrete3DCoord(0, 0, 0), 1);
        brick3.AddBlock(new Discrete3DCoord(1, 0, 0), 1);
        brick3.AddBlock(new Discrete3DCoord(2, 0, 0), 1);
        notebook.Add(brick3);

        return(notebook);
    }
Пример #2
0
    public void TestRotate()
    {
        Blueprint x_line = new Blueprint(3, 3, 3);

        x_line.AddBlock(new Discrete3DCoord(0, 0, 0), 1);
        x_line.AddBlock(new Discrete3DCoord(1, 0, 0), 1);
        x_line.AddBlock(new Discrete3DCoord(2, 0, 0), 1);

        Blueprint y_line = x_line.Rotate(RotationAxis.Z_AXIS, 1);
        Blueprint z_line = x_line.Rotate(RotationAxis.Y_AXIS, 1);

        Assert.AreEqual(1, y_line.GetBlocks()[2, 0, 0]);
        Assert.AreEqual(1, y_line.GetBlocks()[2, 1, 0]);
        Assert.AreEqual(1, y_line.GetBlocks()[2, 2, 0]);

        Assert.AreEqual(1, z_line.GetBlocks()[2, 0, 0]);
        Assert.AreEqual(1, z_line.GetBlocks()[2, 0, 1]);
        Assert.AreEqual(1, z_line.GetBlocks()[2, 0, 2]);

        CollectionAssert.AreEqual(
            x_line.GetBlocks(),
            y_line.Rotate(RotationAxis.Z_AXIS, 3).GetBlocks());

        CollectionAssert.AreEqual(
            x_line.GetBlocks(),
            z_line.Rotate(RotationAxis.Y_AXIS, -1).GetBlocks());
    }
Пример #3
0
    public void TestAddBlock()
    {
        Blueprint a = new Blueprint(3, 3, 3);

        a.AddBlock(new Discrete3DCoord(0, 0, 0), 1);
        Assert.AreEqual(1, a.GetBlocks()[0, 0, 0]);
        a.AddBlock(new Discrete3DCoord(1, 2, 0), 3);
        Assert.AreEqual(1, a.GetBlocks()[1, 2, 0], 3);
    }
Пример #4
0
    public void TestApplyDesign()
    {
        Blueprint composite = new Blueprint(4, 5, 4);

        Blueprint long_block = new Blueprint(4, 1, 1);

        long_block.AddBlock(new Discrete3DCoord(0, 0, 0), 1);
        long_block.AddBlock(new Discrete3DCoord(1, 0, 0), 1);
        long_block.AddBlock(new Discrete3DCoord(2, 0, 0), 1);
        long_block.AddBlock(new Discrete3DCoord(3, 0, 0), 1);

        Blueprint tall_block = new Blueprint(2, 3, 1);

        tall_block.AddBlock(new Discrete3DCoord(0, 0, 0), 1);
        tall_block.AddBlock(new Discrete3DCoord(0, 1, 0), 1);
        tall_block.AddBlock(new Discrete3DCoord(0, 2, 0), 1);

        Blueprint really_really_long_block = new Blueprint(10, 1, 1);

        really_really_long_block.AddBlock(new Discrete3DCoord(0, 0, 0), 1);
        really_really_long_block.AddBlock(new Discrete3DCoord(1, 0, 0), 1);
        really_really_long_block.AddBlock(new Discrete3DCoord(2, 0, 0), 1);
        really_really_long_block.AddBlock(new Discrete3DCoord(3, 0, 0), 1);
        really_really_long_block.AddBlock(new Discrete3DCoord(4, 0, 0), 1);
        really_really_long_block.AddBlock(new Discrete3DCoord(5, 0, 0), 1);
        really_really_long_block.AddBlock(new Discrete3DCoord(6, 0, 0), 1);
        really_really_long_block.AddBlock(new Discrete3DCoord(7, 0, 0), 1);
        really_really_long_block.AddBlock(new Discrete3DCoord(8, 0, 0), 1);
        really_really_long_block.AddBlock(new Discrete3DCoord(9, 0, 0), 1);

        composite.ApplyDesign(long_block, 0, 0, 0);

        List <int> unique_ids = new List <int>();

        unique_ids.Add(composite.GetBlocks()[0, 0, 0]);
        CollectionAssert.AllItemsAreUnique(unique_ids);
        CollectionAssert.DoesNotContain(unique_ids, 0);

        composite.ApplyDesign(tall_block, 0, 1, 0);
        unique_ids.Add(composite.GetBlocks()[0, 1, 0]);
        CollectionAssert.AllItemsAreUnique(unique_ids);
        CollectionAssert.DoesNotContain(unique_ids, 0);

        composite.ApplyDesign(tall_block, 3, 1, 0);
        unique_ids.Add(composite.GetBlocks()[3, 1, 0]);
        CollectionAssert.AllItemsAreUnique(unique_ids);
        CollectionAssert.DoesNotContain(unique_ids, 0);

        composite.ApplyDesign(really_really_long_block, 0, 3, 0);
        unique_ids.Add(composite.GetBlocks()[0, 3, 0]);
        CollectionAssert.AllItemsAreUnique(unique_ids);
        CollectionAssert.DoesNotContain(unique_ids, 0);

        Assert.AreEqual(composite.GetBlocks()[0, 3, 0], composite.GetBlocks()[3, 3, 0]);
    }
Пример #5
0
    public void TestCopyInto()
    {
        Blueprint a = new Blueprint(3, 3, 3);

        a.AddBlock(new Discrete3DCoord(0, 0, 0), 1);
        a.AddBlock(new Discrete3DCoord(0, 0, 1), 1);
        a.AddBlock(new Discrete3DCoord(0, 0, 2), 1);

        Blueprint mismatched_size = new Blueprint(2, 3, 3);

        Assert.Throws <System.ArgumentException>(() => a.CopyInto(mismatched_size));

        Blueprint copy = new Blueprint(3, 3, 3);

        a.CopyInto(copy);
        CollectionAssert.AreEqual(a.GetBlocks(), copy.GetBlocks());
    }
Пример #6
0
    public void TestDeleteID()
    {
        Blueprint empty = new Blueprint(4, 4, 4);
        Blueprint arch  = new Blueprint(4, 4, 4);

        CollectionAssert.AreEqual(empty.GetBlocks(), arch.GetBlocks());

        arch.AddBlock(new Discrete3DCoord(0, 0, 0), 1);
        arch.AddBlock(new Discrete3DCoord(0, 1, 0), 1);
        arch.AddBlock(new Discrete3DCoord(0, 2, 0), 1);

        arch.AddBlock(new Discrete3DCoord(2, 0, 0), 1);
        arch.AddBlock(new Discrete3DCoord(2, 1, 0), 1);
        arch.AddBlock(new Discrete3DCoord(2, 2, 0), 1);

        arch.AddBlock(new Discrete3DCoord(0, 3, 0), 1);
        arch.AddBlock(new Discrete3DCoord(1, 3, 0), 1);
        arch.AddBlock(new Discrete3DCoord(2, 3, 0), 1);

        CollectionAssert.AreNotEqual(empty.GetBlocks(), arch.GetBlocks());

        arch.DeleteID(1);
        CollectionAssert.AreEqual(empty.GetBlocks(), arch.GetBlocks());
    }
Пример #7
0
    public void TestIsStable()
    {
        Blueprint stable = new Blueprint(3, 3, 3);

        Assert.IsTrue(stable.IsStable());
        stable.AddBlock(new Discrete3DCoord(0, 0, 0), 1);
        Assert.IsTrue(stable.IsStable());
        stable.AddBlock(new Discrete3DCoord(0, 1, 0), 1);
        stable.AddBlock(new Discrete3DCoord(2, 0, 0), 2);
        stable.AddBlock(new Discrete3DCoord(2, 1, 0), 2);
        Assert.IsTrue(stable.IsStable());
        stable.AddBlock(new Discrete3DCoord(0, 2, 0), 3);
        stable.AddBlock(new Discrete3DCoord(1, 2, 0), 3);
        stable.AddBlock(new Discrete3DCoord(2, 2, 0), 3);
        Assert.IsTrue(stable.IsStable());
        Blueprint unstable = new Blueprint(3, 3, 3);

        unstable.AddBlock(new Discrete3DCoord(1, 1, 1), 1);
        Assert.IsFalse(unstable.IsStable());
    }