Example #1
0
        public void StringToInt_Positive()
        {
            StringToInt stringToInt = new StringToInt();
            var ret = stringToInt.Convert("+12345".ToCharArray());

            Assert.AreEqual(12345, ret);
        }
Example #2
0
        public void StringToInt_String()
        {
            StringToInt stringToInt = new StringToInt();
            var ret = stringToInt.Convert("a123".ToCharArray());

            Assert.AreEqual(0, ret);
        }
Example #3
0
        public void StringToInt_Max()
        {
            StringToInt stringToInt = new StringToInt();
            var ret = stringToInt.Convert("2147483647".ToCharArray());

            Assert.AreEqual(2147483647, ret);
        }
Example #4
0
        public void StringToInt()
        {
            StringToInt stringToInt = new StringToInt();
            var ret = stringToInt.Convert("1234567890".ToCharArray());

            Assert.AreEqual(1234567890, ret);
        }
Example #5
0
        public static void Main()
        {
            StringToInt sti = new StringToInt(CountChars);

            Console.WriteLine(sti.Invoke("I ate a bear. Who wins now huh?"));
            Console.WriteLine(sti.Invoke("I used to be a strong man, now I'm stronger!"));
            Console.WriteLine(sti.Invoke("I found money in my asscrack the other day. I suspect fame will reach me any moment now"));
            Console.WriteLine(DelegateUser(sti, "Yes baby, turn me into a pamphlet"));
            Console.ReadKey();
        }
Example #6
0
 public void StringToInt_OutofRange()
 {
     try
     {
         StringToInt stringToInt = new StringToInt();
         var ret = stringToInt.Convert("2147483649".ToCharArray());
     }
     catch (Exception ex)
     {
         Assert.AreEqual("Out", ex.Message);
     }
 }
Example #7
0
 static void Main(string[] args)
 {
     Question1.Test();
     EvaluateReversePolishNotation.Test();
     MedianTwoSortedArrays.Test();
     StringSum.Test();
     LongestSubstringWithoutRepeatingChar.Test();
     CustomSort.Test();
     MergeIntervals.Test();
     RegexMatch.Test();
     StringToInt.Test();
 }
 public void WhiteSpacePrefixAndSuffix()
 {
     Assert.AreEqual(45735, StringToInt.Stoi("    zaf-=137198274nf", out var idx, 36));
     Assert.AreEqual("    zaf".Length, idx);
 }
 public void Base0DetectBase16()
 {
     Assert.AreEqual(44810, StringToInt.Stoi("    0xAF0A-=137198274nf", out var idx, 0));
     Assert.AreEqual("    0xAF0A".Length, idx);
 }
 public void HexaDecimal()
 {
     Assert.AreEqual(19918245, StringToInt.Stoi("12FEDA5", out var idx, 16));
     Assert.AreEqual("12FEDA5".Length, idx);
 }
 public void Octal()
 {
     Assert.AreEqual(46396, StringToInt.Stoi("132474", out var idx, 8));
     Assert.AreEqual("132474".Length, idx);
 }
 public void Decimal()
 {
     Assert.AreEqual(12345, StringToInt.Stoi("12345", out var idx, 10));
     Assert.AreEqual("12345".Length, idx);
 }
Example #13
0
 public static int DelegateUser(StringToInt toInt, string str)
 {
     return(toInt(str));
 }
Example #14
0
 public static int DelegateUser(this string s, StringToInt del)
 {
     return(del(s));
 }
Example #15
0
        public static int DelegateUser(StringToInt sti, string str)
        {
            int result = sti(str);

            return(result);
        }
 public void Base0DetectDecimal()
 {
     Assert.AreEqual(3546752, StringToInt.Stoi("    3546752-=137198274nf", out var idx, 0));
     Assert.AreEqual("    3546752".Length, idx);
 }
        public void StringToIntCorrectlyConvertsToJson()
        {
            var sti = new StringToInt();

            sti.ToString().ShouldEqual(StringToIntJson);
        }
Example #18
0
 //7
 public static int DelegateUser(StringToInt ST, string str)
 {
     return(ST(str));
 }