Пример #1
0
        public void GetRowItemListGuardCase2Test()
        {
            RectMatrix <int> matrix = new RectMatrix <int>();

            matrix.EnsureSize(4, 2);
            matrix[0, 0] = 5;
            matrix[0, 1] = 7;
            matrix[1, 0] = 1;
            matrix[1, 1] = 9;
            matrix[2, 0] = -2;
            matrix[2, 1] = 3;
            matrix[3, 0] = 5;
            matrix[3, 1] = 2;
            var result = matrix.GetRowItemList(-1);
        }
Пример #2
0
        public void ForEachTest()
        {
            RectMatrix <string> matrix = new RectMatrix <string>();

            matrix.EnsureSize(2, 3);
            matrix[0, 0] = "F";
            matrix[0, 1] = "X";
            matrix[0, 2] = "7";
            matrix[1, 0] = "ABC";
            matrix[1, 1] = "N";
            matrix[1, 2] = "P";
            List <string> list = new List <string>();

            matrix.ForEach(x => list.Add(x));
            CollectionAssert.AreEqual(new string[] { "F", "X", "7", "ABC", "N", "P" }, list);
        }
Пример #3
0
        public void AttributesCountTest()
        {
            RectMatrix <int, double> matrix = new RectMatrix <int, double>();

            matrix.EnsureSize(2, 4);
            var rowAttributes    = matrix.RowAttributes;
            var columnAttributes = matrix.ColumnAttributes;

            Assert.IsNotNull(rowAttributes);
            Assert.IsNotNull(columnAttributes);
            Assert.IsNotNull(matrix.RowAttributes);
            Assert.IsNotNull(matrix.ColumnAttributes);
            Assert.AreEqual(2, matrix.RowAttributes.Length);
            Assert.AreEqual(4, matrix.ColumnAttributes.Length);
            matrix.EnsureSize(32, 64);
            Assert.AreEqual(32, matrix.RowAttributes.Length);
            Assert.AreEqual(64, matrix.ColumnAttributes.Length);
        }
Пример #4
0
        public void GetColumnItemListTest()
        {
            RectMatrix <int> matrix = new RectMatrix <int>();

            matrix.EnsureSize(2, 4);
            matrix[0, 0] = 11;
            matrix[0, 1] = 5;
            matrix[0, 2] = -7;
            matrix[0, 3] = 6;
            matrix[1, 0] = 3;
            matrix[1, 1] = 0;
            matrix[1, 2] = -7;
            matrix[1, 3] = 2;
            CollectionAssert.AreEqual(new int[] { 11, 3 }, matrix.GetColumnItemList(0));
            CollectionAssert.AreEqual(new int[] { 5, 0 }, matrix.GetColumnItemList(1));
            CollectionAssert.AreEqual(new int[] { -7, -7 }, matrix.GetColumnItemList(2));
            CollectionAssert.AreEqual(new int[] { 6, 2 }, matrix.GetColumnItemList(3));
        }
Пример #5
0
        public void GetRowItemListTest()
        {
            RectMatrix <int> matrix = new RectMatrix <int>();

            matrix.EnsureSize(4, 2);
            matrix[0, 0] = 5;
            matrix[0, 1] = 7;
            matrix[1, 0] = 1;
            matrix[1, 1] = 9;
            matrix[2, 0] = -2;
            matrix[2, 1] = 3;
            matrix[3, 0] = 5;
            matrix[3, 1] = 2;
            CollectionAssert.AreEqual(new int[] { 5, 7 }, matrix.GetRowItemList(0));
            CollectionAssert.AreEqual(new int[] { 1, 9 }, matrix.GetRowItemList(1));
            CollectionAssert.AreEqual(new int[] { -2, 3 }, matrix.GetRowItemList(2));
            CollectionAssert.AreEqual(new int[] { 5, 2 }, matrix.GetRowItemList(3));
        }
Пример #6
0
        public void AttributesValuesTest()
        {
            RectMatrix <int, string> matrix = new RectMatrix <int, string>();

            matrix.EnsureSize(2, 3);
            matrix[0, 0]               = 7;
            matrix[0, 1]               = 1;
            matrix[0, 2]               = 3;
            matrix[1, 0]               = -2;
            matrix[1, 1]               = 5;
            matrix[1, 2]               = 8;
            matrix.RowAttributes[1]    = "X";
            matrix.ColumnAttributes[0] = "A";
            matrix.ColumnAttributes[2] = "T";
            matrix.EnsureSize(64, 32);
            Assert.AreEqual("X", matrix.RowAttributes[1]);
            Assert.AreEqual("A", matrix.ColumnAttributes[0]);
            Assert.AreEqual("T", matrix.ColumnAttributes[2]);
        }
