예제 #1
0
        public void Equals_TwoIdenticalStates_AreEqual()
        {
            var floor10 = Floor.HydrogenChip | Floor.HydrogenGenerator;
            var floor11 = Floor.LithiumChip | Floor.LithiumGenerator;
            var state1  = new FloorState(1, new List <Floor> {
                floor10, floor11
            });

            var floor20 = Floor.HydrogenChip | Floor.HydrogenGenerator;
            var floor21 = Floor.LithiumChip | Floor.LithiumGenerator;
            var state2  = new FloorState(1, new List <Floor> {
                floor20, floor21
            });

            Assert.Equal(state1, state2);
        }
예제 #2
0
        protected bool Equals(FloorState other)
        {
            if (ElevatorFloor != other.ElevatorFloor)
            {
                return(false);
            }

            for (int i = 0; i < Floors.Count; i++)
            {
                if (Floors[i] != other.Floors[i])
                {
                    return(false);
                }
            }

            return(true);
        }
예제 #3
0
        public void GetHashCode_TwoIdenticalStates_SameHashCode()
        {
            var floor10 = Floor.HydrogenChip | Floor.HydrogenGenerator;
            var floor11 = Floor.LithiumChip | Floor.LithiumGenerator;
            var state1  = new FloorState(1, new List <Floor> {
                floor10, floor11
            });

            var floor20 = Floor.HydrogenChip | Floor.HydrogenGenerator;
            var floor21 = Floor.LithiumChip | Floor.LithiumGenerator;
            var state2  = new FloorState(1, new List <Floor> {
                floor20, floor21
            });

            var hashCode1 = state1.GetHashCode();
            var hashCode2 = state2.GetHashCode();

            Assert.Equal(hashCode1, hashCode2);
        }
예제 #4
0
        public void Next_WhenSafeGeneratorChipCombinationExists_ReturnsNewStates()
        {
            var floor0 = Floor.HydrogenChip | Floor.LithiumChip;
            var floor1 = Floor.HydrogenGenerator;

            var state = new FloorState(0, new List <Floor> {
                floor0, floor1
            });

            var expectedFloor0 = Floor.LithiumChip;
            var expectedFloor1 = Floor.HydrogenChip | Floor.HydrogenGenerator;

            var expectedState = new FloorState(1, new List <Floor> {
                expectedFloor0, expectedFloor1
            }, 1);

            var nextStates = state.Next();

            Assert.Single(nextStates, expectedState);
        }