Esempio n. 1
0
        public void ShouldMoveDuplicateItemToTopOfList(string[] stringsToPush, string expectedString, int expectedCount)
        {
            StringStack stringStack = new StringStack(stringsToPush);

            Assert.AreEqual(expectedString, stringStack.Peek());
            Assert.AreEqual(expectedCount, stringStack.Count);
        }
Esempio n. 2
0
        public void Add()
        {
            var stack = new StringStack();

            stack.Push("a");
            Assert.Contains("a", stack);
        }
Esempio n. 3
0
        public void ShouldNotAddEmptyStrings()
        {
            StringStack stringStack = new StringStack();

            stringStack.Push("");

            Assert.AreEqual(0, stringStack.Count);
        }
Esempio n. 4
0
        public void Clear()
        {
            var stack = new StringStack();

            stack.Push("a");
            stack.Clear();
            Assert.Zero(stack.Count);
        }
Esempio n. 5
0
        public void SetUp()
        {
            _stack = new StringStack(16);
            Assert.AreEqual(0, _stack.Count);

            _stack.Push("one");
            _stack.Push("two");
            _stack.Push("three");
            Assert.AreEqual(3, _stack.Count);
        }
Esempio n. 6
0
        public void GetByteTest()
        {
            StringStack SS = new StringStack("112233445566");

            Assert.AreEqual("11", SS.getByte());
            Assert.AreEqual("22", SS.getByte());
            Assert.AreEqual("33", SS.getByte());
            Assert.AreEqual("44", SS.getByte());
            Assert.AreEqual("112233445566", SS.OriginalString);
        }
Esempio n. 7
0
        public void getRemaining()
        {
            StringStack SS = new StringStack("11223344556677889900");

            Assert.AreEqual("1122", SS.getBytes(2));
            Assert.AreEqual("33", SS.getByte());
            Assert.AreEqual("44", SS.getByte());
            Assert.AreEqual("556677", SS.getBytes(3));
            Assert.AreEqual("889900", SS.getRemaining());
        }
Esempio n. 8
0
        public void GetBytesTest()
        {
            StringStack SS = new StringStack("112233445566778899");

            Assert.AreEqual("1122", SS.getBytes(2));
            Assert.AreEqual("33", SS.getByte());
            Assert.AreEqual("44", SS.getByte());
            Assert.AreEqual("556677", SS.getBytes(3));
            Assert.AreEqual("112233445566778899", SS.OriginalString);
        }
Esempio n. 9
0
        public void Count()
        {
            var stack = new StringStack();

            stack.Push("a");
            stack.Push("b");
            stack.Push("c");
            stack.Push("d");
            stack.Push("e");
            Assert.AreEqual(stack.Count, 5);
        }
Esempio n. 10
0
        private StringStack CreateTestStack()
        {
            var stack = new StringStack();

            for (var i = 0; i < 25; i++)
            {
                stack.Push(new string((char)('a' + i), 1));
            }

            return(stack);
        }
Esempio n. 11
0
        public void IsLIFO()
        {
            var stack = new StringStack();

            stack.Push("a");
            stack.Push("b");
            stack.Push("c");
            string pop = stack.Pop();

            Assert.AreEqual("c", pop);
        }
Esempio n. 12
0
        public void ShouldRemoveOldestStringWhenAtCapacityAndNewStringIsAdded()
        {
            StringStack stringStack = new StringStack(3);

            stringStack.Push("apple");
            stringStack.Push("orange");
            stringStack.Push("pineapple");
            stringStack.Push("pear");

            Assert.AreEqual(3, stringStack.Count);
            Assert.AreEqual("pear", stringStack.Peek());
        }
Esempio n. 13
0
        public Data_0340(string val)
        {
            StringStack SS = new StringStack(val);
            TP_MTI = SS.getByte();
            TPOA = new TPDA();
            val = TPOA.parse(SS.getRemaining());

            SS = new StringStack(val);
            TP_PID = SS.getByte();
            TP_DCS = SS.getByte();
            TP_SCTS = SS.getBytes(7);

            UserData = new Data_0348(SS.getRemaining());
        }
