예제 #1
0
        /// <summary>
        /// Compiles a collection of transformation tables into a state machine.
        /// </summary>
        /// <param name="transformations">The transformations.</param>
        /// <returns>
        /// Compiled state machine.
        /// </returns>
        public StateMachine Compile(IEnumerable <IGlyphTransformationTable> transformations)
        {
            var builder = new StateMachineBuilder();

            foreach (var transformation in transformations)
            {
                this.CompileTransformation(transformation, builder);
            }

            return(builder.GetStateMachine());
        }
        /// <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));
        }
        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()));
        }