public void IsBranchFeatureInRoute() { var network = GetSnakeNetwork(false, new Point(0, 0), new Point(100, 0), new Point(200, 100)); var branch = network.Branches[0]; var networkLocation0 = new NetworkLocation(branch, 0); var networkLocation10 = new NetworkLocation(branch, 10); var networkLocation20 = new NetworkLocation(branch, 20); var networkLocation30 = new NetworkLocation(branch, 30); var networkLocation40 = new NetworkLocation(branch, 40); branch.BranchFeatures.Add(networkLocation0); branch.BranchFeatures.Add(networkLocation10); branch.BranchFeatures.Add(networkLocation20); branch.BranchFeatures.Add(networkLocation30); branch.BranchFeatures.Add(networkLocation40); var route = RouteHelper.CreateRoute( new[] { new NetworkLocation(branch, 5), new NetworkLocation(branch, 35) }); Assert.IsFalse(RouteHelper.IsBranchFeatureInRoute(route, networkLocation0)); Assert.IsTrue(RouteHelper.IsBranchFeatureInRoute(route, networkLocation10)); Assert.IsTrue(RouteHelper.IsBranchFeatureInRoute(route, networkLocation20)); Assert.IsTrue(RouteHelper.IsBranchFeatureInRoute(route, networkLocation30)); Assert.IsFalse(RouteHelper.IsBranchFeatureInRoute(route, networkLocation40)); }
public void GetSegmentForNetworkLocationTest() { var network = CreateThreeNodesNetwork(); // new Point(0, 0), new Point(100, 0), new Point(300, 0) var branch0T100 = (Branch)network.Branches[0]; var branch100T300 = (Branch)network.Branches[1]; var route = RouteHelper.CreateRoute(new[] { new NetworkLocation(branch0T100, 20.0), new NetworkLocation(branch0T100, 80.0), new NetworkLocation(branch100T300, 20.0) }); Assert.AreEqual(3, route.Segments.Values.Count); INetworkSegment networkSegment; networkSegment = RouteHelper.GetSegmentForNetworkLocation(route, new NetworkLocation(branch0T100, 10)); Assert.IsNull(networkSegment); networkSegment = RouteHelper.GetSegmentForNetworkLocation(route, new NetworkLocation(branch0T100, 50)); Assert.AreEqual(networkSegment, route.Segments.Values[0]); networkSegment = RouteHelper.GetSegmentForNetworkLocation(route, new NetworkLocation(branch0T100, 90)); Assert.AreEqual(networkSegment, route.Segments.Values[1]); networkSegment = RouteHelper.GetSegmentForNetworkLocation(route, new NetworkLocation(branch100T300, 10)); Assert.AreEqual(networkSegment, route.Segments.Values[2]); networkSegment = RouteHelper.GetSegmentForNetworkLocation(route, new NetworkLocation(branch100T300, 30)); Assert.IsNull(networkSegment); }
public void GetLocationsForAnotherRoute() { var network = CreateThreeNodesNetwork(); var branch = (Branch)network.Branches[0]; var source = new NetworkCoverage { Network = network }; source[new NetworkLocation(branch, 10.0)] = 10.0; source[new NetworkLocation(branch, 50.0)] = 30.0; source[new NetworkLocation(branch, 60.0)] = 20.0; source[new NetworkLocation(branch, 80.0)] = 10.0; //90-->0-->80 var route = RouteHelper.CreateRoute(new[] { new NetworkLocation(branch, 90.0) , new NetworkLocation(branch, 0.0), new NetworkLocation(branch, 80) }); var expectedLocations = new[] { new NetworkLocation(branch, 90.0) , new NetworkLocation(branch, 80.0) , new NetworkLocation(branch, 60.0) , new NetworkLocation(branch, 50.0) , new NetworkLocation(branch, 10.0) , new NetworkLocation(branch, 0) , new NetworkLocation(branch, 10.0) , new NetworkLocation(branch, 50.0) , new NetworkLocation(branch, 60.0) , new NetworkLocation(branch, 80.0) }; var actualLocations = RouteHelper.GetLocationsInRoute(source, route); Assert.AreEqual(expectedLocations, actualLocations); }
public void CheckRouteChainages() { var network = GetSnakeNetwork(false, new Point(0, 0), new Point(100, 0), new Point(200, 100)); var branch = network.Branches[0]; var networkLocation0 = new NetworkLocation(branch, 0); var networkLocation10 = new NetworkLocation(branch, 10); var networkLocation20 = new NetworkLocation(branch, 20); var networkLocation30 = new NetworkLocation(branch, 30); var networkLocation40 = new NetworkLocation(branch, 40); branch.BranchFeatures.Add(networkLocation0); branch.BranchFeatures.Add(networkLocation10); branch.BranchFeatures.Add(networkLocation20); branch.BranchFeatures.Add(networkLocation30); branch.BranchFeatures.Add(networkLocation40); var route = RouteHelper.CreateRoute(new[] { new NetworkLocation(branch, 5), new NetworkLocation(branch, 35) }); var route2 = RouteHelper.CreateRoute(new[] { new NetworkLocation(branch, 35), new NetworkLocation(branch, 5) }); Assert.AreEqual(-1, RouteHelper.GetRouteChainage(route, networkLocation0)); Assert.AreEqual(5, RouteHelper.GetRouteChainage(route, networkLocation10)); Assert.AreEqual(15, RouteHelper.GetRouteChainage(route, networkLocation20)); Assert.AreEqual(25, RouteHelper.GetRouteChainage(route, networkLocation30)); Assert.AreEqual(-1, RouteHelper.GetRouteChainage(route, networkLocation40)); Assert.AreEqual(-1, RouteHelper.GetRouteChainage(route2, networkLocation0)); Assert.AreEqual(25, RouteHelper.GetRouteChainage(route2, networkLocation10)); Assert.AreEqual(15, RouteHelper.GetRouteChainage(route2, networkLocation20)); Assert.AreEqual(5, RouteHelper.GetRouteChainage(route2, networkLocation30)); Assert.AreEqual(-1, RouteHelper.GetRouteChainage(route2, networkLocation40)); }
public static bool CreateRoute(NetRoute o) { #if DEBUG_TUN Log.Verbose("CreateRoute {InterNetwork} {Address} {Cidr} {Gateway} {Interface} {Metric}", AddressFamily.InterNetwork, o.Network, o.Cidr, o.Gateway, (ulong)o.InterfaceIndex, o.Metric); #endif return(RouteHelper.CreateRoute(AddressFamily.InterNetwork, o.Network, o.Cidr, o.Gateway, (ulong)o.InterfaceIndex, o.Metric)); }
public void CreateSegments() { var network = GetSnakeNetwork(false, new Point(0, 0), new Point(100, 0), new Point(200, 100)); //; var network = GetNetwork(); var branch1 = network.Branches[0]; var routeCoverage = RouteHelper.CreateRoute( new[] { new NetworkLocation(branch1, 0), new NetworkLocation(branch1, 50), new NetworkLocation(branch1, 10) }); Assert.AreEqual(2, routeCoverage.Segments.Values.Count); Assert.AreEqual(0, routeCoverage.Segments.Values[0].Chainage); Assert.AreEqual(50, routeCoverage.Segments.Values[0].EndChainage); Assert.AreEqual(50, routeCoverage.Segments.Values[1].Chainage); Assert.AreEqual(10, routeCoverage.Segments.Values[1].EndChainage); }