Exemple #1
0
        public void GivenItemWithRoute_WhenTargetFull_ShouldNotRouteSingleItem()
        {
            ModuleB.LimitItemCount = 1;
            ModuleB.Entities.PlatformItems.Add(new PlatformItem {
                ItemId = 99
            });
            var item = new PlatformItem {
                ItemId = 1
            };

            item.Route = new Route
            {
                RouteItems = new Collection <RouteItem>
                {
                    new RouteItem {
                        ModuleType = 1
                    },
                    new RouteItem {
                        ModuleType = 2
                    },
                }
            };

            ModuleA.TestCurrentItemRoutings.Should().HaveCount(0, "must not route because target port is full");

            ModuleA.SimulateItemDetected(item);

            ModuleA.TestCurrentItemRoutings.Should().HaveCount(0, "must not route because target port is still full");
        }
Exemple #2
0
        public void GivenItemWithRoute_WhenReleased_ShouldRouteAndUpdateIndex()
        {
            var item = new PlatformItem();

            item.Route = new Route
            {
                RouteItems = new Collection <RouteItem>
                {
                    new RouteItem {
                        ModuleType = 1
                    },
                    new RouteItem {
                        ModuleType = 3
                    },
                    new RouteItem {
                        ModuleType = 4
                    }
                }
            };
            ModuleA.Entities.PlatformItems.Add(item);

            ModuleA.SimulateItemReleased(item, 1);

            item.Route.CurrentIndex.Should().Be(1);
            ModuleC.Entities.PlatformItems.Should().Contain(item);
            ModuleC.TestCurrentItemRoutings.Should().HaveCount(1);
            ModuleA.Entities.PlatformItems.Should().HaveCount(0);

            ModuleC.SimulateItemReleased(item, 0);

            ModuleC.Entities.PlatformItems.Should().HaveCount(0);
            ModuleD.Entities.PlatformItems.Should().HaveCount(1);
        }
Exemple #3
0
        public void GivenItemWithRoute_WhenTargetPortFull_ShouldNotRouteSingleItem()
        {
            ModuleB.SimulateIsFull(0);
            var item = new PlatformItem();

            item.Route = new Route
            {
                RouteItems = new Collection <RouteItem>
                {
                    new RouteItem {
                        ModuleType = 1
                    },
                    new RouteItem {
                        ModuleType = 2
                    },
                }
            };

            ModuleA.SimulateNewItemCreated(item);

            ModuleA.TestCurrentItemRoutings.Should().HaveCount(0, "must not route because target port is full");

            ModuleA.SimulateItemDetected(item);

            ModuleA.TestCurrentItemRoutings.Should().HaveCount(0, "must not route because target port is still full");
        }
Exemple #4
0
        public void GivenItemWithRoute_WhenDetectedPingPong_ShouldRouteAndUpdateIndex()
        {
            var item = new PlatformItem();

            item.Route = new Route
            {
                RouteItems = new Collection <RouteItem>
                {
                    new RouteItem {
                        ModuleType = 1
                    },
                    new RouteItem {
                        ModuleType = 2
                    },
                    new RouteItem {
                        ModuleType = 1
                    }
                }
            };

            ModuleA.SimulateNewItemCreated(item);
            item.Route.CurrentIndex.Should().Be(0);
            ModuleA.TestCurrentItemRoutings.Should().ContainValue(0, "port 0 is the path to ModuleB which is next in the route");

            ModuleB.SimulateItemDetected(item);
            item.Route.CurrentIndex.Should().Be(1);
            ModuleA.TestCurrentItemRoutings.Should().HaveCount(0, "old routing task is fulfilled");
            ModuleB.TestCurrentItemRoutings.Should().ContainValue(0, "port 0 is the path to ModuleA");

            ModuleA.SimulateItemDetected(item);
            item.Route.CurrentIndex.Should().Be(2);
            ModuleB.TestCurrentItemRoutings.Should().HaveCount(0, "old routing task is fulfilled");
            ModuleA.TestCurrentItemRoutings.Should().HaveCount(0, "item has no more route items");
        }
Exemple #5
0
    // Start is called before the first frame update
    void Start()
    {
        var moduleA = new ModuleA();

        moduleA.Log();

        var moduleB = new ModuleB();

        moduleB.Say("Hey");
    }