Esempio n. 14
0
        public void Copy()
        {
            StringStack copy = _stack.Copy();

            Assert.AreEqual(_stack.Count, copy.Count);

            int count = _stack.Count;

            for (int i = 0; i < count; i++)
            {
                CloneableType x = _stack.Pop(), y = copy.Pop();
                Assert.AreEqual(x, y);
                Assert.AreNotSame(x, y);
            }
        }
Esempio n. 15
0
        public Data_0340(string val)
        {
            StringStack SS = new StringStack(val);

            TP_MTI = SS.getByte();
            TPOA   = new TPDA();
            val    = TPOA.parse(SS.getRemaining());

            SS      = new StringStack(val);
            TP_PID  = SS.getByte();
            TP_DCS  = SS.getByte();
            TP_SCTS = SS.getBytes(7);

            UserData = new Data_0348(SS.getRemaining());
        }
Esempio n. 16
0
        public void Constructor()
        {
            StringStack stack = new StringStack(567);

            stack.Push("foo"); stack.Push("bar");
            Assert.AreEqual(2, stack.Count);

            CloneableType[] array = new CloneableType[4] {
                "a", "b", "c", "d"
            };
            stack = new StringStack(array);
            Assert.AreEqual(4, stack.Count);
            Assert.IsFalse(stack.Equals(array));
            Assert.IsTrue(stack.EqualsReverse(array));
        }
Esempio n. 17
0
        public void Clone()
        {
            StringStack clone = (StringStack)_stack.Clone();

            Assert.AreEqual(_stack.Count, clone.Count);

            int count = _stack.Count;

            for (int i = 0; i < count; i++)
            {
                CloneableType x = _stack.Pop(), y = clone.Pop();
                Assert.AreEqual(x, y);
                Assert.AreSame(x, y);
            }
        }
Esempio n. 18
0
        public void Equals()
        {
            StringStack stack = new StringStack();

            stack.Push("one");
            stack.Push("two");
            stack.Push("three");
            Assert.IsTrue(_stack.Equals(stack));
            Assert.IsFalse(_stack.EqualsReverse(stack));

            stack.Push("one");
            Assert.IsFalse(_stack.Equals(stack));

            stack.Pop();
            Assert.IsTrue(_stack.Equals(stack));
        }
Esempio n. 19
0
        private static void testStringStack()
        {
            StringStack stacks = new StringStack();

            for (int i = 0; i < 100; i++)
            {
                stacks.Push(i.ToString());
            }

            Console.WriteLine(stacks.ToString());
            Console.WriteLine(stacks.Pop());
            Console.WriteLine(stacks.Pop());
            stacks.Push("i.ToString()");
            Console.WriteLine(stacks.ToString());
            for (int i = 0; i < 100; i++)
            {
                stacks.Push(i.ToString());
            }

            Console.WriteLine(stacks.ToString());
        }
Esempio n. 20
0
        public Data_0348(string val)
        {
            StringStack SS = new StringStack(val);
            TPUDL = Convert.ToInt32(Convert.ToByte(SS.getByte(),16));
            UDHL =SS.getByte();
            IEIa =SS.getByte();
            IEDa =SS.getByte();
            CPL = SS.getBytes(2);
            CHL = Convert.ToInt32(Convert.ToByte(SS.getByte(), 16));
            SPI = SS.getBytes(2);
            Kic  = SS.getByte();
            Kid = SS.getByte();
            TAR = SS.getBytes(3);
            CNTR = SS.getBytes(5);
            PCNTR = SS.getByte();

            if (CHL > 13)
            {
                RC_CC_DS = SS.getBytes(CHL - 13);
            }

            SecureData = SS.getRemaining();
        }
Esempio n. 21
0
        public Data_0348(string val)
        {
            StringStack SS = new StringStack(val);

            TPUDL = Convert.ToInt32(Convert.ToByte(SS.getByte(), 16));
            UDHL  = SS.getByte();
            IEIa  = SS.getByte();
            IEDa  = SS.getByte();
            CPL   = SS.getBytes(2);
            CHL   = Convert.ToInt32(Convert.ToByte(SS.getByte(), 16));
            SPI   = SS.getBytes(2);
            Kic   = SS.getByte();
            Kid   = SS.getByte();
            TAR   = SS.getBytes(3);
            CNTR  = SS.getBytes(5);
            PCNTR = SS.getByte();

            if (CHL > 13)
            {
                RC_CC_DS = SS.getBytes(CHL - 13);
            }

            SecureData = SS.getRemaining();
        }
