Ejemplo n.º 1
0
        public void DontMatchTileTwice()
        {
            CreateAlgorithm(
                GSTHelper.FromString("Hallo Welt!"),
                GSTHelper.FromString("Hallo Welt!ASDF Hallo Welt!"));

            Algorithm.RunToCompletion();

            Assert.AreEqual(1, Algorithm.Tiles.Count(), "matched a tile more than once");
        }
Ejemplo n.º 2
0
        public void DoNotMatchTwoIdenticalTilesOnA()
        {
            CreateAlgorithm(
                GSTHelper.FromString("Hallo Welt! Hallo Welt!"),
                GSTHelper.FromString("Hallo Welt!"));

            Algorithm.RunToCompletion();

            Assert.AreEqual(1, Algorithm.Tiles.Count());
        }
Ejemplo n.º 3
0
        public void DontBeCaseInsensitive()
        {
            CreateAlgorithm(
                GSTHelper.FromString("hallo welt! wie du mir gefällst!"),
                GSTHelper.FromString("Hallo Welt?ASDF Wie du mir gefällst_"));

            Algorithm.RunToCompletion();

            Assert.AreEqual(0, Algorithm.Tiles.Count(), "found UNEXPECTED match");
        }
Ejemplo n.º 4
0
        public void OverlappingMatchesOfSameSize()
        {
            CreateAlgorithm(
                GSTHelper.FromString("Hallo Welt!"),
                GSTHelper.FromString("allo Welt!|SEP|Hallo Welt"));

            Algorithm.RunToCompletion();

            Assert.AreEqual(1, Algorithm.Tiles.Count(), "too many tiles found");
        }
Ejemplo n.º 5
0
        public void SimilarityCalculation()
        {
            CreateAlgorithm(
                GSTHelper.FromString("Hallo Welt!\r\n\t Du bist Deutschland"),
                GSTHelper.FromString("*Bla\nBlub*Hallo Welt!\tAS\rDF Du bist Deutschland!"));

            Algorithm.RunToCompletion();

            Assert.AreEqual(91, Algorithm.Similarity, "similarity has unexpected value");
        }
Ejemplo n.º 6
0
        public void MinimizesHashes()
        {
            Algorithm = new HashingGSTAlgorithm <GSTToken <char> >(GSTHelper.FromString("XeLATst"), GSTHelper.FromString("LATunik"))
            {
                MinimumMatchLength = 3
            };
            Algorithm.DoOneRun();

            Assert.AreEqual(1, Algorithm.HashesA.Count, string.Format("expected 1 after minimize, but: A = {0}", Algorithm.HashesA.Count));
            Assert.AreEqual(1, Algorithm.HashesB.Count, string.Format("expected 1 after minimize, but: B = {0}", Algorithm.HashesB.Count));
        }
Ejemplo n.º 7
0
        public void SetUp()
        {
            abstractGSTAlgorithmTest = new AbstractGSTAlgorithmTest(typeof(GSTAlgorithm <GSTToken <char> >));
            var listA = GSTHelper.FromString("Hallo");
            var listB = GSTHelper.FromString("Hallo");

            Algorithm = new HashingGSTAlgorithm <GSTToken <char> >(listA, listB)
            {
                MinimumMatchLength = 3
            };
        }
Ejemplo n.º 8
0
        public void EqualsValue()
        {
            var tile1 = new Tile <GSTToken <char> >(GSTHelper.FromString("Hallo"), 1, 5);
            var tile2 = new Tile <GSTToken <char> >(GSTHelper.FromString("Hallo"), 1, 5);

            Assert.True(tile1.EqualsValue(tile2), "identical tiles do not match");

            tile2 = new Tile <GSTToken <char> >(GSTHelper.FromString("Hallo"), 1, 10);

            Assert.False(tile1.EqualsValue(tile2), "IndexOnB does not influence behaviour");
        }
