public void TestCyclicDependency()
        {
            string testexample     = "a=>" + "\r\n" + "b=>c" + "\r\n" + "c=>f" + "\r\n" + "d=>a" + "\r\n" + "e=>" + "\r\n" + "f=>b";
            string expectedresult  = "Cyclic Dependency.";
            IStringManipulations s = new StringManipulations();

            Assert.AreEqual(s.JobDependencey(testexample), expectedresult);
        }
        public void TestSelfDependency()
        {
            string testexample     = "a=>" + "\r\n" + "b=>" + "\r\n" + "c=>c";
            string expectedresult  = "Jobs cannot Depend on themselves.";
            IStringManipulations s = new StringManipulations();

            Assert.AreEqual(s.JobDependencey(testexample), expectedresult);
        }
示例#3
0
        public IActionResult Producers(int[] c, int[] i)
        {
            var selc = c.ToList();
            var seli = i.ToList();

            ViewData["comunas"] = from Comuna u in _context.Comuna
                                  .Where(a => a.Id != 0 &&
                                         a.Centres.Any(b => b.Type == CentreTypes.Cultivo))
                                  .Include(a => a.Centres)
                                  .Include(a => a.Provincia)
                                  .ThenInclude(a => a.Region)
                                  select new BSSVM {
                Selected = selc.Contains(u.Id),
                Subtext  =
                    $"{StringManipulations.ToRomanNumeral(u.Provincia.Region.Id)} {u.Provincia.Region.Name}, {u.Provincia.Name}",
                Value  = u.Id,
                Text   = u.Name,
                Tokens = string.Join(" ", u.Centres.Select(k => k.Address))
            };

            TextInfo textInfo = new CultureInfo("es-CL", false).TextInfo;

            ViewData["company"] = from Company u in _context.Company
                                  .Where(a => a.Acronym != null)
                                  select new BSSVM
            {
                Tokens   = u.BsnssName + string.Join(" ", u.Centres.Select(k => k.Address)),
                Selected = seli.Contains(u.Id),
                Subtext  =
                    $"({u.Acronym}) {u.Id}-{StringManipulations.GetDigit(u.Id)}",
                Value  = u.Id,
                Text   = textInfo.ToTitleCase(textInfo.ToLower(u.BsnssName.Substring(0, Math.Min(u.BsnssName.Length, 50)))),
                Hellip = u.BsnssName.Length > 50
            };

            ViewData["c"] = string.Join(",", c);
            ViewData["i"] = string.Join(",", i);

            var centres = _context.Centre
                          .Where(
                a => a.Type == (CentreTypes)1 && a.CompanyId != 55555555)
                          .Include(a => a.Coordinates)
                          .Where(
                a => a.Coordinates.Any() &&
                c.Any() && a.ComunaId.HasValue ? selc.Contains(a.ComunaId.Value) : true &&
                i.Any() ? seli.Contains(a.CompanyId) : true
                )
                          .Include(a => a.Company)
                          .Include(a => a.Samplings)
                          .Include(a => a.Comuna)
                          .ThenInclude(a => a.Provincia)
                          .ThenInclude(a => a.Region);

            return(View(centres));
        }
示例#4
0
        public IActionResult GameEngine(Round round)
        {
            if (ModelState.IsValid == false)
            {
                return(NotFound());
            }

            int inputLength = round.UserGuess.Length;

            if (inputLength == 1)
            {
                if (StringManipulations.ContainsCharacter(round.Capital, round.UserGuess))
                {
                    round.CapitalPlaceholder = StringManipulations.ReplaceCharactersInWord(round.Capital, round.CapitalPlaceholder, round.UserGuess);
                    if (round.CapitalPlaceholder == round.Capital)
                    {
                        round.RoundState = "won";
                    }
                }
                else
                {
                    round.WrongGuess    = round.UserGuess;
                    round.PlayersLifes -= 1;
                }
            }
            else
            {
                if (round.UserGuess == round.Capital)
                {
                    round.RoundState = "won";
                }
                else
                {
                    round.WrongGuess    = round.UserGuess;
                    round.PlayersLifes -= 2;
                }
            }

            if (round.PlayersLifes <= 0)
            {
                round.RoundState = "lost";
            }
            else if (round.PlayersLifes == 1)
            {
                round.Hint = $"The capital of {round.Country}";
            }

            round.UserGuess        = null;
            round.NumberOfGuesses += 1;

            return(Json(round));
        }
