public void ShouldBuildSequenceSegment() { SituationGraphSegmentFactory <char> factory; ISituationGraph <char> graph; LexicalRule rule; MockedSituationEdge capEdge; ISituationGraphSegment <char> segment; capEdge = new MockedSituationEdge(); graph = new SituationGraph <char>(); factory = new SituationGraphSegmentFactory <char>(); rule = new LexicalRule(); rule.Predicate = new Sequence(new Terminal('a'), new Terminal('b'), new Terminal('c')); segment = factory.BuildSegment(graph, rule, rule.Predicate, capEdge.AsEnumerable()); Assert.AreEqual(3, graph.Nodes.Count()); Assert.AreEqual(1, segment.InputEdges.Count()); Assert.AreEqual(1, segment.OutputNodes.Count()); Assert.AreEqual(1, segment.OutputNodes.ElementAt(0).Edges.Count()); Assert.IsTrue(segment.InputEdges.ElementAt(0).Predicate.GetInputs().First().Match('a')); Assert.AreEqual(1, graph.Nodes.ElementAt(0).Edges.Count()); Assert.AreEqual(1, graph.Nodes.ElementAt(1).Edges.Count()); Assert.AreEqual(1, graph.Nodes.ElementAt(2).Edges.Count()); Assert.AreEqual(capEdge, segment.OutputNodes.ElementAt(0).Edges.ElementAt(0)); }
public void ShouldNotBuildOneOrMoreSegment() { SituationGraphSegmentFactory <char> factory; ISituationGraph <char> graph; LexicalRule rule; MockedSituationEdge capEdge; OneOrMore predicate; capEdge = new MockedSituationEdge(); graph = new SituationGraph <char>(); factory = new SituationGraphSegmentFactory <char>(); predicate = new OneOrMore(); rule = new LexicalRule() { Name = "A", Predicate = predicate }; Assert.ThrowsException <ArgumentNullException>(() => factory.BuildSegment(null, rule, predicate, capEdge.AsEnumerable())); Assert.ThrowsException <ArgumentNullException>(() => factory.BuildSegment(graph, null, predicate, capEdge.AsEnumerable())); Assert.ThrowsException <ArgumentNullException>(() => factory.BuildSegment(graph, rule, null as OneOrMore, capEdge.AsEnumerable())); Assert.ThrowsException <ArgumentNullException>(() => factory.BuildSegment(graph, rule, predicate, null)); }