public void Test_Growth()
        {
            ByteStack bs = new ByteStack(4);

            bs.Push((byte) 'b');
            Assert.AreEqual("b", bs.ToString());
            bs.Push((byte) 'c');
            Assert.AreEqual("bc", bs.ToString());
            bs.Push((byte) 'd');
            Assert.AreEqual("bcd", bs.ToString());
            bs.Push((byte) 'e');
            Assert.AreEqual("bcde", bs.ToString());
            bs.Push((byte) 'b');
            Assert.AreEqual("bcdeb", bs.ToString());
            bs.Push((byte) 'c');
            Assert.AreEqual("bcdebc", bs.ToString());
            bs.Push((byte) 'd');
            Assert.AreEqual("bcdebcd", bs.ToString());
            bs.Push((byte) 'e');
            Assert.AreEqual("bcdebcde", bs.ToString());
            bs.Push((byte) 'b');
            bs.Push((byte) 'c');
            bs.Push((byte) 'd');
            bs.Push((byte) 'e');
            bs.Push((byte) 'b');
            bs.Push((byte) 'c');
            bs.Push((byte) 'd');
            bs.Push((byte) 'e');
            Assert.AreEqual("bcdebcdebcdebcde", bs.ToString());
        }
 public void Test_Init()
 {
     ByteStack bs = new ByteStack(ENC.GetBytes("foo"));
     Assert.AreEqual("foo", bs.ToString());
     bs.Push((byte) 't');
     Assert.AreEqual("foot", bs.ToString());
     bs = new ByteStack(ENC.GetBytes("f"));
     bs.Push((byte) 't');
     Assert.AreEqual("ft", bs.ToString());
 }
Beispiel #3
0
 [Test] public void Test_Main()
 {
     ByteStack bs = new ByteStack();
     Assert.AreEqual(0, bs.Count);
     bs.Push((byte) 'a');
     Assert.AreEqual(1, bs.Count);
     byte b = bs.Pop();
     Assert.AreEqual(b, (byte)'a');
     Assert.AreEqual(0, bs.Count);
 }
Beispiel #4
0
 /// <summary>
 /// Perform the given function on every element of the trie.  Perl's map() operator.
 /// </summary>
 /// <param name="w">The function to call</param>
 /// <param name="data">Extra data to pass along to the function.</param>
 /// <param name="current">What node are we currently on?</param>
 /// <param name="key">A stack holding the current key value</param>
 protected void Traverse(TrieKeyWalker w, object data, TrieNode current, ByteStack key)
 {
     if (!w(current, data, key))
     {
         return;
     }
     foreach (TrieNode e in current)
     {
         key.Push(e.Byte);
         Traverse(w, data, e, key);
         key.Pop();
     }
 }
Beispiel #5
0
 /// <summary>
 /// Copy the keys from the sub-tree into an ArrayList.
 /// </summary>
 /// <param name="n"> </param>
 /// <param name="data"> </param>
 /// <param name="key"> </param>
 private bool CopyWalker(TrieNode n, object data, ByteStack key)
 {
     if (n.Value != null)
     {
         ArrayList al = (ArrayList)data;
         al.Add((byte[])key);
         if (al.Count >= m_maxResults)
         {
             return(false);
         }
     }
     return(true);
 }
 public void Test_Empty()
 {
     ByteStack bs = new ByteStack();
     byte[] buf = bs;
     Assert.AreEqual(0, buf.Length);
 }
Beispiel #7
0
 /// <summary>
 /// Find all of the keys.
 /// </summary>
 /// <param name="n"> </param>
 /// <param name="data"> </param>
 /// <param name="key"> </param>
 private bool KeyWalker(TrieNode n, object data, ByteStack key)
 {
     if (n.Value != null)
     {
         ArrayList al = (ArrayList) data;
         al.Add((byte[]) key);
     }
     return true;
 }
Beispiel #8
0
 /// <summary>
 /// Perform the given function on every element of the trie.  Perl's map() operator.
 /// </summary>
 /// <param name="w">The function to call</param>
 /// <param name="data">Extra data to pass along to the function.</param>
 /// <param name="current">What node are we currently on?</param>
 /// <param name="key">A stack holding the current key value</param>
 protected void Traverse(TrieKeyWalker w, object data, TrieNode current, ByteStack key)
 {
     if (!w(current, data, key))
     {
         return;
     }
     foreach (TrieNode e in current)
     {
         key.Push(e.Byte);
         Traverse(w, data, e, key);
         key.Pop();
     }
 }
Beispiel #9
0
 /// <summary>
 /// Copy the keys from the sub-tree into an ArrayList.
 /// </summary>
 /// <param name="n"> </param>
 /// <param name="data"> </param>
 /// <param name="key"> </param>
 private bool CopyWalker(TrieNode n, object data, ByteStack key)
 {
     if (n.Value != null)
     {
         ArrayList al = (ArrayList) data;
         al.Add((byte[]) key);
         if (al.Count >= m_maxResults)
         {
             return false;
         }
     }
     return true;
 }