Ejemplo n.º 1
0
        public void Indexer2Test()
        {
            // 3列5行 {0,0}, {1,0}, {2,0}, {0,1}, {1,1}, {2,1}, ... {0,4},{1,4,1},{2,4}  
            const int maxcols = 3, maxrows = 5;
            var seq = Enumerable.Range(0, maxcols).SelectMany(
                 col => Enumerable.Range(0, maxrows), (col, row) => new { col, row }).ToList();
            // 3列5行の2次元配列を作り、初期値(col*row)を入れる
            var arr = new int[maxcols,maxrows];
            seq.ForEach(v => arr[v.col, v.row] = (v.col+1) * (v.row+1));

            var indexer2 = new Indexer2<int>(()=> arr.GetLength(0), ()=> arr.GetLength(1),
                (c,r) => arr[c,r], (c,r,v) => arr[c,r] = v );

            // サイズ
            indexer2.Width.Is(maxcols);
            indexer2.Height.Is(maxrows);
            indexer2.Count.Is(maxcols * maxrows);

            // 列挙子による、元の配列との中身のチェック
            foreach (var v in indexer2.Indexed())
            {
                v.Element.Is(arr[v.Col, v.Row]);
            }

            // ループによる、元の配列との中身のチェック
            for (int r = 0; r < indexer2.Height; r++)
            {
                for (int c = 0; c < indexer2.Width; c++)
                {
                    indexer2[c, r].Is((c+1) * (r+1));
                    indexer2[c, r] = 0;
                    indexer2[c, r].Is(0);
                }
            }
        }
Ejemplo n.º 2
0
        private static void SecondIndexerRunner()
        {
            NewSubject.WriteLine(nameof(Indexer2 <string>));

            var count = 0;
            var myStringCollection = new Indexer2 <string>();

            myStringCollection.Add($"My Test {++count}");
            myStringCollection.Add($"My Test {++count}");

            for (int i = 0; i < count; i++)
            {
                Console.WriteLine($"myStringCollection {i}: {myStringCollection[i]}");
            }
        }
Ejemplo n.º 3
0
        public void Test2()
        {
            Indexer2 indexer2 = new Indexer2();

            try
            {
                int idade1     = indexer2["nome1"];
                int idade2     = indexer2["nome2"];
                int idadeError = indexer2["lalalala"];
            }
            catch (ArgumentNullException argEx)
            {
                //tratar esse problema
            }
            catch (Exception e)
            {
                //tratar genericamente
            }

            Assert.Pass();
        }