Пример #1
0
        public void TestMergeWithNullConditionReturnValid()
        {
            var automata1 = new GeneNode()
            {
                NodeName         = "a1",
                CurrentCondition = new Condition()
                {
                    { "B", true }, { "C", true }
                },                                                                   // here A is missing
                Transitions = new List <GeneTransition>()
                {
                    new GeneTransition()
                    {
                        Node = new GeneNode()
                        {
                            NodeName         = "b1",
                            CurrentCondition = new Condition()
                            {
                                { "A", false }, { "B", false }, { "C", false }
                            },
                        }
                    }
                }
            };


            var automata2 = new GeneNode()
            {
                NodeName         = "a2",
                CurrentCondition = new Condition()
                {
                    { "A", true }, { "B", true }
                },                                                                   // Here C is missing
                Transitions = new List <GeneTransition>()
                {
                    new GeneTransition()
                    {
                        Node = new GeneNode()
                        {
                            NodeName         = "b2",
                            CurrentCondition = new Condition()
                            {
                                { "A", false }, { "B", false }, { "C", false }
                            },
                        }
                    }
                }
            };

            var mergeLogic = new AutomataMergeLogic();
            var res        = mergeLogic.GetMerges(automata1, automata2);

            Assert.AreEqual(1, res.Count);
            Assert.AreEqual(res.First().CurrentCondition["A"], true);
            Assert.AreEqual(res.First().CurrentCondition["B"], true);
            Assert.AreEqual(res.First().CurrentCondition["C"], true);
        }
Пример #2
0
        public void TestMergeWithSameConditionReturnMerged()
        {
            var automata1 = new GeneNode()
            {
                NodeName         = "a1",
                CurrentCondition = new Condition()
                {
                    { "A", true }, { "B", true }, { "C", true }
                },
                Transitions = new List <GeneTransition>()
                {
                    new GeneTransition()
                    {
                        Node = new GeneNode()
                        {
                            NodeName         = "b1",
                            CurrentCondition = new Condition()
                            {
                                { "A", false }, { "B", false }, { "C", false }
                            },
                        }
                    }
                }
            };


            var automata2 = new GeneNode()
            {
                NodeName         = "a2",
                CurrentCondition = new Condition()
                {
                    { "A", true }, { "B", true }, { "C", true }
                },
                Transitions = new List <GeneTransition>()
                {
                    new GeneTransition()
                    {
                        Node = new GeneNode()
                        {
                            NodeName         = "b2",
                            CurrentCondition = new Condition()
                            {
                                { "A", false }, { "B", false }, { "C", false }
                            },
                        }
                    }
                }
            };

            var mergeLogic = new AutomataMergeLogic();
            var res        = mergeLogic.GetMerges(automata1, automata2);

            Assert.AreEqual(1, res.Count);
        }
Пример #3
0
        public void TestPrefixLength()
        {
            var automata1 = new GeneNode()
            {
                NodeName         = "a1",
                CurrentCondition = new Condition()
                {
                    { "A", false }, { "B", false }, { "C", false }
                },
                Transitions = new List <GeneTransition>()
                {
                    new GeneTransition()
                    {
                        Node = new GeneNode()
                        {
                            NodeName         = "b1",
                            CurrentCondition = new Condition()
                            {
                                { "A", true }, { "B", true }, { "C", true }
                            },
                            Transitions = new List <GeneTransition>()
                            {
                                new GeneTransition()
                                {
                                    Node = new GeneNode()
                                    {
                                        NodeName = "c1"
                                    }
                                }
                            }
                        }
                    }
                }
            };

            // a2 is prefix, because only b2 will be matched
            var automata2 = new GeneNode()
            {
                NodeName         = "a2",
                CurrentCondition = new Condition()
                {
                    { "A", false }, { "B", true }, { "C", true }
                },
                Transitions = new List <GeneTransition>()
                {
                    new GeneTransition()
                    {
                        Node = new GeneNode()
                        {
                            NodeName         = "b2",
                            CurrentCondition = new Condition()
                            {
                                { "A", false }, { "B", false }, { "C", false }
                            },
                            Transitions = new List <GeneTransition>()
                            {
                                new GeneTransition()
                                {
                                    Node = new GeneNode()
                                    {
                                        NodeName = "c2"
                                    }
                                }
                            }
                        }
                    }
                }
            };

            var mergeLogic = new AutomataMergeLogic();
            var res        = mergeLogic.GetMerges(automata1, automata2);

            // length should be 4
            // a2 => b2@a1 => b1 => c1

            Assert.AreEqual(1, res.Count);
            var builder = new StringBuilder();

            res.First().AppendPath(builder);
            logger.Info(builder.ToString());
            Assert.AreEqual(4, res.First().NodeLength);
        }
Пример #4
0
        public void TestMergeWhenAutomata2CanBeMergedFromAutomata1Child()
        {
            var automata1 = new GeneNode()
            {
                NodeName         = "a1",
                CurrentCondition = new Condition()
                {
                    { "A", true }, { "B", true }, { "C", true }
                },
                Transitions = new List <GeneTransition>()
                {
                    new GeneTransition()
                    {
                        Node = new GeneNode()
                        {
                            NodeName         = "b1",
                            CurrentCondition = new Condition()
                            {
                                { "A", false }, { "B", false }, { "C", false }
                            },
                            Transitions = new List <GeneTransition>()
                            {
                                new GeneTransition()
                                {
                                    Node = new GeneNode()
                                    {
                                        NodeName = "c1"
                                    }
                                }
                            }
                        }
                    }
                }
            };


            var automata2 = new GeneNode()
            {
                NodeName         = "a2",
                CurrentCondition = new Condition()
                {
                    { "A", false }, { "B", false }, { "C", false }
                },
                Transitions = new List <GeneTransition>()
                {
                    new GeneTransition()
                    {
                        Node = new GeneNode()
                        {
                            NodeName         = "b2",
                            CurrentCondition = new Condition()
                            {
                                { "A", false }, { "B", true }, { "C", true }
                            },
                            Transitions = new List <GeneTransition>()
                            {
                                new GeneTransition()
                                {
                                    Node = new GeneNode()
                                    {
                                        NodeName = "c2"
                                    }
                                }
                            }
                        }
                    }
                }
            };

            var mergeLogic = new AutomataMergeLogic();
            var res        = mergeLogic.GetMerges(automata1, automata2);

            Assert.AreEqual(1, res.Count);
            Assert.AreEqual(4, res.First().NodeLength);
        }