Ejemplo n.º 1
0
        public void ShouldSplitLettersRangeInputsIntersectsSeveralSegmentsCase()
        {
            TerminalRangeInputCollection <char> items;

            ITerminalRangeInput <char>[] inputs;

            items = new TerminalRangeInputCollection <char>(new FSMLib.LexicalAnalysis.RangeValueProvider());

            Assert.AreEqual(0, items.Count);
            items.Add(new TerminalRangeInput('a', 'c'));
            Assert.AreEqual(1, items.Count);
            items.Add(new TerminalRangeInput('e', 'g'));
            Assert.AreEqual(2, items.Count);
            items.Add(new TerminalRangeInput('c', 'e'));

            inputs = items.ToArray();
            Assert.AreEqual(5, inputs.Length);
            Assert.AreEqual('a', inputs[0].FirstValue);
            Assert.AreEqual('b', inputs[0].LastValue);
            Assert.AreEqual('c', inputs[1].FirstValue);
            Assert.AreEqual('c', inputs[1].LastValue);
            Assert.AreEqual('d', inputs[2].FirstValue);
            Assert.AreEqual('d', inputs[2].LastValue);
            Assert.AreEqual('e', inputs[3].FirstValue);
            Assert.AreEqual('e', inputs[3].LastValue);
            Assert.AreEqual('f', inputs[4].FirstValue);
            Assert.AreEqual('g', inputs[4].LastValue);
        }
Ejemplo n.º 2
0
        public IEnumerable <IInput <char> > GetInputs()
        {
            TerminalRangeInputCollection <char> rangeCollection;


            rangeCollection = new TerminalRangeInputCollection <char>(new RangeValueProvider());
            rangeCollection.Add(new TerminalRangeInput(char.MinValue, char.MaxValue));


            if (Values != null)
            {
                foreach (char val in Values)
                {
                    rangeCollection.Add(val);
                }
            }

            foreach (TerminalRangeInput input in rangeCollection)
            {
                //if (input.FirstValue != input.LastValue) yield return input;
                if (!Values.Contains(input.FirstValue))
                {
                    yield return(input);
                }
            }
        }
Ejemplo n.º 3
0
        public void ShouldAddLettersRangeInput()
        {
            TerminalRangeInputCollection <char> items;

            items = new TerminalRangeInputCollection <char>(new FSMLib.LexicalAnalysis.RangeValueProvider());

            Assert.AreEqual(0, items.Count);
            items.Add(new TerminalRangeInput('a', 'b'));
            Assert.AreEqual(1, items.Count);
            items.Add(new TerminalRangeInput('c', 'd'));
            Assert.AreEqual(2, items.Count);
        }
Ejemplo n.º 4
0
        public IEnumerable <IActionInput <T> > GetDistinctInputs(IEnumerable <IInput <T> > Inputs)
        {
            List <IActionInput <T> >         results;
            TerminalRangeInputCollection <T> items;

            results = new List <IActionInput <T> >();
            items   = new TerminalRangeInputCollection <T>(provider);
            foreach (IInput <T> input in Inputs)
            {
                switch (input)
                {
                case ITerminalInput <T> terminalInput:
                    items.Add(terminalInput.Value);
                    break;

                case ITerminalRangeInput <T> terminalRange:
                    items.Add(terminalRange);
                    break;

                case IActionInput <T> i:
                    if (results.FirstOrDefault(item => item.Equals(i)) == null)
                    {
                        results.Add(i);
                    }
                    break;
                }
            }

            // return results, and convert one item ranges to single terminal
            foreach (ITerminalRangeInput <T> input in items)
            {
                if (input.FirstValue.Equals(input.LastValue))
                {
                    yield return(CreateTerminalInput(input.FirstValue));
                }
                else
                {
                    yield return(input);
                }
            }
            foreach (IActionInput <T> input in results)
            {
                yield return(input);
            }
        }
Ejemplo n.º 5
0
        public void ShouldEnumerate()
        {
            TerminalRangeInputCollection <char> items;

            ITerminalRangeInput <char>[] ranges;

            items = new TerminalRangeInputCollection <char>(new FSMLib.LexicalAnalysis.RangeValueProvider());

            items.Add('a');
            items.Add('b');

            ranges = items.ToArray();
            Assert.AreEqual(2, ranges.Length);
            Assert.AreEqual('a', ranges[0].FirstValue);
            Assert.AreEqual('a', ranges[0].LastValue);
            Assert.AreEqual('b', ranges[1].FirstValue);
            Assert.AreEqual('b', ranges[1].LastValue);
        }
Ejemplo n.º 6
0
        public void ShouldSplitLettersRangeInputsUsingSingleTerminalCase()
        {
            TerminalRangeInputCollection <char> items;

            ITerminalRangeInput <char>[] inputs;

            items = new TerminalRangeInputCollection <char>(new FSMLib.LexicalAnalysis.RangeValueProvider());

            Assert.AreEqual(0, items.Count);
            items.Add(new TerminalRangeInput('a', 'g'));
            items.Add('c');

            inputs = items.ToArray();
            Assert.AreEqual(3, inputs.Length);
            Assert.AreEqual('a', inputs[0].FirstValue);
            Assert.AreEqual('b', inputs[0].LastValue);
            Assert.AreEqual('c', inputs[1].FirstValue);
            Assert.AreEqual('c', inputs[1].LastValue);
            Assert.AreEqual('d', inputs[2].FirstValue);
            Assert.AreEqual('g', inputs[2].LastValue);
        }