public void TestMethod2()
        {
            var stringAlgorithms = new StringAlgorithms();

            Assert.IsTrue(stringAlgorithms.AreAnagrams("123", "231"));
            Assert.IsFalse(stringAlgorithms.AreAnagrams("123", "211"));
        }
        public void Reverse_Test()
        {
            string value1 = StringAlgorithms.Reverse("Paris");
            string value2 = StringAlgorithms.Reverse("Las Vegas");
            string value3 = StringAlgorithms.Reverse("Dormitory");

            Assert.True(value1 == "siraP");
        }
Beispiel #3
0
        public void Returnsᅠzeroᅠwhenᅠtypeᅠnameᅠlistᅠisᅠempty()
        {
            var typeNames = Array.Empty <string>();

            var length = StringAlgorithms.GetDeepestCommonNamespaceLength(typeNames);

            length.Should().Be(0);
        }
        public void IsUnique_Test()
        {
            bool value1 = StringAlgorithms.IsUnique("abcdef");
            bool value2 = StringAlgorithms.IsUnique("abcad");
            bool value3 = StringAlgorithms.IsUnique("123try");

            Assert.True(value1 && !value2 && value3);
        }
Beispiel #5
0
        private static bool ComparisonStringAlgorithms()
        {
            switch (Configuration.Variant)
            {
            case "1": return(StringAlgorithms.PartialEquals(StringA, StringB));

            default: return(false);
            }
        }
Beispiel #6
0
 private static void IfFalseAlgorithms()
 {
     switch (Configuration.Variant)
     {
     case "1":
         StringA = StringAlgorithms.Sort(StringA, false);
         break;
     }
 }
        public void RemoveDuplicateChars_Test()
        {
            string value1 = StringAlgorithms.RemoveDuplicateChars("Google");
            string value2 = StringAlgorithms.RemoveDuplicateChars("Yahoo");
            string value3 = StringAlgorithms.RemoveDuplicateChars("Line1\\Line2\\Line3");


            Assert.True(value1 == "Gogle" && value2 == "Yaho");
        }
        public void IsPalidrome_Test()
        {
            bool value1 = StringAlgorithms.IsPalidrome("Radar");
            bool value2 = StringAlgorithms.IsPalidrome("Kayak");
            bool value3 = StringAlgorithms.IsPalidrome("racecar");
            bool value4 = StringAlgorithms.IsPalidrome("levelup");

            Assert.True(value1 && value2 && value3 && !value4);
        }
        public void IsAnagrams_Test()
        {
            bool value1 = StringAlgorithms.IsAnagrams("Paris", "Pairs");
            bool value2 = StringAlgorithms.IsAnagrams("Las Vegas", "Salvages");
            bool value3 = StringAlgorithms.IsAnagrams("Dormitory", "Dirty room");
            bool value4 = StringAlgorithms.IsAnagrams("Night", "Think");

            Assert.True(value1 && value2 && value3 && !value4);
        }
Beispiel #10
0
        static void Main(string[] args)
        {
            System.Console.WriteLine("Introduce a word to get all its permutations");

            var line = System.Console.ReadLine();

            System.Console.WriteLine();
            var result = new StringAlgorithms().AllPermutations(line);

            var index = 1;

            foreach (var word in result)
            {
                System.Console.WriteLine($"{index}. {word}");
                index += 1;
            }

            System.Console.WriteLine();
            System.Console.WriteLine("Please enter a list of words : ");

            System.Console.WriteLine();
            var listWords      = new List <string>();
            var shouldContinue = true;

            while (shouldContinue)
            {
                System.Console.Write("More words yes(Y) or no(N) : ");
                var command = System.Console.ReadLine();
                switch (command)
                {
                case "y":
                case "Y":
                    System.Console.Write("Introduce a word : ");
                    var readLine = System.Console.ReadLine();
                    listWords.Add(readLine);
                    break;

                case "n":
                case "N":
                    shouldContinue = false;
                    break;

                default:
                    System.Console.WriteLine("un-recognized command");
                    break;
                }
            }

            System.Console.WriteLine();
            foreach (var word in new StringAlgorithms().GetOnlyAnagrams(listWords))
            {
                System.Console.WriteLine(word);
            }

            System.Console.ReadLine();
        }