Ejemplo n.º 9
0
        private void StartAlgorithm(object sender, RoutedEventArgs e)
        {
            Algorithm = new GSTAlgorithm <GSTToken <char> >(
                GSTHelper.FromString(TextABox.GetTextWithoutLineBreaks().Replace("\r\n", "AA")),
                GSTHelper.FromString(TextBBox.GetTextWithoutLineBreaks().Replace("\r\n", "AA")))
            {
                MinimumMatchLength = Int32.Parse(MMLTB.Text) - 1
            };

            //WriteToConsole(TextABox.GetTextWithoutLineBreaks());
            Reset();
        }
Ejemplo n.º 10
0
        public void EqualityComparerTest()
        {
            var dict1 = HashingGSTAlgorithm <GSTToken <char> > .CreateHashMap(GSTHelper.FromString("Hallo"), 3).ToArray();

            var dict2 = HashingGSTAlgorithm <GSTToken <char> > .CreateHashMap(GSTHelper.FromString("Hallo"), 3).ToArray();

            var comparer = HashingGSTAlgorithm <GSTToken <char> > .HashingEntity.Comparer;

            for (int i = 0; i < dict1.Length; i++)
            {
                Assert.AreEqual(dict1[i].Key, dict2[i].Key, string.Format("dict1 {0}, dict2 {1}", dict1[i].Value[0], dict2[i].Value[0]));
                Assert.IsTrue(comparer.Equals(dict1[i].Value[0], dict2[i].Value[0]));
            }
        }
Ejemplo n.º 11
0
        public void MatchesTwoDifferentTiles()
        {
            CreateAlgorithm(
                GSTHelper.FromString("Hallo Welt! Du bist Deutschland"),
                GSTHelper.FromString("*BlaBlub*Hallo Welt!ASDF Du bist Deutschland!"));

            Algorithm.RunToCompletion();

            Assert.AreEqual(2, Algorithm.Tiles.Count(), "unexpected number of matches");
            var listTiles = Algorithm.Tiles.ToList();

            Assert.True(" Du bist Deutschland".ToCharTile(11, 24).EqualsValue(listTiles[0]), "first tile does not match");
            Assert.True("Hallo Welt!".ToCharTile(0, 9).EqualsValue(listTiles[1]), "second tile does not match");
        }
Ejemplo n.º 12
0
        public void HandlesEscapeSequences()
        {
            CreateAlgorithm(
                GSTHelper.FromString("Hallo Welt!\r\n\t Du bist Deutschland"),
                GSTHelper.FromString("*Bla\nBlub*Hallo Welt!\tAS\rDF Du bist Deutschland!"));

            Algorithm.RunToCompletion();

            Assert.AreEqual(2, Algorithm.Tiles.Count(), "unexpected number of matches");
            var listTiles = Algorithm.Tiles.ToList();

            Assert.True(" Du bist Deutschland".ToCharTile(14, 27).EqualsValue(listTiles[0]), "first tile does not match");
            Assert.True("Hallo Welt!".ToCharTile(0, 10).EqualsValue(listTiles[1]), "second tile does not match");
        }
Ejemplo n.º 13
0
        public void TwoTilesInString()
        {
            CreateAlgorithm(GSTHelper.FromString("Hallo Welt! Wie du mir gefällst!"),
                            GSTHelper.FromString("Hallo Welt?ASDF Wie du mir gefällst_"));

            Algorithm.DoOneRun();

            Assert.AreEqual(1, Algorithm.Tiles.Count(), "no matching tiles found");

            var tile = Algorithm.Tiles.First();

            Assert.True(" Wie du mir gefällst".ToCharTile(11, 15).EqualsValue(tile));

            Algorithm.DoOneRun();
            Assert.AreEqual(2, Algorithm.Tiles.Count(), "too few tiles found");
        }
