Beispiel #1
0
        public void Create1()
        {
            var tests = new[]
            {
                new { Type = MatrixElementTypes.RgbPixel, ExpectResult = true },
                new { Type = MatrixElementTypes.RgbAlphaPixel, ExpectResult = true },
                new { Type = MatrixElementTypes.HsiPixel, ExpectResult = true },
                new { Type = MatrixElementTypes.UInt8, ExpectResult = true },
                new { Type = MatrixElementTypes.UInt16, ExpectResult = true },
                new { Type = MatrixElementTypes.UInt32, ExpectResult = true },
                new { Type = MatrixElementTypes.Int8, ExpectResult = true },
                new { Type = MatrixElementTypes.Int16, ExpectResult = true },
                new { Type = MatrixElementTypes.Int32, ExpectResult = true },
                new { Type = MatrixElementTypes.Float, ExpectResult = true },
                new { Type = MatrixElementTypes.Double, ExpectResult = true }
            };

            var rules = new[]
            {
                new { Column = 0, Row = 0, ExpectResult = true },
                new { Column = 0, Row = -1, ExpectResult = false },
                new { Column = -1, Row = 0, ExpectResult = false },
                new { Column = -1, Row = -1, ExpectResult = false },
                new { Column = 1, Row = 0, ExpectResult = true },
                new { Column = 0, Row = 1, ExpectResult = true },
                new { Column = 1, Row = 1, ExpectResult = true },
                new { Column = 10, Row = 0, ExpectResult = true },
                new { Column = 0, Row = 10, ExpectResult = true }
            };

            foreach (var r in rules)
            {
                foreach (var test in tests)
                {
                    TwoDimentionObjectBase matrix = null;

                    try
                    {
                        if (r.ExpectResult)
                        {
                            matrix = CreateMatrix(test.Type, r.Row, r.Column);
                        }
                        else
                        {
                            try
                            {
                                matrix = CreateMatrix(test.Type, r.Row, r.Column);
                                Assert.Fail($"{matrix.GetType().Name} should throw excption for Type: {test.Type}, Row: {r.Row}, Column: {r.Column}.");
                            }
                            catch
                            {
                                Console.WriteLine("OK");
                            }
                        }
                    }
                    catch (Exception e)
                    {
                        Console.WriteLine(e.StackTrace);
                        Console.WriteLine($"Failed to create for Type: {test.Type}, Row: {r.Row}, Column: {r.Column}.");
                        throw;
                    }
                    finally
                    {
                        if (matrix != null)
                        {
                            this.DisposeAndCheckDisposedState(matrix);
                        }
                    }
                }
            }
        }
Beispiel #2
0
        public void ToStringTest()
        {
            var array = new[]
            {
                1, 2, 6,
                5, 3, 6,
                4, 5, 0
            };

            const string answer  = "1 2 6 \n5 3 6 \n4 5 0 \n";
            const string answer1 = "\u0001 \u0002 \u0006 \n\u0005 \u0003 \u0006 \n\u0004 \u0005 ";

            var tests = new[]
            {
                new { Type = MatrixElementTypes.RgbPixel, ExpectResult = false, Answer = "" },
                new { Type = MatrixElementTypes.RgbAlphaPixel, ExpectResult = false, Answer = "" },
                new { Type = MatrixElementTypes.HsiPixel, ExpectResult = false, Answer = "" },
                new { Type = MatrixElementTypes.UInt8, ExpectResult = true, Answer = answer1 },
                new { Type = MatrixElementTypes.UInt16, ExpectResult = true, Answer = answer },
                new { Type = MatrixElementTypes.UInt32, ExpectResult = true, Answer = answer },
                new { Type = MatrixElementTypes.Int8, ExpectResult = true, Answer = answer1 },
                new { Type = MatrixElementTypes.Int16, ExpectResult = true, Answer = answer },
                new { Type = MatrixElementTypes.Int32, ExpectResult = true, Answer = answer },
                new { Type = MatrixElementTypes.Float, ExpectResult = true, Answer = answer },
                new { Type = MatrixElementTypes.Double, ExpectResult = true, Answer = answer }
            };

            foreach (var test in tests)
            {
                TwoDimentionObjectBase matrix = null;

                try
                {
                    if (test.ExpectResult)
                    {
                        matrix = CreateMatrix(test.Type, 3, 3);
                        this.Assign(matrix, array);
                        var str = matrix.ToString();
                        Assert.AreEqual(test.Answer, str);
                    }
                    else
                    {
                        try
                        {
                            matrix = CreateMatrix(test.Type, 3, 3);

                            var str = matrix.ToString();
                            Assert.Fail($"{matrix.GetType().Name} should throw excption for Type: {test.Type}.");
                        }
                        catch
                        {
                            Console.WriteLine("OK");
                        }
                    }
                }
                catch (Exception e)
                {
                    Console.WriteLine(e.StackTrace);
                    Console.WriteLine($"Failed to create for Type: {test.Type}.");
                    throw;
                }
                finally
                {
                    if (matrix != null)
                    {
                        this.DisposeAndCheckDisposedState(matrix);
                    }
                }
            }
        }