public void UngroupPath_SimplePathWithBackTransitions_UngroupsThePath()
        {
            State state1 = new State(), state2;

            state1.Transitions.Add(new AlwaysTransition {
                TargetState = state1
            });
            var path = new ITransition[]
            {
                new SimpleTransition
                {
                    HeadShift = 1,
                    GlyphId   = 1,
                    Action    = new SubstitutionAction {
                        ReplacedGlyphCount = 1
                    },
                    LookupFlags = LookupFlags.IgnoreBaseGlyphs,
                    TargetState = state1
                },
                new SetTransition
                {
                    HeadShift  = 2,
                    GlyphIdSet = new HashSet <ushort> {
                        21, 22, 23
                    },
                    Action = new SubstitutionAction {
                        ReplacedGlyphCount = 2
                    },
                    LookupFlags = LookupFlags.IgnoreBaseGlyphs,
                    TargetState = state2 = new State(),
                },
                new AlwaysTransition
                {
                    HeadShift = 3,
                    Action    = new SubstitutionAction {
                        ReplacedGlyphCount = 3
                    },
                    LookupFlags = LookupFlags.IgnoreBaseGlyphs,
                    TargetState = new State {
                        Transitions = new ITransition[] { new AlwaysTransition {
                                                              TargetState = state2
                                                          } }
                    }
                }
            };

            var builder = new StateMachineBuilder();
            var result  = builder.UngroupPath(path).ToList();

            var expectedPaths = new IEnumerable <ITransition>[]
            {
                new ITransition[]
                {
                    new SimpleTransition
                    {
                        HeadShift = 1,
                        GlyphId   = 1,
                        Action    = new SubstitutionAction {
                            ReplacedGlyphCount = 1
                        },
                        LookupFlags = LookupFlags.IgnoreBaseGlyphs
                    },
                    new SimpleTransition
                    {
                        HeadShift = 2,
                        GlyphId   = 21,
                        Action    = new SubstitutionAction {
                            ReplacedGlyphCount = 2
                        },
                        LookupFlags = LookupFlags.IgnoreBaseGlyphs
                    },
                    new AlwaysTransition
                    {
                        HeadShift = 3,
                        Action    = new SubstitutionAction {
                            ReplacedGlyphCount = 3
                        },
                        LookupFlags = LookupFlags.IgnoreBaseGlyphs
                    }
                },
                new ITransition[]
                {
                    new SimpleTransition
                    {
                        HeadShift = 1,
                        GlyphId   = 1,
                        Action    = new SubstitutionAction {
                            ReplacedGlyphCount = 1
                        },
                        LookupFlags = LookupFlags.IgnoreBaseGlyphs
                    },
                    new SimpleTransition
                    {
                        HeadShift = 2,
                        GlyphId   = 22,
                        Action    = new SubstitutionAction {
                            ReplacedGlyphCount = 2
                        },
                        LookupFlags = LookupFlags.IgnoreBaseGlyphs
                    },
                    new AlwaysTransition
                    {
                        HeadShift = 3,
                        Action    = new SubstitutionAction {
                            ReplacedGlyphCount = 3
                        },
                        LookupFlags = LookupFlags.IgnoreBaseGlyphs
                    }
                },
                new ITransition[]
                {
                    new SimpleTransition
                    {
                        HeadShift = 1,
                        GlyphId   = 1,
                        Action    = new SubstitutionAction {
                            ReplacedGlyphCount = 1
                        },
                        LookupFlags = LookupFlags.IgnoreBaseGlyphs
                    },
                    new SimpleTransition
                    {
                        HeadShift = 2,
                        GlyphId   = 23,
                        Action    = new SubstitutionAction {
                            ReplacedGlyphCount = 2
                        },
                        LookupFlags = LookupFlags.IgnoreBaseGlyphs
                    },
                    new AlwaysTransition
                    {
                        HeadShift = 3,
                        Action    = new SubstitutionAction {
                            ReplacedGlyphCount = 3
                        },
                        LookupFlags = LookupFlags.IgnoreBaseGlyphs
                    }
                }
            };

            var comparer = new PathEqualityComparer();

            Assert.IsTrue(comparer.Equals(expectedPaths[0], result[0]));
            Assert.IsTrue(comparer.Equals(expectedPaths[1], result[1]));
            Assert.IsTrue(comparer.Equals(expectedPaths[2], result[2]));
            Assert.AreEqual(expectedPaths.Length, result.Count);

            Assert.AreSame(result[0].First().TargetState.Transitions.First().TargetState, result[0].First().TargetState);
            Assert.AreSame(result[2].ElementAt(2).TargetState.Transitions.First().TargetState, result[2].ElementAt(1).TargetState);
        }
        public void UngroupPath_SimplePath_UngroupsThePath()
        {
            var path = new ITransition[]
            {
                new SimpleTransition
                {
                    HeadShift = 1,
                    GlyphId   = 1,
                    Action    = new SubstitutionAction {
                        ReplacedGlyphCount = 1
                    },
                    LookupFlags = LookupFlags.IgnoreBaseGlyphs
                },
                new SetTransition
                {
                    HeadShift  = 2,
                    GlyphIdSet = new HashSet <ushort> {
                        21, 22, 23
                    },
                    Action = new SubstitutionAction {
                        ReplacedGlyphCount = 2
                    },
                    LookupFlags = LookupFlags.IgnoreBaseGlyphs
                },
                new AlwaysTransition
                {
                    HeadShift = 3,
                    Action    = new SubstitutionAction {
                        ReplacedGlyphCount = 3
                    },
                    LookupFlags = LookupFlags.IgnoreBaseGlyphs
                }
            };

            var builder = new StateMachineBuilder();
            var result  = builder.UngroupPath(path).ToList();

            var expectedPaths = new IEnumerable <ITransition>[]
            {
                new ITransition[]
                {
                    new SimpleTransition
                    {
                        HeadShift = 1,
                        GlyphId   = 1,
                        Action    = new SubstitutionAction {
                            ReplacedGlyphCount = 1
                        },
                        LookupFlags = LookupFlags.IgnoreBaseGlyphs
                    },
                    new SimpleTransition
                    {
                        HeadShift = 2,
                        GlyphId   = 21,
                        Action    = new SubstitutionAction {
                            ReplacedGlyphCount = 2
                        },
                        LookupFlags = LookupFlags.IgnoreBaseGlyphs
                    },
                    new AlwaysTransition
                    {
                        HeadShift = 3,
                        Action    = new SubstitutionAction {
                            ReplacedGlyphCount = 3
                        },
                        LookupFlags = LookupFlags.IgnoreBaseGlyphs
                    }
                },
                new ITransition[]
                {
                    new SimpleTransition
                    {
                        HeadShift = 1,
                        GlyphId   = 1,
                        Action    = new SubstitutionAction {
                            ReplacedGlyphCount = 1
                        },
                        LookupFlags = LookupFlags.IgnoreBaseGlyphs
                    },
                    new SimpleTransition
                    {
                        HeadShift = 2,
                        GlyphId   = 22,
                        Action    = new SubstitutionAction {
                            ReplacedGlyphCount = 2
                        },
                        LookupFlags = LookupFlags.IgnoreBaseGlyphs
                    },
                    new AlwaysTransition
                    {
                        HeadShift = 3,
                        Action    = new SubstitutionAction {
                            ReplacedGlyphCount = 3
                        },
                        LookupFlags = LookupFlags.IgnoreBaseGlyphs
                    }
                },
                new ITransition[]
                {
                    new SimpleTransition
                    {
                        HeadShift = 1,
                        GlyphId   = 1,
                        Action    = new SubstitutionAction {
                            ReplacedGlyphCount = 1
                        },
                        LookupFlags = LookupFlags.IgnoreBaseGlyphs
                    },
                    new SimpleTransition
                    {
                        HeadShift = 2,
                        GlyphId   = 23,
                        Action    = new SubstitutionAction {
                            ReplacedGlyphCount = 2
                        },
                        LookupFlags = LookupFlags.IgnoreBaseGlyphs
                    },
                    new AlwaysTransition
                    {
                        HeadShift = 3,
                        Action    = new SubstitutionAction {
                            ReplacedGlyphCount = 3
                        },
                        LookupFlags = LookupFlags.IgnoreBaseGlyphs
                    }
                }
            };

            var comparer = new PathEqualityComparer();

            Assert.IsTrue(comparer.Equals(expectedPaths[0], result[0]));
            Assert.IsTrue(comparer.Equals(expectedPaths[1], result[1]));
            Assert.IsTrue(comparer.Equals(expectedPaths[2], result[2]));
            Assert.AreEqual(expectedPaths.Length, result.Count);
        }