public void TestBackReference()
 {
     var regex = new Regex(@"(...?)\1*");
       var str = CharSetString.Parse("OREOR[EO][OR][OR][ER]ORE");
       Assert.IsTrue(regex.AddConstraints(str));
       Assert.AreEqual("OREOREOREORE", str.ToString());
 }
Ejemplo n.º 2
0
 public void TestAddConstraints3()
 {
     var regex = new Regex("(A|BC|DEF)(GHI|JK|L)");
       var str = CharSetString.UnconstrainedStringOfLength(4);
       Assert.IsTrue(regex.AddConstraints(str));
       Assert.AreEqual("[ABD][CEG][FHJ][IKL]", str.ToString());
 }
Ejemplo n.º 3
0
 public void TestAddConstraints1()
 {
     var regex = new Regex("X*");
       var str = CharSetString.UnconstrainedStringOfLength(7);
       Assert.IsTrue(regex.AddConstraints(str));
       Assert.AreEqual("XXXXXXX", str.ToString());
 }
        public void TestLaterMatchesConstrainEarlierMatches()
        {
            var reg = new Regex("(.)\\1");
              var str = CharSetString.Parse(".A");
              reg.AddConstraints(str);

              Assert.AreEqual(
            @"AA",
            str.ToString());
        }
        public void TestInnerMatchesOfDifferentLengths()
        {
            var reg = new Regex("(AAA|B)+");
              var rrm = (RegexRepetitionModifier)reg.Atoms[0];

              var possMatches = rrm.GeneratePossibleMatches(0, CharSetString.UnconstrainedStringOfLength(4));
              Assert.AreEqual(
            @"AAAB
            BAAA
            BBBB",
             String.Join("\r\n", possMatches));
        }
        public void TestRegexParseToStringRoundTrip()
        {
            var mitMysteryHunt2013Clues = new []
                                      {
                                        ".*H.*H.*",
                                        "(DI|NS|TH|OM)*",
                                        "F.*[AO].*[AO].*",
                                        "(O|RHH|MM)*",
                                        ".*",
                                        "C*MC(CCC|MM)*",
                                        "[^C]*[^R]*III.*",
                                        "(...?)\\1*",
                                        "([^X]|XCC)*",
                                        "(RR|HHH)*.?",
                                        "N.*X.X.X.*E",
                                        "R*D*M*",
                                        ".(C|HH)*",
                                        ".*SE.*UE.*",
                                        ".*LR.*RL.*",
                                        ".*OXR.*",
                                        "([^CEM]|EM)*",
                                        "(HHX|[^HX])*",
                                        ".*PRR.*DDC.*",
                                        ".*",
                                        "[AM]*CM(RC)*R?",
                                        "([^CM]|MM|CC)*",
                                        "(E|CR|MN)*",
                                        "P+(..)\\1.*",
                                        "[CHMNOR]*I[CHMNOR]*",
                                        "(ND|ET|IN)[^X]*",
                                        ".*G.*V.*H.*",
                                        "[CR]*",
                                        ".*XEXM*",
                                        ".*DD.*CCM.*",
                                        ".*XHCR.*X.*",
                                        ".*(.)(.)(.)(.)\\4\\3\\2\\1.*",
                                        ".*(IN|SE|HI)",
                                        "[^C]*MMM[^C]*",
                                        ".*(.)C\\1X\\1.*",
                                        "[CEIMU]*OH[AEMOR]*",
                                        "(RX|[^R])*",
                                        "[^M]*M[^M]*",
                                        "(S|MM|HHH)*"
                                      };

              foreach (var regexStr in mitMysteryHunt2013Clues)
              {
            var regex = new Regex(regexStr);
            Assert.AreEqual(regexStr, regex.ToString());
              }
        }
        public void TestBackReferences2()
        {
            var regex = new Regex(@"(...?)\1*");
              var str = CharSetString.Parse("ABC...");
              Assert.IsTrue(regex.AddConstraints(str));
              Assert.AreEqual("ABCABC", str.ToString());

              str = CharSetString.Parse("AB....");
              Assert.IsTrue(regex.AddConstraints(str));
              Assert.AreEqual("AB.[AB][AB].", str.ToString());

              str = CharSetString.Parse("ABA...");
              Assert.IsTrue(regex.AddConstraints(str));
              Assert.AreEqual("ABA[AB][AB][AB]", str.ToString());
        }
        public void TestBackReferences1()
        {
            var regex = new Regex(@"(ABC)\1");
              var str = CharSetString.Parse("ABC...");
              Assert.IsTrue(regex.AddConstraints(str));
              Assert.AreEqual("ABCABC", str.ToString());

              str = CharSetString.Parse("ABCA..");
              Assert.IsTrue(regex.AddConstraints(str));
              Assert.AreEqual("ABCABC", str.ToString());

              str = CharSetString.Parse("ABCB..");
              ExceptionAssert.AssertThrows<CharSet.EmptyIntersectionException>(() =>
            regex.AddConstraints(str));
        }
Ejemplo n.º 9
0
        public void TestAddConstraints4()
        {
            var regex = new Regex("X+Y+Z+");
              var str = CharSetString.UnconstrainedStringOfLength(5);
              Assert.IsTrue(regex.AddConstraints(str));
              Assert.AreEqual("X[XY][XYZ][YZ]Z", str.ToString());

              str = CharSetString.Parse("...X..");
              Assert.IsTrue(regex.AddConstraints(str));
              Assert.AreEqual("XXXXYZ", str.ToString());

              str = CharSetString.Parse("..Z..");
              Assert.IsTrue(regex.AddConstraints(str));
              Assert.AreEqual("XYZZZ", str.ToString());
        }
