public MathFunctionRoute(int partnerLabel, int outputPort, int outputLabel, int function, PartnerPacketWaiter partnerWaiter) { PartnerLabel = partnerLabel; OutputPort = outputPort; OutputLabel = outputLabel; PartnerWaiter = partnerWaiter; Function = function; }
public ProgramMathFunction(PartnerPacketWaiter waiter) { Waiter = waiter; }
public void MathFunction( [Range(0, 1)] int BUFER_ROUTE, [Range(2, 3)] int OUT_LABEL, [Range(3, 4)] int OUT_PORT, [Range(5, 6)] int FUNCTION, [Range(7, 8)] int IN_LABEL ) { var inputPacket = Mock.Of <IPacket>(); inputPacket.Label = (int)PacketStaticLabels.ProgramPacket; inputPacket.Data = new StructureCompressor() .PackHalf(FUNCTION) .PackHalf(OUT_LABEL) .PackHalf(OUT_PORT) .PackHalf(BUFER_ROUTE) .PackHalf(IN_LABEL) .PackHalf((int)ProgramRoutesId.MathFuncton) .Build(); var Core = Mock.Of <ICore>(); Core.OutPorts = Mock.Of <IOutPortBlock>(); Core.WaitedPackets = new HashSet <IPacket>(); Core.Router = Mock.Of <IRouter>(); var createdGenreal = false; IRoute generalRoute = null; var createdBuffer = false; var waiter = new PartnerPacketWaiter(); var routerTable = new Mock <IRouterTable>(); routerTable.Setup(t => t.AddRoute(IN_LABEL, It.IsAny <IRoute>())) .Callback((int label, IRoute p_route) => { createdGenreal = p_route is MathFunctionRoute rt && rt.PartnerLabel == BUFER_ROUTE && rt.OutputPort == OUT_PORT && rt.OutputLabel == OUT_LABEL && rt.Function == FUNCTION && rt.PartnerWaiter == waiter; generalRoute = p_route; }); routerTable.Setup(t => t.AddRoute(BUFER_ROUTE, It.IsAny <IRoute>())) .Callback((int label, IRoute p_route) => { createdBuffer = p_route is BufferRiseRoute rt && rt.PartnerWaiter == waiter && rt.PartnerLabel == IN_LABEL && rt.PartnerRoute == generalRoute; }); Core.Router.Table = routerTable.Object; var route = new ProgrammRoute(); route.RouteProgrammsBases.Add(ProgramRoutesId.MathFuncton, new ProgramMathFunction(waiter)); route.Route(inputPacket, Core); Assert.IsTrue(createdBuffer && createdGenreal); }