Пример #1
0
        public void ReverseTest()
        {
            var c = new ReverseInteger();

            // example1
            var target   = 123;
            var result   = c.Reverse(target);
            var expected = 321;

            Assert.AreEqual(expected, result);

            // example2
            target   = -123;
            result   = c.Reverse(target);
            expected = -321;
            Assert.AreEqual(expected, result);

            //example3
            target   = 120;
            result   = c.Reverse(target);
            expected = 21;
            Assert.AreEqual(expected, result);


            target   = 0;
            result   = c.Reverse(target);
            expected = 0;
            Assert.AreEqual(expected, result);
        }
Пример #2
0
        public void Reverse_WhenCalledWithExample1_ReturnsCorrectResult()
        {
            // Arrange
            var input    = 123;
            var expected = 321;

            // Act
            var result = _reverseInteger.Reverse(input);

            // Assert
            Assert.AreEqual(expected, result);
        }
Пример #3
0
        public void GivenNullValue_ShouldThrowArgumentException(int?value)
        {
            Action action = () => ReverseInteger.Reverse(value);

            action.Should().Throw <ArgumentException>()
            .WithMessage("Value can not be null");
        }
Пример #4
0
        public void Reverse(int num, int expected)
        {
            var ri     = new ReverseInteger();
            var result = ri.Reverse(num);

            result.Should().Be(expected);
        }
Пример #5
0
        public void ReverseInteger()
        {
            ReverseInteger reverseInteger = new ReverseInteger();
            int            num            = 123;

            Assert.AreEqual(reverseInteger.Reverse(num), 321);
        }
Пример #6
0
        public void TestSolution(int input, int expectedResult)
        {
            var soln   = new ReverseInteger();
            var result = soln.Reverse(input);

            Assert.Equal(expectedResult, result);
        }
Пример #7
0
        public void Reverse_Basic()
        {
            var srv = new ReverseInteger();

            int r = srv.Reverse(123);

            Assert.AreEqual(321, r);
        }
Пример #8
0
        public void Reverse_Overflow_Return_0()
        {
            var srv = new ReverseInteger();

            int r = srv.Reverse(int.MaxValue);

            Assert.AreEqual(0, r);
        }
Пример #9
0
        public void Reverse_Under_0()
        {
            var srv = new ReverseInteger();

            int r = srv.Reverse(-123);

            Assert.AreEqual(-321, r);
        }
Пример #10
0
        public void ReverseTest()
        {
            var xList     = new[] { 123, -120, 0 };
            var expecteds = new[] { 321, -21, 00 };

            foreach (var(x, expected) in xList.Zip(expecteds))
            {
                ReverseInteger.Reverse(x).Should().Be(expected);
            }
        }
        public void ZeroAtTheEndDoesNotCount()
        {
            //Arrange
            var calculation = new ReverseInteger();
            //act
            var reversed = calculation.Reverse(120);

            //Assert
            Assert.Equal(21, reversed);
        }
        public void ThreeMinusNumbersReturnRevresedAndStillMinus()
        {
            //Arrange
            var calculation = new ReverseInteger();
            //act
            var reversed = calculation.Reverse(-123);

            //Assert
            Assert.Equal(-321, reversed);
        }
        public void NumberReturnedIsNotHigherThanThe32BitIntegerRange()
        {
            //Arrange
            var calculation = new ReverseInteger();
            //Act
            var reversed = calculation.Reverse(1534236469);

            //Assert
            Assert.Equal(0, reversed);
        }
        public void ThreeNumbersAreReveresed()
        {
            //Arrange
            var calculation = new ReverseInteger();
            //act
            var reversed = calculation.Reverse(123);

            //Assert
            Assert.Equal(321, reversed);
        }
        public void OneNumberReturnsNumber()
        {
            //Arrange
            var calculation = new ReverseInteger();
            //act
            var reversed = calculation.Reverse(1);

            //Assert
            Assert.Equal(1, reversed);
        }
        public void NumberReturnedIsNotLowerThanThe32BitIntegerRange()
        {
            //Arrange
            var calculation = new ReverseInteger();
            //Act
            var reversed = calculation.Reverse(-2147483648);

            //Assert
            Assert.Equal(0, reversed);
        }
Пример #17
0
        public void ReverseInteger(int input, int expected)
        {
            // Arrange
            var sut = new ReverseInteger();
            // Act
            var result = sut.Reverse(input);

            // Assert
            result.Should().Be(expected);
        }
        public void Input1534236469()
        {
            //Arrange
            var reverseInteger = new ReverseInteger();
            var expected       = 0;
            var intput         = 1534236469;
            //Act
            var act = reverseInteger.Reverse(intput);

            //Assert
            Assert.AreEqual(expected, act);
        }
        public void Input123Oupt321()
        {
            //Arrange
            var reverseInteger = new ReverseInteger();
            var expected       = 321;
            var intput         = 123;
            //Act
            var act = reverseInteger.Reverse(intput);

            //Assert
            Assert.AreEqual(expected, act);
        }