Beispiel #11
0
        public void LevenshteinDistanceVersion2Tests(
            string string1,
            string string2,
            int expected)
        {
            var distance =
                StringAlgorithms.LevenshteinDistanceVersion2(
                    string1, string2);

            Assert.AreEqual(distance, expected);
        }
Beispiel #12
0
        public void DamerauLevenshteinDistanceTests(
            string string1,
            string string2,
            int expected)
        {
            var distance =
                StringAlgorithms.DamerauLevenshteinDistance(
                    string1, string2);

            Assert.AreEqual(distance, expected);
        }
Beispiel #13
0
        public void Returnsᅠexpectedᅠlengthᅠwhenᅠsingleᅠtypeᅠnameᅠstartsᅠwithᅠnamespace(string @namespace)
        {
            var typeNames = new[]
            {
                $"{@namespace}.SomeName"
            };

            var length = StringAlgorithms.GetDeepestCommonNamespaceLength(typeNames);

            length.Should().Be(@namespace.Length + 1);
        }
Beispiel #14
0
        public void Returnsᅠzeroᅠwhenᅠoneᅠtypeᅠnameᅠisᅠempty()
        {
            var typeNames = new[]
            {
                string.Empty
            };

            var length = StringAlgorithms.GetDeepestCommonNamespaceLength(typeNames);

            length.Should().Be(0);
        }
Beispiel #15
0
        public void Returnsᅠoneᅠwhenᅠtypeᅠnamesᅠstartᅠwithᅠdot() // Not a valid programming case.
        {
            var typeNames = new[]
            {
                ".SomeName",
                ".SomeOtherName"
            };

            var length = StringAlgorithms.GetDeepestCommonNamespaceLength(typeNames);

            length.Should().Be(1);
        }
        public void TestMethod3()
        {
            var toto = new StringAlgorithms().GetOnlyAnagrams(
                new List <string>()
            {
                "123", "451", "1021", "321"
            }
                );

            Assert.IsTrue(toto.Count == 1);
            Assert.IsTrue(toto[0] == "123");
        }
Beispiel #17
0
        public void Returnsᅠzeroᅠwhenᅠdifferentᅠtypeᅠnamesᅠdoᅠnotᅠhaveᅠnamespaces()
        {
            var typeNames = new[]
            {
                "SomeName",
                "SomeOtherName"
            };

            var length = StringAlgorithms.GetDeepestCommonNamespaceLength(typeNames);

            length.Should().Be(0);
        }
Beispiel #18
0
        public void Returnsᅠzeroᅠwhenᅠoneᅠofᅠtypeᅠnamesᅠisᅠwhitespace()
        {
            var typeNames = new[]
            {
                "  ",
                "A.SomeName"
            };

            var length = StringAlgorithms.GetDeepestCommonNamespaceLength(typeNames);

            length.Should().Be(0);
        }
Beispiel #19
0
 private void EvaluteAritExpression_Click(object sender, RoutedEventArgs e)
 {
     try
     {
         var    exp = ExpressiontxtBox.Text;
         double r   = StringAlgorithms.EvaluateArithmeticExpression(exp);
         EvaluatedExpResult.Text = r.ToString();
     }
     catch (Exception ex)
     {
         MessageBox.Show(ex.Message);
     }
 }
        public void TestMethod1()
        {
            var toTest        = new StringAlgorithms().AllPermutations("123").ToList();
            var correctResult = new List <string>()
            {
                "123", "132", "213", "312", "231", "321"
            };

            for (var i = 0; i < toTest.Count; ++i)
            {
                Assert.IsTrue(toTest[i] == correctResult[i]);
            }
        }
        static void Main(string[] args)
        {
            Console.Write("Insert any sentence in your mind: \n");
            string sentence = Console.ReadLine();

            StringAlgorithms stringAlgorithms = new StringAlgorithms();

            Console.WriteLine("Reversed with While Loop: " + stringAlgorithms.ReverseSentenceWithWhileLoop(sentence), "\n");
            Console.WriteLine("Reversed with For Loop: " + stringAlgorithms.ReverseSentenceWithForLoop(sentence), "\n");
            Console.WriteLine("Reverse Words with While Loop: " + stringAlgorithms.ReverseWordsWithWhileLoop(sentence), "\n");
            Console.WriteLine("Reverse Words with For Loop: " + stringAlgorithms.ReverseWordsWithForLoop(sentence), "\n");

            Console.ReadLine();
        }