Пример #7
0
        public void CloneTest2()
        {
            RectMatrix <string> matrix = new RectMatrix <string>();

            matrix.EnsureSize(3, 2);
            matrix[0, 0] = "A";
            matrix[0, 1] = "3";
            matrix[1, 0] = "9";
            matrix[1, 1] = "0";
            matrix[2, 0] = "7";
            matrix[2, 1] = "P";
            var result = matrix.Clone();

            Assert.AreEqual("A", result[0, 0]);
            Assert.AreEqual("3", result[0, 1]);
            Assert.AreEqual("9", result[1, 0]);
            Assert.AreEqual("0", result[1, 1]);
            Assert.AreEqual("7", result[2, 0]);
            Assert.AreEqual("P", result[2, 1]);
        }
Пример #8
0
        public void CloneTest1()
        {
            RectMatrix <int> matrix = new RectMatrix <int>();

            matrix.EnsureSize(2, 3);
            matrix[0, 0] = 1;
            matrix[0, 1] = 2;
            matrix[0, 2] = 7;
            matrix[1, 0] = 9;
            matrix[1, 1] = 0;
            matrix[1, 2] = 5;
            var result = matrix.Clone();

            Assert.AreEqual(1, result[0, 0]);
            Assert.AreEqual(2, result[0, 1]);
            Assert.AreEqual(7, result[0, 2]);
            Assert.AreEqual(9, result[1, 0]);
            Assert.AreEqual(0, result[1, 1]);
            Assert.AreEqual(5, result[1, 2]);
        }
Пример #9
0
        public void TranslateWithAttributesTest1()
        {
            RectMatrix <string, int> matrix = new RectMatrix <string, int>();

            matrix.EnsureSize(4, 3);
            matrix[0, 0]               = "a";
            matrix[0, 1]               = "b";
            matrix[0, 2]               = "c";
            matrix[1, 0]               = "d";
            matrix[1, 1]               = "e";
            matrix[1, 2]               = "f";
            matrix[2, 0]               = "g";
            matrix[2, 1]               = "h";
            matrix[2, 2]               = "i";
            matrix[3, 0]               = "j";
            matrix[3, 1]               = "k";
            matrix[3, 2]               = "l";
            matrix.RowAttributes[0]    = 2;
            matrix.RowAttributes[1]    = 4;
            matrix.RowAttributes[2]    = 6;
            matrix.RowAttributes[3]    = 8;
            matrix.ColumnAttributes[0] = 12;
            matrix.ColumnAttributes[1] = 8;
            matrix.ColumnAttributes[2] = 4;
            matrix.Translate((row, column, rowAttribute, columnAttribute, x) => rowAttribute > 3 && rowAttribute < 7 && columnAttribute < 9, (row, column, x) => "-" + x + "-");
            Assert.AreEqual("a", matrix[0, 0]);
            Assert.AreEqual("b", matrix[0, 1]);
            Assert.AreEqual("c", matrix[0, 2]);
            Assert.AreEqual("d", matrix[1, 0]);
            Assert.AreEqual("-e-", matrix[1, 1]);
            Assert.AreEqual("-f-", matrix[1, 2]);
            Assert.AreEqual("g", matrix[2, 0]);
            Assert.AreEqual("-h-", matrix[2, 1]);
            Assert.AreEqual("-i-", matrix[2, 2]);
            Assert.AreEqual("j", matrix[3, 0]);
            Assert.AreEqual("k", matrix[3, 1]);
            Assert.AreEqual("l", matrix[3, 2]);
        }
Пример #10
0
        public void GetItemsTest2()
        {
            RectMatrix <int, int> matrix = new RectMatrix <int, int>();

            matrix.EnsureSize(3, 2);
            matrix[0, 0]               = 2;
            matrix[0, 1]               = 7;
            matrix[1, 0]               = 3;
            matrix[1, 1]               = 5;
            matrix[2, 0]               = 8;
            matrix[2, 1]               = 0;
            matrix.RowAttributes[0]    = 1;
            matrix.RowAttributes[1]    = 2;
            matrix.RowAttributes[2]    = 3;
            matrix.ColumnAttributes[0] = 4;
            matrix.ColumnAttributes[1] = 10;
            List <int> rowIndexList    = new List <int>();
            List <int> columnIndexList = new List <int>();
            var        result          = matrix.GetItems((row, column, rowAttribute, columnAttribute, x) => { rowIndexList.Add(row); columnIndexList.Add(column); return(columnAttribute > 5); }).ToList();

            CollectionAssert.AreEqual(new int[] { 0, 0, 1, 1, 2, 2 }, rowIndexList);
            CollectionAssert.AreEqual(new int[] { 0, 1, 0, 1, 0, 1 }, columnIndexList);
        }