Exemple #6
0
        public void GivenItemCreatedInModuleA_WhenDetectedInModuleB_ShouldMoveItem()
        {
            var item = new PlatformItem();

            ModuleA.SimulateNewItemCreated(item);

            ModuleB.SimulateItemDetected(item);

            ModuleA.Entities.PlatformItems.Count.Should().Be(0, "item is now in ModuleB and cannot exist in ModuleA at the same time");
            ModuleB.Entities.PlatformItems.Contains(item).Should().BeTrue("item was detected in ModuleB");
        }
Exemple #7
0
        public void WhenReleaseItem_ShouldBeInNextModule()
        {
            var item = new PlatformItem();

            ModuleA.Entities.PlatformItems.Add(item);

            ModuleA.SimulateItemReleased(item, 0);

            ModuleB.Entities.PlatformItems.Should().Contain(item, "item should be in ModuleB because it comes next");
            ModuleA.Entities.PlatformItems.Should().HaveCount(0, "item has been released");
        }
Exemple #8
0
        public void GivenModuleFullAndRouteAll_WhenNotFullAnymore_ShouldRouteAll()
        {
            var item = new PlatformItem();

            ModuleB.LimitItemCount = 1;
            ModuleB.Entities.PlatformItems.Add(item);
            ModuleBusManager.ForcePath(ModuleA, ModuleB, 0, 0);

            ModuleA.SimulateItemDetected(item);

            ModuleA.TestCurrentAllPortRoutings.Should().HaveCount(1);
        }
Exemple #9
0
        public void GivenItemInModule_WhenDetectedAgain_NothingHappens()
        {
            var item = new PlatformItem();

            ModuleA.Entities.PlatformItems.Add(item);
            ModuleA.MonitorEvents();

            // simulate a circulating buffer within ModuleA, where items detected multiple times
            ModuleA.SimulateItemDetected(item);
            ModuleA.SimulateItemDetected(item);

            ModuleA.Entities.PlatformItems.Count.Should().Be(1, "only one item is in ModuleA even if detected multiple times");
            ModuleA.ShouldNotRaise("CurrentItemCountChangedEvent");
        }
Exemple #10
0
        public void GivenItemAlreadyCreated_WhenDetectCreatedAgain_ShouldLogWarnAndRemoveOldItem()
        {
            var item = new PlatformItem {
                Id = 1, ItemId = 1
            };

            ModuleA.SimulateNewItemCreated(item);

            ModuleB.SimulateNewItemCreated(new PlatformItem {
                ItemId = 1
            });

            Logger.Verify(l => l.Warn(It.IsAny <string>()), Times.AtLeastOnce);
            ModuleA.Entities.PlatformItems.Should().HaveCount(0);
            ModuleB.Entities.PlatformItems.Should().HaveCount(1);
        }
Exemple #11
0
        public void GivenItemAlreadyCreated_WhenDetectedAgain_ShouldMoveShirt()
        {
            var item = new PlatformItem {
                ItemId = 1
            };

            ModuleA.SimulateNewItemCreated(item);

            ModuleB.SimulateItemDetected(new PlatformItem {
                ItemId = 1
            });

            ModuleA.Entities.PlatformItems.Should().HaveCount(0);
            ModuleB.ContainsItem(item.ItemId).Should().BeTrue();
            ModuleB.Entities.PlatformItems.First().Should().BeSameAs(item);
        }
Exemple #12
0
        public void GivenItemWithRouteAndAlreadyCreated_WhenDetected_ShouldUpdateRoute()
        {
            var item = new PlatformItem {
                ItemId = 1
            };

            item.Route = CreateRoute();
            ModuleA.SimulateNewItemCreated(item);

            ModuleB.SimulateItemDetected(item);

            var route = ModuleB.Entities.PlatformItems.First().Route;

            route.Should().NotBeNull();
            route.CurrentIndex.Should().Be(1);
        }
        public void FacadeInjection()
        {
            // Arrange
            var dependency    = new ModuleA();
            var depend        = new ModuleADependend();
            var moduleManager = CreateObjectUnderTest(new IServerModule[]
            {
                dependency,
                depend
            });

            // Act
            moduleManager.Initialize();

            // Assert
            Assert.NotNull(depend.Dependency, "Facade not injected correctly");
        }
