コード例 #1
0
        /// <summary>
        /// Tests that multiple calls to AddPath yield correct state machine.
        /// </summary>
        /// <param name="paths">The paths.</param>
        /// <param name="expectedEntryState">Expected state of the entry.</param>
        public void TestAddPaths(ITransition[][] paths, State expectedEntryState)
        {
            var builder = new StateMachineBuilder();

            foreach (var path in paths)
            {
                builder.AddPath(path);
            }

            var result = builder.GetStateMachine();

            var expectedMachine = new StateMachine(expectedEntryState);

            Assert.IsTrue(new StateMachineEqualityComparer().Equals(expectedMachine, result));
        }
コード例 #2
0
        public void GetStateMachine_ForkingPath_CollectsAllStatesAndTransitions()
        {
            SimpleTransition commonTransition, forkedTransition1, forkedTransition2;

            var paths = new[]
            {
                new[]
                {
                    commonTransition = new SimpleTransition
                    {
                        GlyphId   = 1,
                        HeadShift = 1,
                        Action    = new SubstitutionAction
                        {
                            ReplacedGlyphCount  = 1,
                            ReplacementGlyphIds = new ushort[] { 1 }
                        }
                    },
                    forkedTransition1 = new SimpleTransition
                    {
                        GlyphId   = 2,
                        HeadShift = 2,
                        Action    = new SubstitutionAction
                        {
                            ReplacedGlyphCount  = 2,
                            ReplacementGlyphIds = new ushort[] { 2 }
                        }
                    }
                },
                new[]
                {
                    new SimpleTransition
                    {
                        GlyphId   = 1,
                        HeadShift = 1,
                        Action    = new SubstitutionAction
                        {
                            ReplacedGlyphCount  = 1,
                            ReplacementGlyphIds = new ushort[] { 1 }
                        }
                    },
                    forkedTransition2 = new SimpleTransition {
                        GlyphId   = 3,
                        HeadShift = 3,
                        Action    = new SubstitutionAction
                        {
                            ReplacedGlyphCount  = 3,
                            ReplacementGlyphIds = new ushort[] { 3 }
                        }
                    }
                }
            };

            var builder = new StateMachineBuilder();

            foreach (var path in paths)
            {
                builder.AddPath(path);
            }

            var result = builder.GetStateMachine();

            Assert.AreEqual(result.States.Count, 4);
            Assert.IsTrue(
                new[] { commonTransition, forkedTransition1, forkedTransition2 }.ValuesEqual(result.Transitions, new TransitionNonrecursiveEqualityComparer()));
        }