示例#5
0
        public string Format(String format, Object obj, IFormatProvider provider)
        {
            // Display information about method call.
            if (!this.Equals(provider))
            {
                return(null);
            }

            // Set default format specifier
            if (string.IsNullOrEmpty(format))
            {
                format = "N";
            }

            string numericString = obj.ToString();

            if (obj is int && format.ToUpper().Equals("U"))
            {
                return(String.Format("{0,9:N0}-{1}", obj, StringManipulations.GetDigit((int)obj)));
            }

            if (obj is string && format.ToUpper().Equals("I"))
            {
                return(Regex.Replace(obj.ToString(), "-.*", "").Replace(".", ""));
            }

            // If this is a byte and the "R" format string, format it with Roman numerals.
            if (obj is int && format.ToUpper().Equals("R"))
            {
                return(StringManipulations.ToRomanNumeral((int)obj));
            }

            // Use default for all other formatting.
            if (obj is IFormattable)
            {
                return(((IFormattable)obj).ToString(format, CultureInfo.CreateSpecificCulture("es-CL")));
            }
            else
            {
                return(obj.ToString());
            }
        }
示例#6
0
        public void Show()
        {
            CommonViews.Title(StringManipulations.AddSpacesBeetween(GetType().Name));

            Dependency dependency = Container.GetDependency(GetType());

            var methodsName = dependency.GetMethodsName();

            int userChoice = CommonViews.Menu(StringManipulations.AddSpacesBeetween(methodsName).ToArray());

            if (userChoice < methodsName.Count && userChoice >= 0)
            {
                string methodName = methodsName[userChoice];

                if (!methodName.Equals("GoBack"))
                {
                    CommonViews.Title(StringManipulations.AddSpacesBeetween(methodName));

                    object methodReturnObject = dependency.InvokeMethod(methodName, null);

                    if (methodName.StartsWith("GoTo"))
                    {
                        GoToMethod(methodName, methodReturnObject);
                    }
                    else
                    {
                        InvokeCrudMethod(methodName, methodReturnObject);
                        Console.ReadLine();
                    }
                    Show();
                }
            }
            else
            {
                Show();
            }
        }
示例#7
0
        public string Format(string format, object obj, IFormatProvider provider)
        {
            // Display information about method call.
            if (!Equals(provider))
            {
                return(null);
            }

            // Set default format specifier
            if (string.IsNullOrEmpty(format))
            {
                format = "N";
            }

            //string numericString = obj.ToString();

            if (obj is int && format.Equals("U", StringComparison.InvariantCultureIgnoreCase))
            {
                return(string.Format(CultureInfo.InvariantCulture, "{0,9:N0}-{1}", obj, StringManipulations.GetDigit((int)obj)));
            }

            // If this is a byte and the "R" format string, format it with Roman numerals.
            if (obj is int && format.Equals("R", StringComparison.InvariantCultureIgnoreCase))
            {
                return(StringManipulations.ToRomanNumeral((int)obj));
            }

            // Use default for all other formatting.
            if (obj is IFormattable)
            {
                return(((IFormattable)obj).ToString(format, CultureInfo.CurrentCulture));
            }
            else
            {
                return(obj?.ToString());
            }
        }
        public void GetNameFromUriWithoutExtensionSouldReturnNull()
        {
            var fileName = StringManipulations.GetNameFromUriWithoutExtension(string.Empty);

            Assert.Null(fileName);
        }
        public void GetNameFromUriWithoutExtensionSouldPassWithoutError(string uri)
        {
            var fileName = StringManipulations.GetNameFromUriWithoutExtension(uri);

            Assert.Equal("ggtmr0rydvxdeu2xjcoj", fileName);
        }