Esempio n. 22
0
        public void Stack_Peek_DoesntRemoveNode()
        {
            StringStack stack = new StringStack();

            StringStack
        }
Esempio n. 23
0
        // -------------------------- MessagePartSplitter -----------------------
        // input is an array holding the unfolded lines of the message.
        // Build and return a list of MimeMessagePart objects.  Each part object holds the
        // lines of a part of the message.
        // ( a part is either the header part or the boundary string delimited content parts.
        public static InMail.MimeMessagePartList MessagePartSplitter(string[] InLines)
        {
            InMail.MimeMessagePartList parts   = new InMail.MimeMessagePartList( );
            int          curPartBx             = -1;
            int          curPartCx             = 0;
            MimePartCode curPartCode           = MimePartCode.Top;
            bool         currentlyBetweenParts = false;
            bool         partIsJustStarting    = true;
            StringStack  bdryStack             = new StringStack( );

            for (int Ix = 0; Ix < InLines.Length; ++Ix)
            {
                string       line = InLines[Ix];
                MimeLineCode lc   = MimeParser.CalcLineCode(line, bdryStack.GetTop( ));

                switch (lc)
                {
                case MimeLineCode.Property:
                {
                    StringPair propPair = MimeParser.SplitPropertyLine(line);

                    // the content-type property.  Could have an boundary="xxxxx" element.
                    // Boundary strings in a mime document have scope. That is, within one
                    // boundary ( section ) of the document, there can be sub boundaries
                    // ( sub sections )
                    if (propPair.a.ToLower( ) == "content-type")
                    {
                        PartProperty.ContentType ct =
                            MimeParser.ParseContentType(propPair.b);
                        if ((ct.Boundary != null) && (ct.Boundary != ""))
                        {
                            bdryStack.Push(ct.Boundary);
                        }
                    }
                    break;
                }

                // part boundary line. load the lines of the current part and reset the line
                // counter of this new part.
                case MimeLineCode.PartBdry:
                    if (curPartBx != -1)
                    {
                        parts.AddNewPart(curPartCode)
                        .LoadLines(InLines, curPartBx, curPartCx);
                    }
                    curPartCx             = 0;
                    curPartBx             = -1;
                    curPartCode           = MimePartCode.Content;
                    currentlyBetweenParts = false;
                    partIsJustStarting    = true;
                    break;

                case MimeLineCode.PartEndBdry:
                    if (curPartBx != -1)
                    {
                        parts.AddNewPart(curPartCode)
                        .LoadLines(InLines, curPartBx, curPartCx);
                    }
                    curPartCx = 0;
                    curPartBx = -1;
                    if (bdryStack.IsNotEmpty)
                    {
                        bdryStack.Pop( );
                    }
                    currentlyBetweenParts = true;
                    break;

                default:
                    break;
                }

                // add to range of lines in the current part.
                if ((currentlyBetweenParts == false) && (lc != MimeLineCode.PartBdry))
                {
                    if ((partIsJustStarting == true) && (line == ""))
                    {
                    }
                    else
                    {
                        ++curPartCx;
                        if (curPartBx == -1)
                        {
                            curPartBx = Ix;
                        }
                    }
                    partIsJustStarting = false;
                }
            }

            // load the lines of the final in progress part.
            if (curPartBx != -1)
            {
                parts.AddNewPart(curPartCode)
                .LoadLines(InLines, curPartBx, curPartCx);
            }

            return(parts);
        }