Пример #20
0
        private static void ReverseIntegerTest()
        {
            Console.WriteLine("\nReverse Integer question:");

            int[] testNumbers = new int[] { 123, -123, 120, 1534236469 };

            ReverseInteger reverseInteger = new ReverseInteger();

            foreach (int number in testNumbers)
            {
                Console.WriteLine("{0} -> {1}", number, reverseInteger.Reverse(number));
            }
        }
Пример #21
0
        public void OverflowNegativeLargeNumberTest()
        {
            // arrange
            int inputNumber            = -1234567899;// this reversed will be 9,987,654,321 which is beyond the Int32
            int expectedReversedNumber = 0;

            // act
            ReverseInteger reverseInteger       = new ReverseInteger();
            int            actualReversedNumber = reverseInteger.Reverse(inputNumber);

            // assert
            Assert.AreEqual(expectedReversedNumber, actualReversedNumber);
        }
Пример #22
0
        public void ReversePositiveNumberTest()
        {
            // arrange
            int inputNumber            = 123;
            int expectedReversedNumber = 321;

            // act
            ReverseInteger reverseInteger       = new ReverseInteger();
            int            actualReversedNumber = reverseInteger.Reverse(inputNumber);

            // assert
            Assert.AreEqual(expectedReversedNumber, actualReversedNumber);
        }
Пример #23
0
        public void ReverseIntegerTest()
        {
            var solution = new ReverseInteger();

            Assert.Equal(321, solution.Reverse(123));
            Assert.Equal(-321, solution.Reverse(-123));
            Assert.Equal(21, solution.Reverse(120));
            Assert.Equal(-1, solution.Reverse(-1));
            Assert.Equal(0, solution.Reverse(0));
            Assert.Equal(0, solution.Reverse(1534236469));
            Assert.Equal(0, solution.Reverse(-2147483648));
        }
        public void Reverse_PassedNegative2147483648_ThrowsException()
        {
            Exception exception = null;

            try
            {
                ReverseInteger.Reverse(-2147483648);
            }
            catch (Exception ex)
            {
                exception = ex;
            }
            Assert.IsNotNull(exception);
        }
Пример #25
0
        public void Examples(int input, int expected)
        {
            // Given

            // When
            _stopwatch.Start();
            var result = _sut.Reverse(input);

            _stopwatch.Stop();

            // Then
            result.Should().Be(expected);

            Console.WriteLine($"Ran for: {_stopwatch.Elapsed.Milliseconds} ms");
            Console.WriteLine($"Ran for: {_stopwatch.Elapsed.Ticks} ticks");
        }
Пример #26
0
        public void ReversesAllIntegerInput()
        {
            // Arrange
            var reverser = new ReverseInteger();

            // Act | Assert
            Assert.AreEqual("0", reverser.Reverse(0));
            Assert.AreEqual("9", reverser.Reverse(9));
            Assert.AreEqual("01", reverser.Reverse(10));
            Assert.AreEqual("51", reverser.Reverse(15));
            Assert.AreEqual("84", reverser.Reverse(48));
            Assert.AreEqual("415", reverser.Reverse(514));
            Assert.AreEqual("4201", reverser.Reverse(1024));
        }
Пример #27
0
        public void ReverseTest_Examples()
        {
            // Arrange
            ReverseInteger algo = new ReverseInteger();

            int[] input    = { 123, -123, 120 };
            int[] expected = { 321, -321, 21 };

            for (int i = 0; i < input.Length; i++)
            {
                // Act
                int result = algo.Reverse(input[i]);

                // Assert
                Assert.AreEqual(result, expected[i]);
            }
        }
Пример #28
0
        public void TestReverseInteger()
        {
            var r = ReverseInteger.Reverse(123);

            Assert.AreEqual(r, 321);

            r = ReverseInteger.Reverse(-123);
            Assert.AreEqual(r, -321);

            r = ReverseInteger.Reverse(120);
            Assert.AreEqual(r, 21);

            r = ReverseInteger.Reverse(2147483647);
            Assert.AreEqual(r, 0);

            r = ReverseInteger.Reverse(-2147483648);
            Assert.AreEqual(r, 0);
        }
        public void PostiveNumber()
        {
            int result = ReverseInteger.Reverse(8734);

            Assert.Equal(4378, result);
        }
        public void PositiveNumberBorderline()
        {
            int result = ReverseInteger.Reverse(2147483647);

            Assert.Equal(0, result);
        }