Beispiel #22
0
        public List <HitomiTagdata> GetTotalListFuzzy(string search)
        {
            List <HitomiTagdata> result = new List <HitomiTagdata>();
            List <HitomiTagdata> target = new List <HitomiTagdata>();

            target.AddRange(tagdata_collection.female);
            target.AddRange(tagdata_collection.male);
            search = search.ToLower();
            foreach (var tagdata in tagdata_collection.artist)
            {
                HitomiTagdata data = new HitomiTagdata(); data.Tag = "artist:" + tagdata.Tag.ToLower().Replace(' ', '_');
                data.Count = -StringAlgorithms.get_diff(search, tagdata.Tag.ToLower().Replace(' ', '_')); result.Add(data);
            }
            foreach (var tagdata in tagdata_collection.group)
            {
                HitomiTagdata data = new HitomiTagdata(); data.Tag = "group:" + tagdata.Tag.ToLower().Replace(' ', '_');
                data.Count = -StringAlgorithms.get_diff(search, tagdata.Tag.ToLower().Replace(' ', '_')); result.Add(data);
            }
            foreach (var tagdata in tagdata_collection.series)
            {
                HitomiTagdata data = new HitomiTagdata(); data.Tag = "series:" + tagdata.Tag.ToLower().Replace(' ', '_');
                data.Count = -StringAlgorithms.get_diff(search, tagdata.Tag.ToLower().Replace(' ', '_')); result.Add(data);
            }
            foreach (var tagdata in tagdata_collection.character)
            {
                HitomiTagdata data = new HitomiTagdata(); data.Tag = "character:" + tagdata.Tag.ToLower().Replace(' ', '_');
                data.Count = -StringAlgorithms.get_diff(search, tagdata.Tag.ToLower().Replace(' ', '_')); result.Add(data);
            }
            foreach (var tagdata in tagdata_collection.type)
            {
                HitomiTagdata data = new HitomiTagdata(); data.Tag = "type:" + tagdata.Tag.ToLower().Replace(' ', '_');
                data.Count = -StringAlgorithms.get_diff(search, tagdata.Tag.ToLower().Replace(' ', '_')); result.Add(data);
            }
            foreach (var tagdata in target)
            {
                HitomiTagdata data = new HitomiTagdata(); data.Tag = tagdata.Tag.ToLower().Replace(' ', '_');
                data.Count = -StringAlgorithms.get_diff(search, tagdata.Tag.ToLower().Replace(' ', '_')); result.Add(data);
            }
            foreach (var tagdata in tagdata_collection.tag)
            {
                HitomiTagdata data = new HitomiTagdata(); data.Tag = "tag:" + tagdata.Tag.ToLower().Replace(' ', '_');
                data.Count = -StringAlgorithms.get_diff(search, tagdata.Tag.ToLower().Replace(' ', '_')); result.Add(data);
            }
            result.Sort((a, b) => b.Count.CompareTo(a.Count));
            return(result);
        }
Beispiel #23
0
        private void 제목비슷한작품선택취소SToolStripMenuItem_Click(object sender, EventArgs e)
        {
            List <string> titles = new List <string>();

            ImagePanel.SuspendLayout();
            for (int i = 0; i < ImagePanel.Controls.Count; i++)
            {
                string ttitle = (ImagePanel.Controls[i] as PicElement).Label.Split('|')[0];
                if ((ImagePanel.Controls[i] as PicElement).Overlap ||
                    (titles.Count > 0 && !titles.TrueForAll((title) => StringAlgorithms.get_diff(ttitle, title) > HitomiSetting.Instance.GetModel().TextMatchingAccuracy)))
                {
                    (ImagePanel.Controls[i] as PicElement).Selected = false;
                    continue;
                }

                titles.Add(ttitle);
            }
            ImagePanel.ResumeLayout();
        }