Esempio n. 24
0
        // -------------------------- MessagePartSplitter -----------------------
        // input is an array holding the unfolded lines of the message.
        // Build and return a list of MimeMessagePart objects.  Each part object holds the
        // lines of a part of the message.
        // ( a part is either the header part or the boundary string delimited content parts.
        public static InMail.MimeMessagePartList MessagePartSplitter(string InStream)
        {
            InMail.MimeMessagePartList parts  = new InMail.MimeMessagePartList( );
            bool        currentlyBetweenParts = false;
            StringStack bdryStack             = new StringStack( );

            int    Ex   = -1;
            string line = null;

            MimeMessagePart.PartInProgress pip =
                new MimeMessagePart.PartInProgress(MimePartCode.Top);

            while (true)
            {
                // advance in string.
                int lineBx = Ex + 1;
                if (lineBx >= InStream.Length)
                {
                    break;
                }

                // the next line in the stream. recognize folds depending on if currently within
                // a part header or within the message lines of the part ( no folding there )
                if (pip.CurrentlyAmoungPropertyLines == true)
                {
                    IntStringPair rv = ScanEndUnfoldedLine(InStream, lineBx);
                    Ex   = rv.a;
                    line = rv.b;
                }
                else
                {
                    IntStringPair rv = ScanEndLine(InStream, lineBx);
                    Ex   = rv.a;
                    line = rv.b;
                }

                // calc what kind of a line in the mime document we have here.
                MimeLineCode lc = MimeParser.CalcLineCode(line, bdryStack.GetTop( ));
                if ((lc == MimeLineCode.Property) &&
                    (pip.CurrentlyAmoungMessageLines == true))
                {
                    lc = MimeLineCode.Text;
                }

                switch (lc)
                {
                case MimeLineCode.Property:
                {
                    StringPair propPair = MimeParser.SplitPropertyLine(line);

                    // the content-type property.  Could have an boundary="xxxxx" element.
                    // Boundary strings in a mime document have scope. That is, within one
                    // boundary ( section ) of the document, there can be sub boundaries
                    // ( sub sections )
                    if (propPair.a.ToLower( ) == "content-type")
                    {
                        PartProperty.ContentType ct =
                            MimeParser.ParseContentType(propPair.b);
                        if ((ct.Boundary != null) && (ct.Boundary != ""))
                        {
                            bdryStack.Push(ct.Boundary);
                        }
                    }
                    pip.AddLine(lineBx, line);
                    break;
                }

                // part boundary line. load the lines of the current part and reset the line
                // counter of this new part.
                case MimeLineCode.PartBdry:
                    if (pip.HasLines == true)
                    {
                        parts.AddNewPart(InStream, pip);
                    }
                    pip = new MimeMessagePart.PartInProgress(MimePartCode.Content);
                    currentlyBetweenParts = false;
                    break;

                case MimeLineCode.PartEndBdry:
                    if (pip.HasLines == true)
                    {
                        parts.AddNewPart(InStream, pip);
                    }
                    pip = new MimeMessagePart.PartInProgress(MimePartCode.Content);
                    if (bdryStack.IsNotEmpty)
                    {
                        bdryStack.Pop( );
                    }
                    currentlyBetweenParts = true;
                    break;

                // we have a line which is not a property line, not a boundary line.
                default:
                {
                    // just starting out.  discard the "+OK" response sent by the server immed
                    // before the start of the message.
                    if ((pip.PartCode == MimePartCode.Top) &&
                        (pip.PartIsJustStarting == true) &&
                        (line.Length >= 3) &&
                        (line.Substring(0, 3) == "+OK"))
                    {
                    }

                    // currently handling property lines.
                    else if (pip.CurrentlyAmoungPropertyLines == true)
                    {
                        // a blank line switches from property lines to message lines.
                        if (line.Length == 0)
                        {
                            pip.CurrentlyAmoungPropertyLines = false;
                            pip.CurrentlyAmoungMessageLines  = true;
                        }

                        // what is this text line doing amoung the property lines ??
                        // for now, just ignore it.
                        else
                        {
                        }
                    }

                    else if (currentlyBetweenParts == false)
                    {
                        pip.AddLine(lineBx, line);
                    }
                    break;
                }
                }
            }

            // load the lines of the final in progress part.
            if (pip.HasLines == true)
            {
                parts.AddNewPart(InStream, pip);
            }

            return(parts);
        }
Esempio n. 25
0
 public void TearDown()
 {
     _stack.Clear();
     _stack = null;
 }
Esempio n. 26
0
        public void ShouldReturnStringAtIndex(string[] stringsToPush, string expected, int index)
        {
            StringStack stringStack = new StringStack(stringsToPush);

            Assert.AreEqual(expected, stringStack[index]);
        }
Esempio n. 27
0
        public void ShouldReturnMostRecentlyAddedStringAsTopItem(string[] stringsToPush, string expected)
        {
            StringStack stringStack = new StringStack(stringsToPush);

            Assert.AreEqual(expected, stringStack.Peek());
        }