Beispiel #1
0
        public void TestStringToInteger()
        {
            StringToInteger stringToInteger = new StringToInteger();

            Assert.Equal(42, stringToInteger.MyAtoi("42"));
            Assert.Equal(-42, stringToInteger.MyAtoi("   -42"));
            Assert.Equal(4193, stringToInteger.MyAtoi("4193 with words"));
            Assert.Equal(0, stringToInteger.MyAtoi("words and 987"));
            Assert.Equal(-2147483648, stringToInteger.MyAtoi("-91283472332"));
            //Assert.Equal(3.14159, stringToInteger.MyAtoi("3.14159"));
        }
        public void MyAtoiTest6()
        {
            var input    = "90000000000";
            var expected = int.MaxValue;

            StringToInteger.MyAtoi(input).Should().Be(expected);
        }
        public void MyAtoiTest5()
        {
            var input    = "-91283472332";
            var expected = int.MinValue;

            StringToInteger.MyAtoi(input).Should().Be(expected);
        }
        public void MyAtoiTest4()
        {
            var input    = "words and 987";
            var expected = 0;

            StringToInteger.MyAtoi(input).Should().Be(expected);
        }
        public void MyAtoiTest3()
        {
            var input    = "4193 with words";
            var expected = 4193;

            StringToInteger.MyAtoi(input).Should().Be(expected);
        }
        public void MyAtoiTest2()
        {
            var input    = "   -42";
            var expected = -42;

            StringToInteger.MyAtoi(input).Should().Be(expected);
        }
        public void TestName()
        {
            //Given
            var instance = new StringToInteger();
            var s1       = "42";
            var s2       = "  -42";
            var s3       = "4193 with words";
            var s4       = "words and 987";
            var s5       = "-91283472332";

            //When

            //Then
            Assert.Equal(42, instance.MyAtoi(s1));
            Assert.Equal(-42, instance.MyAtoi(s2));
            Assert.Equal(4193, instance.MyAtoi(s3));
            Assert.Equal(0, instance.MyAtoi(s4));
            Assert.Equal(-2147483648, instance.MyAtoi(s5));
        }
Beispiel #8
0
        private static void StringToIntegerTest()
        {
            Console.WriteLine("\nReverse Integer question:");

            string[] testStrings = new string[] { "42", "   -42", "4193 with words", "words and 987", "-91283472332", "+1", "2147483648" };

            StringToInteger stringToInteger = new StringToInteger();

            foreach (string str in testStrings)
            {
                Console.WriteLine("{0} -> {1}", str, stringToInteger.MyAtoi(str));
            }
        }
        public void StringToIntegerTestMethod5()
        {
            int value = StringToInteger.MyAtoi("-91283472332");

            Assert.AreEqual(-2147483648, value);
        }
        public void StringToIntegerTestMethod4()
        {
            int value = StringToInteger.MyAtoi("words and 987");

            Assert.AreEqual(0, value);
        }
        public void StringToIntegerTestMethod3()
        {
            int value = StringToInteger.MyAtoi("4193 with words");

            Assert.AreEqual(4193, value);
        }
        public void StringToIntegerTestMethod2()
        {
            int value = StringToInteger.MyAtoi("   -42");

            Assert.AreEqual(-42, value);
        }
        void InternalTest(string str, int expected)
        {
            int actual = StringToInteger.MyAtoi(str);

            Assert.Equal <int>(expected, actual);
        }