public void NoMatch() { Regex2 regex = new Regex2("xyz", AlgorithmType); Match2 match = regex.Match("Something or other"); Assert.AreEqual(Match2.Empty, match); }
public void OneMatch() { Regex2 regex = new Regex2("thing", AlgorithmType); Match2 match = regex.Match("Something or other"); Assert.AreEqual(Factory.CreateMatch(4, 5, "thing"), match); }
public static void NextMatchTest() { const int n1 = 5000, n2 = 5300, n3 = 5500, n4 = 7000; Counter counter = new Counter(); MatchCollection2 coll = Factory.CreateMatchCollection(getMatches(n1, counter)); Assert.AreEqual(0, counter.Value); for (Match2 match = coll.First(); match.Index < n2; match = match.NextMatch()) { ; } Assert.AreEqual(n2 - n1 + 1, counter.Value); for (Match2 match = coll.First(); match.Index < n3; match = match.NextMatch()) { ; } Assert.AreEqual(n3 - n1 + 1, counter.Value); for (Match2 match = coll.First(); match.Index < n4; match = match.NextMatch()) { ; } Assert.AreEqual(n4 - n1 + 1, counter.Value); for (Match2 match = coll.First(); match.Index < n2; match = match.NextMatch()) { ; } Assert.AreEqual(n4 - n1 + 1, counter.Value); }
public void TwoMatches() { Regex2 regex = new Regex2("thing", AlgorithmType); Match2[] matches = regex.Matches("A thing or another thing").ToArray(); Match2[] expected = new Match2[] { Factory.CreateMatch(2, 5, "thing"), Factory.CreateMatch(19, 5, "thing") }; CollectionAssert.AreEqual(expected, matches, "MatchCollection"); Assert.AreEqual(matches[1], matches[0].NextMatch(), "NextMatch/1."); Assert.AreEqual(Match2.Empty, matches[1].NextMatch(), "NextMatch/2."); Assert.AreEqual(Match2.Empty, matches[1].NextMatch().NextMatch(), "NextMatch/3."); }
public async Task RecentMatches_ReturnNotMoreThanCountEntries() { await StatisticStorage.UpdateMatch(Match1.GetIndex(), Match1.InitPlayers(Match1.EndTime)); await StatisticStorage.UpdateMatch(Match2.GetIndex(), Match2.InitPlayers(Match2.EndTime)); await WaitForTasks(); var response = await Module.ProcessRequest(CreateRequest("", "/reports/recent-matches/1")); var expected = new[] { new { server = Match1.HostServer.Id, timestamp = Match1.EndTime, results = Match1 }, new { server = Match2.HostServer.Id, timestamp = Match2.EndTime, results = Match2 }, }.OrderByDescending(m => m.timestamp).Take(1).ToArray(); response.Response.Should().Be(new JsonHttpResponse(HttpStatusCode.OK, expected)); }
public async Task PopularServers_ReturnMostPopularServer() { await StatisticStorage.UpdateServer(Server1.GetIndex(), Server1); await StatisticStorage.UpdateServer(Server2.GetIndex(), Server2); await StatisticStorage.UpdateMatch(Match2.GetIndex(), Match2.InitPlayers(Match2.EndTime)); await WaitForTasks(); var response = await Module.ProcessRequest(CreateRequest("", "/reports/popular-servers/1")); response.Response.Should().Be(new JsonHttpResponse(HttpStatusCode.OK, new[] { new { endpoint = Server2.Id, name = Server2.Name, averageMatchesPerDay = 1.0, } })); }
public void MatchOverlap() { Match2[] matches = new Regex2("thing", AlgorithmType).Matches("Some thinthing or another").ToArray(); Match2[] expected = new Match2[] { Factory.CreateMatch(9, 5, "thing") }; CollectionAssert.AreEqual(expected, matches, "False overlap."); matches = new Regex2("alfa", AlgorithmType).Matches("This is alfalfa").ToArray(); expected = new Match2[] { Factory.CreateMatch(8, 4, "alfa") }; CollectionAssert.AreEqual(expected, matches, "Real overlap."); matches = new Regex2("alfa", AlgorithmType).Matches("This is alfalfalfa").ToArray(); expected = new Match2[] { Factory.CreateMatch(8, 4, "alfa"), Factory.CreateMatch(14, 4, "alfa") }; CollectionAssert.AreEqual(expected, matches, "Double overlap."); }