コード例 #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);
            }
        }
コード例 #11
0
        public void ZeroAtTheEndDoesNotCount()
        {
            //Arrange
            var calculation = new ReverseInteger();
            //act
            var reversed = calculation.Reverse(120);

            //Assert
            Assert.Equal(21, reversed);
        }
コード例 #12
0
        public void ThreeMinusNumbersReturnRevresedAndStillMinus()
        {
            //Arrange
            var calculation = new ReverseInteger();
            //act
            var reversed = calculation.Reverse(-123);

            //Assert
            Assert.Equal(-321, reversed);
        }
コード例 #13
0
        public void NumberReturnedIsNotHigherThanThe32BitIntegerRange()
        {
            //Arrange
            var calculation = new ReverseInteger();
            //Act
            var reversed = calculation.Reverse(1534236469);

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

            //Assert
            Assert.Equal(321, reversed);
        }
コード例 #15
0
        public void OneNumberReturnsNumber()
        {
            //Arrange
            var calculation = new ReverseInteger();
            //act
            var reversed = calculation.Reverse(1);

            //Assert
            Assert.Equal(1, reversed);
        }
コード例 #16
0
        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);
        }
コード例 #18
0
        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);
        }
コード例 #19
0
        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
ファイル: Program.cs プロジェクト: ArmaanMcleod/LeetCode
        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);
        }
コード例 #29
0
        public void PostiveNumber()
        {
            int result = ReverseInteger.Reverse(8734);

            Assert.Equal(4378, result);
        }
コード例 #30
0
        public void PositiveNumberBorderline()
        {
            int result = ReverseInteger.Reverse(2147483647);

            Assert.Equal(0, result);
        }