Example #1
0
        public void ParseStringToInt_ReturnInt()
        {
            string s = "104";

            var actualResult = parser.Parse(s);

            Assert.AreEqual(actualResult, 104);
        }
Example #2
0
        static void Main(string[] args)
        {
            IntParser parser = new IntParser();

            string s = "104";

            Console.WriteLine(s + " - " + parser.Parse(s) + "\n");

            s = "1";
            Console.WriteLine(s + " - " + parser.Parse(s) + "\n");

            s = "0";
            Console.WriteLine(s + " - " + parser.Parse(s) + "\n");

            s = "14";
            Console.WriteLine(s + " - " + parser.Parse(s) + "\n");

            s = "1MSD0";
            Console.WriteLine(s + " - " + parser.Parse(s) + "\n");

            s = "154645";
            Console.WriteLine(s + " - " + parser.Parse(s) + "\n");

            s = "1546451127168460";
            Console.WriteLine(s + " - " + parser.Parse(s) + "\n");

            s = "";
            Console.WriteLine(s + " - " + parser.Parse(s) + "\n");

            Console.ReadLine();
        }
 public static Either <TLeft, int> ParseToInt <TLeft>(
     this Either <TLeft, string> source,
     IFormatProvider provider,
     TLeft left)
 {
     return(source.FlatMap(x => IntParser.Parse <TLeft>(x, provider, left)));
 }
 public static Either <TLeft, int> ParseToInt <TLeft>(
     this Either <TLeft, string> source,
     NumberStyles style,
     TLeft left)
 {
     return(source.FlatMap(x => IntParser.Parse <TLeft>(x, style, left)));
 }
 public static Either <TLeft, int> ParseToInt <TLeft>(
     this string source,
     NumberStyles style,
     IFormatProvider provider,
     TLeft left)
 {
     return(IntParser.Parse <TLeft>(source, style, provider, left));
 }
 public void ParseExtremesTests(string input)
 {
     try
     {
         IntParser.Parse(input);
     }
     catch (Exception exception)
     {
         exception.GetType().Should().Be <ArgumentException>();
     }
 }
Example #7
0
        public int SelectOption(string input)
        {
            IntParser intParser;
            int       menuOption;

            try
            {
                intParser  = new IntParser();
                menuOption = intParser.Parse(input);

                if (!Enum.IsDefined(typeof(Options), menuOption))
                {
                    throw new InvalidOperationException();
                }
            }
            catch (Exception)
            {
                menuOption = 0;
                this.writer.WriteLine("Invalid option! Try again!");
            }

            return(menuOption);
        }
        public void ParseFaliureTests(string input)
        {
            var action = new Action(() => { IntParser.Parse(input); });

            action.ShouldThrow <Exception>().WithMessage("Not valid input");
        }
        public void ParseTest(string input, int expectedValue)
        {
            var results = IntParser.Parse(input);

            results.Should().Be(expectedValue);
        }
 public static Either <TLeft, int> ParseToInt <TLeft>(this string source, TLeft left)
 {
     return(IntParser.Parse(source, left));
 }
 public static Maybe <int> ParseToInt(this string source)
 {
     return(IntParser.Parse(source));
 }
 public static Maybe <int> ParseToInt(this Maybe <string> source, NumberStyles style, IFormatProvider provider)
 {
     return(source.FlatMap(x => IntParser.Parse(x, style, provider)));
 }
 public static Maybe <int> ParseToInt(this Maybe <string> source, NumberStyles style)
 {
     return(source.FlatMap(x => IntParser.Parse(x, style)));
 }
 public static Maybe <int> ParseToInt(this string source, NumberStyles style, IFormatProvider provider)
 {
     return(IntParser.Parse(source, style, provider));
 }
 public static Maybe <int> ParseToInt(this string source, NumberStyles style)
 {
     return(IntParser.Parse(source, style));
 }