public void Count() { _stack.Push("foo"); _stack.Push("bar"); Assert.AreEqual(5, _stack.Count); _stack.Pop(); Assert.AreEqual(4, _stack.Count); }
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); }
public void IsLIFO() { var stack = new StringStack(); stack.Push("a"); stack.Push("b"); stack.Push("c"); string pop = stack.Pop(); Assert.AreEqual("c", pop); }
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); }
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()); }
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)); }
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)); }
public void Add() { var stack = new StringStack(); stack.Push("a"); Assert.Contains("a", stack); }
public void ShouldNotAddEmptyStrings() { StringStack stringStack = new StringStack(); stringStack.Push(""); Assert.AreEqual(0, stringStack.Count); }
public void Clear() { var stack = new StringStack(); stack.Push("a"); stack.Clear(); Assert.Zero(stack.Count); }
private StringStack CreateTestStack() { var stack = new StringStack(); for (var i = 0; i < 25; i++) { stack.Push(new string((char)('a' + i), 1)); } return(stack); }
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()); }
// -------------------------- 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); }
// -------------------------- 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); }