Exemple #14
0
        public void GivenItemWithRoute_GivenFull_WhenNotFullAnymore_ShouldRouteSingleItem()
        {
            var item = new PlatformItem {
                ItemId = 1
            };

            item.Route = CreateRoute();
            ModuleB.SimulateIsFull(0);
            ModuleA.SimulateNewItemCreated(item);
            ModuleA.SimulateItemDetected(item);

            ModuleA.TestCurrentItemRoutings.Should().BeEmpty();
            ModuleB.SimulateIsNotFull(0);
            ModuleA.SimulateItemDetected(item);

            ModuleA.TestCurrentItemRoutings.Should().HaveCount(1);
        }
Exemple #15
0
        public void GivenItemWithRoute_WhenDetectedInWrongModule_ShouldNotUpdateIndexAndRouteBack()
        {
            var item = new PlatformItem();

            item.Route = new Route
            {
                RouteItems = new Collection <RouteItem>
                {
                    new RouteItem {
                        ModuleType = 1
                    },
                    new RouteItem {
                        ModuleType = 3
                    },                                // ModuleC
                }
            };

            ModuleA.SimulateNewItemCreated(item);
            ModuleB.SimulateItemDetected(item);    // item detected in wrong module!

            ModuleB.TestCurrentItemRoutings.Should().ContainValue(0, "item was detected in wrong module and should go back to ModuleA");
            item.Route.CurrentIndex.Should().Be(0, "item has still to visit ModuleC");
        }
 private Ship AddModules(Ship ship, string[] modules)
 {
     foreach (string module in modules)
     {
         if (module == "A")
         {
             ship = new ModuleA(ship);
         }
         if (module == "B")
         {
             ship = new ModuleB(ship);
         }
         if (module == "C")
         {
             ship = new ModuleC(ship);
         }
         if (module == "D")
         {
             ship = new ModuleD(ship);
         }
     }
     return(ship);
 }
Exemple #17
0
        public override double GetValue(double x, double y, double z)
        {
            if (ModuleA == null)
            {
                throw new InvalidOperationException("ModuleA cannot be null");
            }
            if (ModuleB == null)
            {
                throw new InvalidOperationException("ModuleB cannot be null");
            }
            if (ControlModule == null)
            {
                throw new InvalidOperationException("Control cannot be null");
            }

            double controlValue = ControlModule.GetValue(x, y, z);

            if (edgeFalloff > 0.0)
            {
                if (controlValue < (LowerBound - edgeFalloff))
                {
                    // The output value from the control module is below the selector
                    // threshold; return the output value from the first source module.
                    return(ModuleA.GetValue(x, y, z));
                }
                double alpha;
                if (controlValue < (LowerBound + edgeFalloff))
                {
                    // The output value from the control module is near the lower end of the
                    // selector threshold and within the smooth curve. Interpolate between
                    // the output values from the first and second source modules.
                    double lowerCurve = (LowerBound - edgeFalloff);
                    double upperCurve = (LowerBound + edgeFalloff);
                    alpha = NoiseMath.SCurve3((controlValue - lowerCurve) / (upperCurve - lowerCurve));
                    return(NoiseMath.LinearInterpolate(ModuleA.GetValue(x, y, z), ModuleB.GetValue(x, y, z), alpha));
                }
                if (controlValue < (UpperBound - edgeFalloff))
                {
                    // The output value from the control module is within the selector
                    // threshold; return the output value from the second source module.
                    return(ModuleB.GetValue(x, y, z));
                }
                if (controlValue < (UpperBound + edgeFalloff))
                {
                    // The output value from the control module is near the upper end of the
                    // selector threshold and within the smooth curve. Interpolate between
                    // the output values from the first and second source modules.
                    double lowerCurve = (UpperBound - edgeFalloff);
                    double upperCurve = (UpperBound + edgeFalloff);
                    alpha = NoiseMath.SCurve3((controlValue - lowerCurve) / (upperCurve - lowerCurve));
                    return(NoiseMath.LinearInterpolate(ModuleB.GetValue(x, y, z), ModuleA.GetValue(x, y, z), alpha));
                }
                // Output value from the control module is above the selector threshold;
                // return the output value from the first source module.
                return(ModuleA.GetValue(x, y, z));
            }
            if (controlValue < LowerBound || controlValue > UpperBound)
            {
                return(ModuleA.GetValue(x, y, z));
            }
            return(ModuleB.GetValue(x, y, z));
        }
Exemple #18
0
        public void WhenNewItemCreated_ShouldAddItemToModule()
        {
            ModuleA.SimulateNewItemCreated(new PlatformItem());

            ModuleA.Entities.PlatformItems.Count.Should().Be(1);
        }