public void MultipleSequencesMultipleKeyboards() { var sm = new SpatialMatcher(); var res = sm.MatchPassword("plko14569852pyfdb").ToList(); res.Count.Should().Be(6); }
public void SingleSequence() { var sm = new SpatialMatcher(); var res = sm.MatchPassword("qwert").ToList(); res.Count.Should().Be(1); res[0].i.Should().Be(0); res[0].j.Should().Be(4); res[0].Token.Should().Be("qwert"); }
public void SpatialMatcher() { var sm = new SpatialMatcher(); var res = sm.MatchPassword("qwert"); Assert.AreEqual(6, res.Count()); var m1 = res.First(); Assert.AreEqual("qwert", m1.Token); Assert.AreEqual(0, m1.Begin); Assert.AreEqual(4, m1.End); res = sm.MatchPassword("plko14569852pyfdb"); Assert.AreEqual(16, res.Count()); // Multiple matches from different keyboard types }
/** * rules for determining if a vehicle is on a break or is otherwise temporarily unavailable: * 1. any vehicle is off of its specified route * 2. any vehicle suddenly disconnects from syncromatics for more than several requests, but it was not at (or at least very close to) the final stop * 3. on routes a,c,d,e: * a. when a vehicle is stopped for excessive time on the east side of the marshall center * b. when a vehicle is stopped for excessive time on the northeast side of the library (leroy collins) [e mod only] * 4. on route b: * a. when a vehicle is stopped for excessive time on the east side of the marshall center * b. when a vehicle is stopped for excessive time at Continuing Education (NEC) * 5. on route f,g: * a. when a vehicle is stopped for excessive time on the northeast side of the library (leroy collins) * * dwell time is not considered here, although it is often that drivers will stop in these places to recover headway or for other reasons. * (in my own experience, drivers usually stop at the proper stop locations to recover headway, but the NEC (and actually all of B) might be a problem in particular) **/ public static bool IsOnBreak(VehicleState state, Route route) { bool isAtMSC = false; bool isAtLaurel = false; bool isAtBase = false; if (route.RouteStops.Count(x => x.StopID == 95569) == 0 && SpatialMatcher.IsAtLaurel(state)) { isAtLaurel = true; } if (route.RouteStops.Count(x => x.RTPI == 401) == 0 && SpatialMatcher.IsAtMSC(state)) { isAtMSC = true; } return(isAtMSC || isAtLaurel || isAtBase); }
/// <summary> /// /// </summary> /// <param name="vehicle"></param> /// <returns></returns> private async Task HandleExistingVehicle(SyncromaticsVehicle vehicle) { VehicleState state = VehicleStates[vehicle.ID]; if (state.GetLatestVehicleReport().Updated.Equals(vehicle.Updated)) { return; //we aren't interested in reports that haven't been updated } if (state.GetLatestVehicleReport().RouteID != vehicle.RouteID) { //if a vehicle changes routes, remove its state and restart Console.WriteLine("route not the same"); VehicleState removedState; VehicleStates.Remove(vehicle.ID, out removedState); return; } state.AddVehicleReport(vehicle); Route route = Routes[vehicle.RouteID]; state.CurrentStopPath = SpatialMatcher.PolygonMatch(state, route); if (state.CurrentStopPath == null) { Console.WriteLine("Cannot match to stop path!"); state.OnRoute = false; failedMatches++; } /* * else if (state.CurrentStopPath != null) * { * state.OnRoute = true; * * double headway = HeadwayGenerator.CalculateHeadwayDifference(VehicleStates.Values.ToList(), route, vehicle.ID); * bool isOnBreak = BreakGenerator.IsOnBreak(state, route); * } */ await AVLProcessing.GetWebsockets().SendVehicleUpdateAsync(new WebSockets.WSVehicleUpdateMsg(state, state.CurrentStopPath, route)); }
public void MatchesSpatialPatternSurroundedByNonSpatialPatterns() { var matcher = new SpatialMatcher(); var pattern = "6tfGHJ"; var password = $"rz!{pattern}%z"; var result = matcher.MatchPassword(password).OfType <SpatialMatch>().Where(m => m.Graph == "qwerty").ToList(); var expected = new[] { new SpatialMatch { Graph = "qwerty", Turns = 2, ShiftedCount = 3, i = 3, j = 3 + pattern.Length - 1, Token = pattern, }, }; result.Should().BeEquivalentTo(expected); }