public void ShouldReturnEmptyRegexForEmptyButValidRegexInput() { // arrange string input = "^$"; // act IRegex result = Parser.Parse(input); // assert Assert.AreEqual(string.Empty, result.GetLongestNonCyclicWord()); }
public void ShouldReturnValueForComplexBranches() { // arrange const string expected = "WSSEESWWWNWNENNEEEENNESSSSWNWSW"; string input = $"^WSSEESWWWNW(S|NENNEEEENN(ESSSSW(NWSW|SSEN)|WSWWN(E|WWS(E|SS))))$"; // act IRegex result = Parser.Parse(input); // assert Assert.AreEqual(expected, result.GetLongestNonCyclicWord()); }
public void ShouldReturnValueForOneBranch() { // arrange const string expected = "SNTRE"; string input = $"^SN(E|TRE)$"; // act IRegex result = Parser.Parse(input); // assert Assert.AreEqual(expected, result.GetLongestNonCyclicWord()); }
public void ShouldReturnResultForThreeCharacterInput() { // arrange const string expecteResult = "SNW"; string input = $"^{expecteResult}$"; // act IRegex result = Parser.Parse(input); // assert Assert.AreEqual(expecteResult, result.GetLongestNonCyclicWord()); }
public void ShouldReturnValueForComplexBranchesWithOptional() { // arrange const string expected = "ESSWWNNNENNWWWSSSSENNNE"; string input = $"^ESSWWN(E|NNENN(EESS(WNSE|)SSS|WWWSSSSE(SW|NNNE)))$"; // act IRegex result = Parser.Parse(input); // assert Assert.AreEqual(expected, result.GetLongestNonCyclicWord()); }
static void Main(string[] args) { string filename = args[0]; string input = File.ReadAllText(filename); IRegex regex = Parser.Parse(input); Console.WriteLine($"Part1: {regex.GetLongestNonCyclicWord().Length}"); HashSet <string> validPaths = new HashSet <string>(); HashSet <string> allPaths = regex.GetNonCyclicWords().ToHashSet(); foreach (var path in allPaths) { for (int i = 1000; i <= path.Length; i++) { validPaths.Add(path.Substring(0, i)); } } Console.WriteLine(validPaths.Count()); Console.WriteLine(validPaths.Select(GetRoomCoordinates).ToHashSet().Count()); }