public void TestArrayArrange()
 {
     int[] list = {1,2,3,4,5,6,7,8,9};
     Columnize.Arrangement<int> intArrange = new Columnize.Arrangement<int>();
     int[][] data = intArrange.ArrangeByRow (list, 3, 3);
     int[][] expect = {
         new int[] {1,2,3},
         new int[] {4,5,6},
         new int[] {7,8,9}
     };
     Assert.AreEqual(data, expect, "rows for (1..9), 3,3");
     data = intArrange.ArrangeByColumn (list, 3, 3);
     int[][] expect2 = {
         new int[] {1,4,7},
         new int[] {2,5,8},
         new int[] {3,6,9}
     };
     Assert.AreEqual(data, expect2, "cols for (1..9), 3,3");
     int[] list2 = {1,2,3,4,5};
     int[][] expect3 = {
         new int[] {1,3,5},
         new int[] {2,4}
     };
     data = intArrange.ArrangeByColumn (list2, 2, 3);
     Assert.AreEqual(data, expect3, "cols for (1..5), 2,3");
 }
示例#2
0
        public static void Main(string[] args)
        {
            // var data = new string[55];
            // for (int i=0; i<55; i++) {
            // 	data [i] = i.ToString ();
            // }
            // var opts = new Opts.Opts ();
            // opts.DisplayWidth = 39;
            // opts.ColSep = "  ";
            // // horizontal
            // opts.ArrangeVertical = false;

            // var rowcolData = new Columnize(data, opts).minRowsAndColwidths();
            // return;

            string [] theArray5 = {"1", "2", "3", "4", "5"};
            Columnize.Arrangement<string> stringArrange = new Columnize.Arrangement<string>();
            string[][] rows = stringArrange.ArrangeByRow(theArray5, 3, 2);
            for (int i=0; i<rows.GetLength(0); i++) {
                for (int j=0; j<rows[i].GetLength(0); j++) {
                    Console.Write ("{0} ", rows[i][j]);
                }
                Console.WriteLine ();
            }
            Console.WriteLine ();

            rows = stringArrange.ArrangeByColumn(theArray5, 2, 3);
            for (int i=0; i<rows.GetLength(0); i++) {
                for (int j=0; j<rows[i].GetLength(0); j++) {;
                    Console.Write ("{0} ", rows[i][j]);
                }
                Console.WriteLine();
            }

            string[] theArray = {"1", "2"};
            var opts = new Opts.Opts (DisplayWidth: 60);
            Console.WriteLine ("Displaywidth {0}", opts.DisplayWidth);
            Console.WriteLine ("Arrange Vertical {0}", opts.ArrangeVertical);

            opts.DisplayWidth = 1;
            Console.WriteLine (Columnize.columnize (theArray, opts));
            Console.WriteLine ("Displaywidth {0}", opts.DisplayWidth);

            opts = Opts.Opts.DefaultOpts();
            opts.ArrangeVertical = false;
            Console.WriteLine ("{0}", opts.DisplayWidth);
            Console.WriteLine ("{0}", opts.ArrangeVertical);

            Console.WriteLine (Columnize.columnize (theArray, opts));

            theArray = new string[] {};
            Console.Write (Columnize.columnize (theArray, opts));
            theArray = new string[] {"1"};
            Console.Write (Columnize.columnize (theArray, opts));
        }
示例#3
0
 public void TestArrangeRowsandCols()
 {
     string[] theArray = {"1", "2", "3", "4", "5"};
     Columnize.Arrangement<string> stringArrange = new Columnize.Arrangement<string>();
     string[][] got = stringArrange.ArrangeByRow (theArray, 3, 2);
     var expect = new string[][]{ new string[]{"1", "2"}, new string[]{ "3", "4" }, new string[]{ "5"}};
     Assert.AreEqual (expect, got, "ArrangeByRow");
     got = stringArrange.ArrangeByColumn (theArray, 2, 3);
     expect = new string[][]{ new string[]{"1", "3", "5"}, new string[]{ "2", "4" }};
     Assert.AreEqual (expect, got, "ArrangeByColumn");
 }