Пример #11
0
        public void TranslateColumnAttributesTest()
        {
            RectMatrix <int, int> matrix = new RectMatrix <int, int>();

            matrix.EnsureSize(3, 2);
            matrix[0, 0]               = 1;
            matrix[0, 1]               = 1;
            matrix[1, 0]               = 1;
            matrix[1, 1]               = 1;
            matrix[2, 0]               = 1;
            matrix[2, 1]               = 1;
            matrix.RowAttributes[0]    = 1;
            matrix.RowAttributes[1]    = 2;
            matrix.RowAttributes[2]    = 3;
            matrix.ColumnAttributes[0] = 4;
            matrix.ColumnAttributes[1] = 10;
            matrix.TranslateColumnAttributes((column, columnAttribute) => columnAttribute > 5, x => x + 2);
            Assert.AreEqual(1, matrix.RowAttributes[0]);
            Assert.AreEqual(2, matrix.RowAttributes[1]);
            Assert.AreEqual(3, matrix.RowAttributes[2]);
            Assert.AreEqual(4, matrix.ColumnAttributes[0]);
            Assert.AreEqual(12, matrix.ColumnAttributes[1]);
        }
Пример #12
0
        public void TranslateColumnTest()
        {
            RectMatrix <string> matrix = new RectMatrix <string>(3, 2);

            matrix.EnsureSize(3, 2);
            matrix[0, 0] = "2";
            matrix[0, 1] = "3";
            matrix[1, 0] = "11";
            matrix[1, 1] = "9";
            matrix[2, 0] = "2";
            matrix[2, 1] = "A";
            List <int> rowIndexList    = new List <int>();
            List <int> columnIndexList = new List <int>();

            matrix.TranslateColumn(0, (row, column, x) => { rowIndexList.Add(row); columnIndexList.Add(column); return(x + "Y"); });
            Assert.AreEqual("2Y", matrix[0, 0]);
            Assert.AreEqual("3", matrix[0, 1]);
            Assert.AreEqual("11Y", matrix[1, 0]);
            Assert.AreEqual("9", matrix[1, 1]);
            Assert.AreEqual("2Y", matrix[2, 0]);
            Assert.AreEqual("A", matrix[2, 1]);
            CollectionAssert.AreEqual(new int[] { 0, 1, 2 }, rowIndexList);
            CollectionAssert.AreEqual(new int[] { 0, 0, 0 }, columnIndexList);
        }
Пример #13
0
        public void TranslateRowTest()
        {
            RectMatrix <int> matrix = new RectMatrix <int>(2, 3);

            matrix.EnsureSize(2, 3);
            matrix[0, 0] = 7;
            matrix[0, 1] = 2;
            matrix[0, 2] = 3;
            matrix[1, 0] = 2;
            matrix[1, 1] = 5;
            matrix[1, 2] = 6;
            List <int> rowIndexList    = new List <int>();
            List <int> columnIndexList = new List <int>();

            matrix.TranslateRow(1, (row, column, x) => { rowIndexList.Add(row); columnIndexList.Add(column); return(x + 2); });
            Assert.AreEqual(7, matrix[0, 0]);
            Assert.AreEqual(2, matrix[0, 1]);
            Assert.AreEqual(3, matrix[0, 2]);
            Assert.AreEqual(4, matrix[1, 0]);
            Assert.AreEqual(7, matrix[1, 1]);
            Assert.AreEqual(8, matrix[1, 2]);
            CollectionAssert.AreEqual(new int[] { 1, 1, 1 }, rowIndexList);
            CollectionAssert.AreEqual(new int[] { 0, 1, 2 }, columnIndexList);
        }
Пример #14
0
        public void ForEachGuardTest()
        {
            RectMatrix <string> matrix = new RectMatrix <string>();

            matrix.ForEach(null);
        }
Пример #15
0
        public void EnsureSizeGuardCase4Test()
        {
            RectMatrix <int> matrix = new RectMatrix <int>(256, 512);

            matrix.EnsureSize(1, -1);
        }