Beispiel #24
0
        private async Task LoadThumbnailAsync()
        {
            List <string> titles = new List <string>();
            List <string> magics = new List <string>();

            for (int i = 0, j = 0; i < 5 && j < HitomiData.Instance.metadata_collection.Count; j++)
            {
                if (HitomiData.Instance.metadata_collection[j].Artists != null &&
                    (HitomiData.Instance.metadata_collection[j].Language == HitomiSetting.Instance.GetModel().Language || HitomiSetting.Instance.GetModel().Language == "ALL") &&
                    HitomiData.Instance.metadata_collection[j].Artists.Contains(artist))
                {
                    string ttitle = HitomiData.Instance.metadata_collection[j].Name.Split('|')[0];
                    if (titles.Count > 0 && !titles.TrueForAll((title) => StringAlgorithms.get_diff(ttitle, title) > HitomiSetting.Instance.GetModel().TextMatchingAccuracy))
                    {
                        continue;
                    }

                    titles.Add(ttitle);
                    magics.Add(HitomiData.Instance.metadata_collection[j].ID.ToString());
                    i++;
                }
            }

            if (HitomiSetting.Instance.GetModel().DetailedLog)
            {
                LogEssential.Instance.PushLog(() => $"This images will be loaded. [RecommendControl]");
                LogEssential.Instance.PushLog(magics);
            }

            for (int i = 0; i < magics.Count; i++)
            {
                _ = Task.Factory.StartNew(x => {
                    int ix = (int)x;
                    try { AddMetadataToPanel(ix, magics[ix]); } catch { }
                }, i);
            }
        }
        public void TestHasUniqueChars()
        {
            string input;
            bool   result;

            input = "nonunique";

            result = StringAlgorithms.HasUniqueChars(input);

            Assert.AreEqual(false, result);

            input = "Unique";

            result = StringAlgorithms.HasUniqueChars(input);

            Assert.AreEqual(true, result);


            input = "";

            result = StringAlgorithms.HasUniqueChars(input);

            Assert.AreEqual(true, result);
        }
Beispiel #26
0
 public void Init()
 {
     strAlgo = new StringAlgorithms();
 }
Beispiel #27
0
        public void Initialize(IList <Mike1DPluginArgument> arguments, Mike1DData mike1DData)
        {
            InitialWaterLevel initialWaterLevel             = new InitialWaterLevel();
            NetworkDataInterp <HDWaterLevelDepth> initialWl = mike1DData.HDParameters.InitialConditions.WaterLevelDepth;

            for (int i = 0; i < arguments.Count; i++)
            {
                Mike1DPluginArgument argument = arguments[i];
                if (StringComparer.OrdinalIgnoreCase.Equals("Node", argument.Key))
                {
                    string[] split = StringAlgorithms.SplitQuoted(argument.Value, ';', '"');
                    if (split.Length == 2 || split.Length == 3)
                    {
                        string nodeId = split[0];
                        if (string.IsNullOrEmpty(nodeId))
                        {
                            continue;
                        }
                        double wl;
                        if (!double.TryParse(split[1], NumberStyles.Any, CultureInfo.InvariantCulture, out wl))
                        {
                            continue;
                        }
                        // Depth or level based value - by default level
                        bool depth = (split.Length == 3 && StringComparer.OrdinalIgnoreCase.Equals("depth", split[2]));

                        initialWl.AddValue(nodeId, new HDWaterLevelDepth(!depth, wl));
                    }
                }
                else if (StringComparer.OrdinalIgnoreCase.Equals("Location", argument.Key))
                {
                    string[] split = StringAlgorithms.SplitQuoted(argument.Value, ';', '"');
                    if (split.Length == 3 || split.Length == 4)
                    {
                        string reachId = split[0];
                        if (string.IsNullOrEmpty(reachId))
                        {
                            continue;
                        }
                        double chainage;
                        if (!double.TryParse(split[1], NumberStyles.Any, CultureInfo.InvariantCulture, out chainage))
                        {
                            continue;
                        }
                        double wl;
                        if (!double.TryParse(split[2], NumberStyles.Any, CultureInfo.InvariantCulture, out wl))
                        {
                            continue;
                        }
                        // Depth or level based value - by default level
                        bool depth = (split.Length == 4 && StringComparer.OrdinalIgnoreCase.Equals("depth", split[3]));

                        initialWl.AddValue(new Location(reachId, chainage), new HDWaterLevelDepth(!depth, wl));
                    }
                }
                else if (StringComparer.OrdinalIgnoreCase.Equals("Span", argument.Key))
                {
                    string[] split = StringAlgorithms.SplitQuoted(argument.Value, ';', '"');
                    if (split.Length == 4 || split.Length == 5)
                    {
                        string reachId = split[0];
                        if (string.IsNullOrEmpty(reachId))
                        {
                            continue;
                        }
                        double chainage;
                        if (!double.TryParse(split[1], NumberStyles.Any, CultureInfo.InvariantCulture, out chainage))
                        {
                            continue;
                        }
                        double chainage2;
                        if (!double.TryParse(split[2], NumberStyles.Any, CultureInfo.InvariantCulture, out chainage2))
                        {
                            continue;
                        }
                        double wl;
                        if (!double.TryParse(split[3], NumberStyles.Any, CultureInfo.InvariantCulture, out wl))
                        {
                            continue;
                        }
                        // Depth or level based value - by default level
                        bool depth = (split.Length == 5 && StringComparer.OrdinalIgnoreCase.Equals("depth", split[4]));

                        initialWl.AddValue(new LocationSpan(reachId, chainage, chainage2), new HDWaterLevelDepth(!depth, wl));
                    }
                }
            }
        }