Ejemplo n.º 10
0
        public void TestAddConstraints2()
        {
            var regex = new Regex("X*YX*");
              var str = CharSetString.UnconstrainedStringOfLength(7);
              Assert.IsTrue(regex.AddConstraints(str));
              Assert.AreEqual("[XY][XY][XY][XY][XY][XY][XY]", str.ToString());

              str = CharSetString.Parse("..Y....");
              Assert.IsTrue(regex.AddConstraints(str));
              Assert.AreEqual("XXYXXXX", str.ToString());

              str = CharSetString.Parse("..Y");
              Assert.IsTrue(regex.AddConstraints(str));
              Assert.AreEqual("XXY", str.ToString());
        }
Ejemplo n.º 11
0
        public void TestAddConstraints5()
        {
            var regex = new Regex("(DI|NS|TH|OM)*");

              var strOneChoice = CharSetString.Parse("[DNT][HI]");
              Assert.IsTrue(regex.AddConstraints(strOneChoice));
              Assert.AreEqual("[DT][HI]", strOneChoice.ToString());

              var strSecondChoice = CharSetString.Parse("[^C][CEMN]");
              Assert.IsTrue(regex.AddConstraints(strSecondChoice));
              Assert.AreEqual("OM", strSecondChoice.ToString());

              var strTwoChoices = CharSetString.Parse("[DNT][HI][^C][CEMN]");
              Assert.IsTrue(regex.AddConstraints(strTwoChoices));
              Assert.AreEqual("[DT][HI]OM", strTwoChoices.ToString());

              var str = CharSetString.Parse("[DNT][HI][^C][CEMN][AEHMOR][AM].[HMS]");
              Assert.IsTrue(regex.AddConstraints(str));
              Assert.AreEqual("[DT][HI]OMOM[NOT][HMS]", str.ToString());
        }
        public void TestBackReferences3()
        {
            var regex = new Regex(@".*(.)(.)(.)(.)\4\3\2\1.*");
              var str = CharSetString.Parse("ABCD....");
              Assert.IsTrue(regex.AddConstraints(str));
              Assert.AreEqual("ABCDDCBA", str.ToString());

              str = CharSetString.Parse("....DCBA");
              Assert.IsTrue(regex.AddConstraints(str));
              Assert.AreEqual("ABCDDCBA", str.ToString());

              // This is an interesting one: with close inspection we can see here that the match
              // must be: ABCDECBAE.
              str = CharSetString.Parse("ABCDE...ABC..");
              Assert.IsTrue(regex.AddConstraints(str));
              Assert.AreEqual("ABCDECBAABCE.", str.ToString());

              // Not enough info here to deduce anything
              str = CharSetString.Parse("..ABCD......");
              Assert.IsFalse(regex.AddConstraints(str));
              Assert.AreEqual("..ABCD......", str.ToString());
        }
        /// <param name="clues">
        ///  The clues as a 3xN grid
        /// </param>
        public HexRegexCrossword(Regex[,] clues)
        {
            if (3 != clues.GetUpperBound(0) + 1 || 0 != clues.GetLowerBound(0)
              || 0 != clues.GetLowerBound(1))
              {
            throw new ArgumentException("The clue array must be 3 X rowCount");
              }
              Clues = clues;

              RowCount = clues.GetUpperBound(1) + 1;
              SideLength = (RowCount + 1)/2;
              GridRows = new CharSetString[3, RowCount];
              // Build up a grid of cells by Q/R.
              // The max coord will be < +/- sideLength
              // Since coords may be negative, this array is offset by +sideLength
              _cellsByQROffsetBySideLength = new CharSet[2 * SideLength, 2 * SideLength];

              for (int axis = 0; axis < 3; axis++)
              {
            for (int idx = -(SideLength - 1); idx <= (SideLength - 1); idx++)
            {
              var row = new List<CharSet>();
              for (int offset = 0;; offset++)
              {
            var qr = AxisIdxOffsetToQR(axis, idx, offset);
            var cell = GetCellByQR(qr);
            if (cell == null) // qr is out of range
            {
              break;
            }
            row.Add(cell);
              }
              GridRows[axis, idx + (SideLength - 1)] = new CharSetString(row);
            }
              }
        }
        public void TestMultipleBackReferences()
        {
            var regex = new Regex(@"(.)C\1X\1");
              var str = CharSetString.Parse(".C.X.");
              Assert.IsFalse(regex.AddConstraints(str));

              str = CharSetString.Parse(".C.X[AB]");
              Assert.IsTrue(regex.AddConstraints(str));
              Assert.AreEqual("[AB]C[AB]X[AB]", str.ToString());

              str = CharSetString.Parse(".C[AB]X.");
              Assert.IsTrue(regex.AddConstraints(str));
              Assert.AreEqual("[AB]C[AB]X[AB]", str.ToString());

              str = CharSetString.Parse(".C[AB]XB");
              Assert.IsTrue(regex.AddConstraints(str));
              Assert.AreEqual("BCBXB", str.ToString());
        }
Ejemplo n.º 15
0
        public void TestOrConstraint()
        {
            var regex = new Regex("(ND|ET|IN)[^X]*");
              var str = CharSetString.UnconstrainedStringOfLength(7);
              Assert.IsTrue(regex.AddConstraints(str));

              Assert.AreEqual("[EIN][DNT][^X][^X][^X][^X][^X]", str.ToString());
        }