private void Btn_AddContainer_Click(object sender, EventArgs e) { Enum.TryParse(Cbbx_ContainerType.SelectedValue.ToString(), out ContainerType status); int weight = (int)Nud_ContainerWeight.Value; if (status == ContainerType.Regular) { Container newContainer = new Container(weight); _dock.AllContainers.Add(newContainer); Lbx_Containers.Items.Add(newContainer); } else if (status == ContainerType.Valuable) { ValuableContainer newContainer = new ValuableContainer(weight); _dock.AllContainers.Add(newContainer); Lbx_Containers.Items.Add(newContainer); } else if (status == ContainerType.Cooled) { CooledContainer newContainer = new CooledContainer(weight); _dock.AllContainers.Add(newContainer); Lbx_Containers.Items.Add(newContainer); } UpdateContainerStats(); }
public bool CreateContainer(int index, int weight, TypeContainer type) { if (weight > 30 || weight < 4) { Program.PrintError("The Weight of The Container cant be more than 30 and less than 4"); return(false); } if (type == TypeContainer.Default_Container) { var newContainer = new DefaultContainer(index, weight); containersList.Add(newContainer); return(true); } else if (type == TypeContainer.Cooled_Container) { var newContainer = new CooledContainer(index, weight); containersList.Add(newContainer); return(true); } else if (type == TypeContainer.Valuable_Container) { var newContainer = new ValuableContainer(index, weight); containersList.Add(newContainer); return(true); } else if (type == TypeContainer.RefrigeratedValuable_Container) { var newContainer = new ValuableCooledContainer(index, weight); containersList.Add(newContainer); return(true); } return(false); }
public void Test_Place_Valuable_On_CooledAndValuable() { //In this test method we will test if we can place a valuable container on top of cooled & valuable container CooledAndValuable container1 = new CooledAndValuable(250); ValuableContainer container2 = new ValuableContainer(250); bool bcontainer1 = false; bool bcontainer2 = false; //Act we place the cooledvalueble first. if (stack.CanAddContainer(container1)) { stack.AddContainerToStack(container1); bcontainer1 = true; } if (stack.CanAddContainer(container2)) { stack.AddContainerToStack(container2); bcontainer2 = true; } //Assert Assert.AreEqual(true, bcontainer1); Assert.AreEqual(false, bcontainer2); }
public void Test_Place_TwoValuableContainers_To_Stack() { //Arrange //First we need a container stack and 2 valuable containers. The weight doesn't matter, you can only place //1 valuable container on a stack. ValuableContainer container1 = new ValuableContainer(250); ValuableContainer container2 = new ValuableContainer(250); bool bcontainer1 = false; bool bcontainer2 = false; //Act if (stack.CanAddContainer(container1)) { stack.AddContainerToStack(container1); bcontainer1 = true; } if (stack.CanAddContainer(container2)) { stack.AddContainerToStack(container2); bcontainer2 = true; } //Assert //The first bool should be true, the second false. Assert.AreEqual(true, bcontainer1); Assert.AreEqual(false, bcontainer2); }
public void ValuableContainers_placement() { //in this test I will test if the containers are placed on the first and last row only! To test this we will need 4 containers and 3 rows. List <ValuableContainer> listContainer = new List <ValuableContainer>(); ValuableContainer container1 = new ValuableContainer(250); ValuableContainer container2 = new ValuableContainer(250); ValuableContainer container3 = new ValuableContainer(250); ValuableContainer container4 = new ValuableContainer(250); ship.width = 2; ship.length = 3; balanceAlgorithme.SetShip(ship); listContainer.Add(container1); listContainer.Add(container2); listContainer.Add(container3); listContainer.Add(container4); balanceAlgorithme.vList = listContainer; //act balanceAlgorithme.FillShip(); //Assert Assert.AreEqual(250, ship.rows[0].Stacks[0].weight); Assert.AreEqual(250, ship.rows[0].Stacks[1].weight); Assert.AreEqual(0, ship.rows[1].Stacks[0].weight); Assert.AreEqual(0, ship.rows[1].Stacks[1].weight); Assert.AreEqual(250, ship.rows[2].Stacks[0].weight); Assert.AreEqual(250, ship.rows[2].Stacks[1].weight); }
public void CantStackOnTopOfValuable() { // Arange ValuableContainer valContainer1 = new ValuableContainer(30); //Container regContainer = new Container(); //use this one to see if regulars CAN be added Stack stack = new Stack(0, 0, BalansPosition.Left); // Act stack.AddContainer(valContainer1); bool canIStackOnTopValuable = stack.CanContainerBeAddedToStack();; // Assert Assert.IsFalse(canIStackOnTopValuable); }
public void TryPlaceContainer_ShouldNotLoadTwoValuables() { // Arrange int expected = 1; Stack stack = new Stack(true, true); IContainer val1 = new ValuableContainer(); IContainer val2 = new ValuableContainer(); stack.TryPlaceContainer(val1); // Act stack.TryPlaceContainer(val2); int result = stack.Containers.Count; Assert.Equal(expected, result); }
public void TryPlaceContainer_ShouldMoveValuableToTop() { // Arrange Stack stack = new Stack(true, true); IContainer valContainer = new ValuableContainer(); IContainer coolContainer = new CoolContainer(); IContainer normalContainer = new NormalContainer(); // Act stack.TryPlaceContainer(valContainer); stack.TryPlaceContainer(coolContainer); stack.TryPlaceContainer(normalContainer); // Assert Assert.Equal(valContainer, stack.Containers[2]); }