コード例 #1
0
        public void DoStepForward3()
        {
            var automaton = new AutomatonBubbleSort(new[] { -1});

            var state = automaton.DoStepForward();

            while (state.StateId != (int)AutomatonBubbleSort.States.FinalState)
            {
                state = automaton.DoStepForward();
            }

            Assert.IsTrue(ArrayEquals(new[] { -1}, state.Array));
        }
コード例 #2
0
        public void DoStepForward4()
        {
            var automaton = new AutomatonBubbleSort(new[] { -1, 2, 0 });

            var state = automaton.DoStepForward();

            Assert.AreEqual((int)AutomatonBubbleSort.States.Condition, state.StateId);
            Assert.IsTrue(ArrayEquals(new[] { -1, 2, 0 }, state.Array));
            Assert.IsTrue(ArrayEquals(new [ ] {0, 1 }, state.SelectedElements.ToArray()));

            state = automaton.DoStepForward();

            Assert.AreEqual((int) AutomatonBubbleSort.States.Condition, state.StateId);
            Assert.IsTrue(ArrayEquals(new[] { -1, 2, 0 }, state.Array));
            Assert.IsTrue(ArrayEquals(new[] { 1, 2 }, state.SelectedElements.ToArray()));

            state = automaton.DoStepForward();

            Assert.AreEqual((int)AutomatonBubbleSort.States.SwappingAdjacentElements, state.StateId);
            Assert.IsTrue(ArrayEquals(new[] { -1, 0, 2 }, state.Array));
            Assert.IsTrue(ArrayEquals(new[] { 1, 2 }, state.SelectedElements.ToArray()));

            state = automaton.DoStepForward();

            Assert.AreEqual((int)AutomatonBubbleSort.States.Condition, state.StateId);
            Assert.IsTrue(ArrayEquals(new[] { -1, 0, 2 }, state.Array));
            Assert.IsTrue(ArrayEquals(new[] { 0, 1 }, state.SelectedElements.ToArray()));
            state = automaton.DoStepForward();

            Assert.AreEqual((int)AutomatonBubbleSort.States.Condition, state.StateId);
            Assert.IsTrue(ArrayEquals(new[] { -1, 0, 2 }, state.Array));
            Assert.IsTrue(ArrayEquals(new[] { 1, 2 }, state.SelectedElements.ToArray()));
            
            state = automaton.DoStepForward();

            while (state.StateId != (int) AutomatonBubbleSort.States.FinalState)
            {
                Assert.AreEqual((int)AutomatonBubbleSort.States.Condition, state.StateId);
                state = automaton.DoStepForward();
            }

            automaton.DoStepForward();
            Assert.AreEqual((int)AutomatonBubbleSort.States.FinalState, state.StateId);

            automaton.DoStepForward();
            Assert.AreEqual((int)AutomatonBubbleSort.States.FinalState, state.StateId);
            Assert.IsTrue(ArrayEquals(new[] { -1, 0, 2 }, state.Array));
        }