Ejemplo n.º 14
0
        private static void Calculate(int len)
        {
            var string1 = src1.Substring(0, len);
            var string2 = src2.Substring(0, len);
            //len += 200; // double length in size
            var watch = Stopwatch.StartNew();

            //Console.WriteLine("String length: A = {0}, B = {1}", string1.Length, string2.Length);
            for (int i = testRuns; i >= 0; i--)
            {
                var algo = new HashingGSTAlgorithm <GSTToken <char> >(
                    GSTHelper.FromString(string1),
                    GSTHelper.FromString(string2));

                algo.RunToCompletion();
                //Console.WriteLine("finished hashing run {0} in {1}", i, watch.Elapsed);
            }
            var runtimeHashing = watch.Elapsed;

            //Console.WriteLine("runtime hashing: {0}", ((int)runtimeHashing.TotalMilliseconds / testRuns));

            watch = Stopwatch.StartNew();

            for (int i = testRuns; i >= 0; i--)
            {
                var algo = new GSTAlgorithm <GSTToken <char> >(
                    GSTHelper.FromString(string1),
                    GSTHelper.FromString(string2));

                algo.RunToCompletion();
            }
            var ratio = (double)watch.ElapsedTicks / runtimeHashing.Ticks;

            Console.WriteLine("runtimes: {0}, {1}, ratio: {2} for {3}",
                              watch.ElapsedMilliseconds / testRuns,
                              runtimeHashing.TotalMilliseconds / testRuns,
                              ratio,
                              len);

            ResultList.Sort(String.CompareOrdinal);
            ResultList.Add(string.Format("{3:000};{0};{1};{2}",
                                         (watch.Elapsed.TotalMilliseconds / testRuns),
                                         (runtimeHashing.TotalMilliseconds / testRuns),
                                         ratio,
                                         len));
        }
Ejemplo n.º 15
0
        /// <summary>
        /// compares the two algorithms against each other over a rather large file (~8000 chars)
        /// </summary>
        private static void EvaluateSpeed()
        {
            XmlConfigurator.Configure(new FileInfo("log4net.xml"));
            src1 = File.ReadAllText(@"test\default_set\TPLV04-S01-02\main-01.c");
            src2 = File.ReadAllText(@"test\default_set\TPLV04-S01-02\main-02.c");
            var testRuns = 2;

            int len = 100;

            // JIT compile both algorithms before we start
            AbstractGSTAlgorithm <GSTToken <char> > initalgo = new HashingGSTAlgorithm <GSTToken <char> >(
                GSTHelper.FromString(src1.Substring(0, 100)),
                GSTHelper.FromString(src2.Substring(0, 100)));

            initalgo.RunToCompletion();

            initalgo = new GSTAlgorithm <GSTToken <char> >(GSTHelper.FromString(src1.Substring(0, 100)),
                                                           GSTHelper.FromString(src2.Substring(0, 100)));
            initalgo.RunToCompletion();

            var liLen1 = new List <int>();
            var liLen2 = new List <int>();
            var liLen3 = new List <int>();
            int c      = 0;

            while (len < src1.Length && len < src2.Length)
            {
                switch (c++ % 3)
                {
                case 0:
                    liLen1.Add(len);
                    break;

                case 1:
                    liLen2.Add(len);
                    break;

                default:
                    liLen3.Add(len);
                    break;
                }

                len += 100;
            }

            Length1 = liLen1.ToArray();
            Length2 = liLen2.ToArray();
            Length3 = liLen3.ToArray();

            var t1 = new Thread(Start1);

            t1.Start();

            var t2 = new Thread(Start2);

            t2.Start();

            var t3 = new Thread(Start3);

            t3.Start();


            Console.WriteLine("Main thread joining");
            t1.Join();
            t2.Join();
            t3.Join();

            File.WriteAllLines(@"test\default_set\performance.txt", ResultList);

            Console.WriteLine("finished all runs");
            Console.ReadLine();
        }
Ejemplo n.º 16
0
 public void SetUp()
 {
     ListA = GSTHelper.FromString("Hallo");
     ListB = GSTHelper.FromString("Hallo");
 }