示例#10
0
        public IActionResult Research(int[] c, int[] i)
        {
            var selc = c.ToList();
            var seli = i.ToList();

            ViewData["comunas"] = from Comuna u in _context.Comuna
                                  .Where(a => a.Id != 0 &&
                                         a.Centres.Any(b => b.Type == CentreTypes.Investigacion))
                                  .Include(a => a.Centres)
                                  .Include(a => a.Provincia)
                                  .ThenInclude(a => a.Region)
                                  select new BSSVM {
                Selected = selc.Contains(u.Id),
                Subtext  =
                    $"{StringManipulations.ToRomanNumeral(u.Provincia.Region.Id)} {u.Provincia.Region.Name}, {u.Provincia.Name}",
                Value = u.Id,
                Text  = u.Name
            };

            TextInfo textInfo = new CultureInfo("es-CL", false).TextInfo;

            ViewData["company"] = from Company u in _context.Company
                                  .Where(a => a.Acronym != null)
                                  select new BSSVM {
                Icon     = $"bib-{u.Acronym}-mono",
                Tokens   = u.BsnssName,
                Selected = seli.Contains(u.Id),
                Subtext  =
                    $"({u.Acronym}) {u.Id}-{StringManipulations.GetDigit(u.Id)}",
                Value  = u.Id,
                Text   = textInfo.ToTitleCase(textInfo.ToLower(u.BsnssName.Substring(0, Math.Min(u.BsnssName.Length, 50)))),
                Hellip = u.BsnssName.Length > 50
            };

            ViewData["c"] = string.Join(",", c);
            ViewData["i"] = string.Join(",", i);

            var centres = _context.Centre
                          .Where(
                a => a.Type == (CentreTypes)5 && a.CompanyId != 55555555)
                          .Include(a => a.Coordinates)
                          .Where(
                a => a.Coordinates.Any() &&
                c.Any() && a.ComunaId.HasValue ? selc.Contains(a.ComunaId.Value) : true &&
                i.Any() ? seli.Contains(a.CompanyId) : true
                )
                          .Include(a => a.Company)
                          .Include(a => a.Comuna)
                          .ThenInclude(a => a.Provincia)
                          .ThenInclude(a => a.Region);

            var polygons = new List <object>();

            foreach (var g in centres)
            {
                polygons.Add(g.Coordinates.OrderBy(o => o.Vertex).Select(m =>
                                                                         new {
                    lat = m.Latitude,
                    lng = m.Longitude
                }));
            }



            return(View(centres));
        }
示例#11
0
        private async Task <string> DeleteImageFromCloudinaryAsync(string imagePath)
        {
            var cloudinaryPublicId = StringManipulations.GetNameFromUriWithoutExtension(imagePath);

            return(await CloudinaryExtension.DeleteImageImageAsync(this.cloudinary, cloudinaryPublicId));
        }
示例#12
0
    static void Main()
    {
        try
        {
            var subString = MathCalculations.Subsequence("Hello!".ToCharArray(), 2, 3);
            Console.WriteLine(subString);

            var subArray = MathCalculations.Subsequence(new int[] { -1, 3, 2, 1 }, 0, 2);
            Console.WriteLine(String.Join(" ", subArray));

            var allArray = MathCalculations.Subsequence(new int[] { -1, 3, 2, 1 }, 0, 4);
            Console.WriteLine(String.Join(" ", allArray));

            var emptyArray = MathCalculations.Subsequence(new int[] { -1, 3, 2, 1 }, 0, 0);
            Console.WriteLine(String.Join(" ", emptyArray));
        }
        catch (ArgumentException ex)
        {
            Console.WriteLine(ex.Message);
        }

        try
        {
            Console.WriteLine(StringManipulations.ExtractEnding("I love C#", 2));
            Console.WriteLine(StringManipulations.ExtractEnding("Nakov", 4));
            Console.WriteLine(StringManipulations.ExtractEnding("beer", 4));
            Console.WriteLine(StringManipulations.ExtractEnding("Hi", 100));
        }
        catch (ArgumentOutOfRangeException ex)
        {
            Console.WriteLine(ex.Message);
        }

        // The app should not throw exceptions when checking whether number is prime.
        var numbers = new int[] { 23, 33 };

        foreach (var number in numbers)
        {
            bool isPrime = MathCalculations.CheckPrime(number);

            if (isPrime)
            {
                Console.WriteLine($"{number} is prime!");
            }
            else
            {
                Console.WriteLine($"{number} is not prime!");
            }
        }

        List <Exam> peterExams = new List <Exam>()
        {
            new SimpleMathExam(2),
            new CSharpExam(55),
            new CSharpExam(100),
            new SimpleMathExam(1),
            new CSharpExam(0),
        };

        Student peter = new Student("Peter", "Petrov", peterExams);
        double  peterAverageResult = peter.CalcAverageExamResultInPercents();

        Console.WriteLine("Average results = {0:p0}", peterAverageResult);
    }