예제 #1
0
        public void DuplicateTest()
        {
            var Shapes = new List <Tetris.Controls.TileControl>();

            byte[,] arr = new byte[4, 4] {
                { 0, 0, 1, 0 }, { 0, 0, 1, 0 }, { 0, 0, 1, 0 }, { 0, 0, 1, 0 }
            };
            byte[,] arr2 = new byte[4, 4] {
                { 1, 1, 1, 1 }, { 1, 0, 0, 1 }, { 1, 0, 0, 1 }, { 1, 1, 1, 1 }
            };
            Shape s1      = new Shape(arr, System.Drawing.Color.FromArgb(0, 0, 0, 0), System.Drawing.Color.FromArgb(0, 0, 0, 0));
            Shape otherS1 = new Shape(arr, System.Drawing.Color.FromArgb(0, 0, 0, 0), System.Drawing.Color.FromArgb(0, 0, 0, 0));
            Shape other   = new Shape(arr2, System.Drawing.Color.FromArgb(0, 0, 0, 0), System.Drawing.Color.FromArgb(0, 0, 0, 0));
            var   tc1     = new Tetris.Controls.TileControl(s1);
            var   tc2     = new Tetris.Controls.TileControl(otherS1);
            var   tc3     = new Tetris.Controls.TileControl(other);

            Shapes.Add(tc1);
            Shapes.Add(tc2);
            Shapes.Add(tc3);
            ShapeValidator.MarkDuplicates(Shapes);
            Assert.IsFalse(Shapes[0].IsDuplicate);
            Assert.IsTrue(Shapes[1].IsDuplicate);
            Assert.IsFalse(Shapes[2].IsDuplicate);
        }
예제 #2
0
 public static double Calculate(Shape shape)
 {
     if (ShapeValidator.IsValid(shape))
     {
         return(shape.CalculateArea());
     }
     throw new ArgumentException();
 }
예제 #3
0
        public void TestTriangle()
        {
            var triangle = new Triangle(1, 2, 2);

            Assert.AreEqual(0.9682458365518543, AreaCalculator.Calculate(triangle));
            var falseTriangle = new Triangle(2, 1, -2);

            Assert.IsFalse(ShapeValidator.IsValid(falseTriangle));
        }
예제 #4
0
        public void TestCircle()
        {
            var circle = new Circle(5);

            Assert.AreEqual(78.53981633974483, AreaCalculator.Calculate(circle));
            var falseCircle = new Circle(-6);

            Assert.IsFalse(ShapeValidator.IsValid(falseCircle));
        }
예제 #5
0
        public void EqualityTest()
        {
            byte[,] arr = new byte[4, 4] {
                { 0, 0, 1, 0 }, { 0, 0, 1, 0 }, { 0, 0, 1, 0 }, { 0, 0, 1, 0 }
            };
            byte[,] arr2 = new byte[4, 4] {
                { 1, 1, 1, 1 }, { 1, 0, 0, 1 }, { 1, 0, 0, 1 }, { 1, 1, 1, 1 }
            };
            Shape s1      = new Shape(arr, System.Drawing.Color.FromArgb(0, 0, 0, 0), System.Drawing.Color.FromArgb(0, 0, 0, 0));
            Shape otherS1 = new Shape(arr, System.Drawing.Color.FromArgb(0, 0, 0, 0), System.Drawing.Color.FromArgb(0, 0, 0, 0));
            Shape other   = new Shape(arr2, System.Drawing.Color.FromArgb(0, 0, 0, 0), System.Drawing.Color.FromArgb(0, 0, 0, 0));

            Assert.IsTrue(ShapeValidator.AreEqual(s1, otherS1));
            Assert.IsFalse(ShapeValidator.AreEqual(s1, other));
        }
예제 #6
0
        public void ValidationTest()
        {
            byte[,] disconnected = new byte[4, 4] {
                { 0, 0, 1, 0 }, { 0, 1, 0, 0 }, { 0, 0, 1, 0 }, { 0, 0, 1, 0 }
            };
            byte[,] hole = new byte[4, 4] {
                { 1, 1, 1, 1 }, { 1, 0, 0, 1 }, { 1, 0, 0, 1 }, { 1, 1, 1, 1 }
            };
            byte[,] valid = new byte[4, 4] {
                { 0, 0, 1, 0 }, { 0, 0, 1, 0 }, { 0, 0, 1, 0 }, { 0, 0, 1, 0 }
            };
            Shape Disconnected = new Shape(disconnected, System.Drawing.Color.FromArgb(0, 0, 0, 0), System.Drawing.Color.FromArgb(0, 0, 0, 0));
            Shape Hole         = new Shape(hole, System.Drawing.Color.FromArgb(0, 0, 0, 0), System.Drawing.Color.FromArgb(0, 0, 0, 0));
            Shape Valid        = new Shape(valid, System.Drawing.Color.FromArgb(0, 0, 0, 0), System.Drawing.Color.FromArgb(0, 0, 0, 0));

            Assert.AreEqual(0, ShapeValidator.isTileValid(Valid));
            Assert.AreEqual(1, ShapeValidator.isTileValid(Hole));
            Assert.AreEqual(2, ShapeValidator.isTileValid(Disconnected));
        }
예제 #7
0
        public TileBrowser(/*ref*/ List <Shape> Shapes)
        {
            InitializeComponent();
            Random r = new Random();

            TileControls.Clear();
            foreach (Shape s in Shapes)
            {
                TileControl t = new TileControl(s);
                TileControls.Add(t);
            }

            ShapeValidator.MarkDuplicates(TileControls);
            SortTilesByValidity();

            foreach (TileControl tc in TileControls)
            {
                this.TilesPanel.Children.Add(tc);
            }
        }