示例#1
0
    public void PrintMatrix_OneFilledElement()
    {
        Console.SetIn(new StringReader("1"));
        int input = int.Parse(Console.ReadLine());

        MatrixWalk matrixWalk = new MatrixWalk(input);
        matrixWalk.Fill();
        string result = matrixWalk.Print();

        Assert.AreEqual(result, string.Format("{0,4}{1}", 1, Environment.NewLine));
    }
示例#2
0
    static void Main()
    {
        Console.Write("Enter a positive number: ");
        string input = Console.ReadLine();
        int number;
        while (!int.TryParse(input, out number) || number < 0 || number > 100)
        {
            Console.Write("You haven't entered a correct positive number. Enter again: ");
            input = Console.ReadLine();
        }

        MatrixWalk matrixWalk = new MatrixWalk(number);
        matrixWalk.Fill();
        Console.Write(matrixWalk.Print());
    }
示例#3
0
    public void PrintMatrix_InputSix()
    {
        Console.SetIn(new StringReader("6"));
        int input = int.Parse(Console.ReadLine());

        MatrixWalk matrixWalk = new MatrixWalk(input);
        matrixWalk.Fill();
        string result = matrixWalk.Print();
        string expected =
            "   1  16  17  18  19  20" + Environment.NewLine +
            "  15   2  27  28  29  21" + Environment.NewLine +
            "  14  31   3  26  30  22" + Environment.NewLine +
            "  13  36  32   4  25  23" + Environment.NewLine +
            "  12  35  34  33   5  24" + Environment.NewLine +
            "  11  10   9   8   7   6" + Environment.NewLine;

        Assert.AreEqual(result, expected);
    }