Beispiel #28
0
        /// <summary>
        /// Finds the specified number of the top closest matches between the
        /// query string and the database of strings to be matched against. The
        /// matching algorithm to be used is an optional parameter of
        /// the StringAlgorithms enum type; if no StringAlgorithms
        /// argument is passed in, it will default to Levenshtein distance.
        /// </summary>
        /// <typeparam name="T">the data type of the metric being used by the
        /// specified string similarity algorithm. If no algorithm is
        /// specified, this method will default to Levenshtein distance which
        /// uses an integer edit distance metric.
        /// </typeparam>
        /// <param name="query">the query string</param>
        /// <param name="database">database of strings to be matched against</param>
        /// <param name="numMatches">number of closest matches to be returned</param>
        /// <param name="algorithm"></param>
        /// <returns></returns>
        public static IList <KeyValuePair <String, T> > FindClosestMatches <T>(String query, IList <String> database, int numMatches, StringAlgorithms algorithm = StringAlgorithms.LevenshteinDistance)
        {
            IList <KeyValuePair <String, T> > result = new List <KeyValuePair <String, T> >(numMatches);

            return(result);
        }
Beispiel #29
0
 /// <summary>
 /// Calculates the
 /// </summary>
 /// <typeparam name="T"></typeparam>
 /// <param name="query">the query string</param>
 /// <param name="database">the </param>
 /// <param name=""></param>
 /// <returns></returns>
 public static IList <KeyValuePair <String, T> > GetAllDistanecs <T>(String query, IList <String> database, StringAlgorithms algorithm = StringAlgorithms.LevenshteinDistance)
 {
     return(FindClosestMatches <T>(query, database, database.Count, algorithm));
 }
Beispiel #30
0
        /// <summary>
        /// Matches a query string against a database of strings stored in the
        /// specified file, using the specified algorithm, and returns the the top
        /// 'numMatches' number of closest-matching strings found.
        /// </summary>
        /// <typeparam name="T">the data type of the metric being used by the
        /// specified string similarity algorithm. If no algorithm is
        /// specified, this method will default to Levenshtein distance which
        /// uses an integer edit distance metric.
        /// </typeparam>
        /// <param name="query">the query string; the string to be matched</param>
        /// <param name="fileName">the name of the file containing the data
        /// set to be matched against
        /// </param>
        /// <param name="numMatches">the number of closest matches to be found
        /// </param>
        /// <param name="algorithm">the string algorithm to be used to do the
        /// matching
        /// </param>
        /// <returns>a List (as an IList) of the closest matches to the query
        /// string and the corresponding string similarity metric value, stored
        /// as (key, value) pairs with the matched string as the key and the
        /// metric as the value.
        /// </returns>
        public static IList <KeyValuePair <String, T> > FindClosestMatches <T>(String query, String fileName, int numMatches, StringAlgorithms algorithm = StringAlgorithms.LevenshteinDistance)
        {
            IList <KeyValuePair <String, T> > result = new List <KeyValuePair <String, T> > (numMatches);

            try
            {
                string line;
                using (StreamReader sr = new StreamReader(fileName))
                {
                    while ((line = sr.ReadLine()) != null)
                    {
                        result.Add(new KeyValuePair <String, T> (line, (T)algorithms[algorithm].DynamicInvoke(new Object[] { query, line })));
                    }
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
            }

            return(result);
        }