Ejemplo n.º 1
0
        public void SutWillReturnCorrectIndexForMunich()
        {
            // Fixture setup.
            String pattern = "Munich";
            String[] names = new String[] { "B Munich", "B-Munich", "B Munich I", "B Munich-I", "B.Munich-I" };
            BoyerMoore sut = new BoyerMoore(pattern);

            foreach (String name in names)
            {
                // Exercise system.
                foreach (Int32 index in sut.ApostolicoGiancarloMatch(name))
                {
                    // Verify outcome.
                    Assert.Equal(2, index); 
					break;
                }

                // Exercise system.
                foreach (Int32 index in sut.BclMatch(name))
                {
                    // Verify outcome.
                    Assert.Equal(2, index); 
					break;
                }

                // Exercise system.
                foreach (Int32 index in sut.BoyerMooreMatch(name))
                {
                    // Verify outcome.
                    Assert.Equal(2, index);
					break;
                }

                // Exercise system.
                foreach (Int32 index in sut.HorspoolMatch(name))
                {
                    // Verify outcome.
                    Assert.Equal(2, index); 
					break;
                }

                // Exercise system.
                foreach (Int32 index in sut.TurboBoyerMooreMatch(name))
                {
                    // Verify outcome.
                    Assert.Equal(2, index);
					break;
                }
            }

            // Teardown.
        }
Ejemplo n.º 2
0
		public static Boolean Matches(String source, String target)
		{
            if (String.IsNullOrWhiteSpace(source))
            {
                throw new ArgumentNullException("source");
            }

            if (String.IsNullOrWhiteSpace(target))
            {
                throw new ArgumentNullException("target");
            }

			Boolean found = false;

			foreach (String pattern in source.Split(' '))
			{
                if (s_ignoredItems.Contains(pattern.ToUpperInvariant()))
                {
                    continue;
                }

				BoyerMoore matcher = new BoyerMoore(pattern);

				foreach (String actual in target.Split(' '))
				{
					if (matcher.TurboBoyerMooreMatch(actual).Count() > 0)
					{
						found = true;
					}
					else
					{
						Int32 dist = LevenshteinDistance.Compute(pattern, actual);
						if (dist == 1 && (pattern.Length == actual.Length))
						{
							found = true;
						}
						else if (dist <= pattern.Length - actual.Length)
						{
							found = true;
						}
						else
						{
							found = false;
						}
					}
				}
			}

			return found;
		}
Ejemplo n.º 3
0
        public void SutWillReturnZeroIndex()
        {
            // Fixture setup.
            String pattern = "123";
            String[] names = new String[] { "B Munich", "B-Munich", "B Munich I", "B Munich-I", "B.Munich-I" };
            BoyerMoore sut = new BoyerMoore(pattern);

            // Exercise system and verify outcome.
            foreach (String name in names)
            {
                Assert.Equal(0, sut.ApostolicoGiancarloMatch(name).Count());
                Assert.Equal(0, sut.BclMatch(name).Count());
                Assert.Equal(0, sut.BoyerMooreMatch(name).Count());
                Assert.Equal(0, sut.HorspoolMatch(name).Count());
                Assert.Equal(0, sut.TurboBoyerMooreMatch(name).Count());
            }

            // Teardown.
        }