Exemplo n.º 1
0
        public static void ExampleTuples()
        {
            Console.WriteLine();
            Console.WriteLine("====== Value Tuples - Example Tuples ======");

            Console.WriteLine("=== Simple Tuple ===");
            var simpleTuple = GetSimpleTuple();

            Console.WriteLine($"simple tuple: {simpleTuple}");
            Console.WriteLine($"item2 of simple tuple: {simpleTuple.Item2}");
            var(_, _, onlyThirdValue) = simpleTuple;
            Console.WriteLine($"last item of simple tuple: { onlyThirdValue}");

            Console.WriteLine("=== Named Tuple ===");
            var namedTuple = GetNamedTuple();

            Console.WriteLine($"named tuple: {namedTuple}");
            Console.WriteLine($"inside of named tuple: {namedTuple.inside}");
            var(_, _, canITakeLastElementLikeThat) = namedTuple;
            Console.WriteLine($"last item of named tuple: { canITakeLastElementLikeThat}");

            Console.WriteLine("=== Deconstruct ===");
            var(_, _, whatIsAreaThen) = new MagicSquare(11, 41);
            Console.WriteLine($"area of MagicSquare: {whatIsAreaThen}");

            Console.WriteLine("====================================================================");
        }
Exemplo n.º 2
0
        public void IsMagicReturnsCorrectSquareState(string stringSequence, bool shouldBeMagic)
        {
            MagicSquare square = new MagicSquare(stringSequence);

            bool isMagic = square.IsMagic();

            isMagic.Should().Be(shouldBeMagic);
        }
Exemplo n.º 3
0
        public void ChangeValueOfSquareReturnsCorrectNumberOfChanges(string stringSequence, int changeValue, int expectedChangeValue)
        {
            MagicSquare square = new MagicSquare(stringSequence);

            square = square.ChangeValueOfSquareAtLocation(0, 0, changeValue);

            square.GetNumberOfChanges().Should().Be(expectedChangeValue);
        }
Exemplo n.º 4
0
        public void MultipleChangesOutputCorrectChangeValue()
        {
            MagicSquare square = new MagicSquare("4,9,2,3,5,7,8,1,5");

            square = square
                     .ChangeValueOfSquareAtLocation(0, 0, 5)
                     .ChangeValueOfSquareAtLocation(0, 0, 7)
                     .ChangeValueOfSquareAtLocation(2, 2, 7);

            square.GetNumberOfChanges().Should().Be(5);
        }