Exemplo n.º 1
0
 /// <exception cref="System.Exception"/>
 internal Node(Path path, int level, SnapshotTestHelper.TestDirectoryTree.Node parent
               , FileSystem fs)
 {
     this.nodePath            = path;
     this.level               = level;
     this.parent              = parent;
     this.nonSnapshotChildren = new AList <SnapshotTestHelper.TestDirectoryTree.Node>();
     fs.Mkdirs(nodePath);
 }
Exemplo n.º 2
0
 public override bool Equals(object o)
 {
     if (o != null && o is SnapshotTestHelper.TestDirectoryTree.Node)
     {
         SnapshotTestHelper.TestDirectoryTree.Node node = (SnapshotTestHelper.TestDirectoryTree.Node
                                                           )o;
         return(node.nodePath.Equals(nodePath));
     }
     return(false);
 }
Exemplo n.º 3
0
 /// <summary>
 /// Constructor to build a tree of given
 /// <paramref name="height"/>
 /// </summary>
 /// <exception cref="System.Exception"/>
 internal TestDirectoryTree(int height, FileSystem fs)
 {
     this.height  = height;
     this.topNode = new SnapshotTestHelper.TestDirectoryTree.Node(new Path("/TestSnapshot"
                                                                           ), 0, null, fs);
     this.levelMap = new Dictionary <int, AList <SnapshotTestHelper.TestDirectoryTree.Node
                                                 > >();
     AddDirNode(topNode, 0);
     GenChildren(topNode, height - 1, fs);
 }
Exemplo n.º 4
0
            /// <summary>Add a node into the levelMap</summary>
            private void AddDirNode(SnapshotTestHelper.TestDirectoryTree.Node node, int atLevel
                                    )
            {
                AList <SnapshotTestHelper.TestDirectoryTree.Node> list = levelMap[atLevel];

                if (list == null)
                {
                    list = new AList <SnapshotTestHelper.TestDirectoryTree.Node>();
                    levelMap[atLevel] = list;
                }
                list.AddItem(node);
            }
Exemplo n.º 5
0
 /// <summary>Randomly retrieve a node from the directory tree.</summary>
 /// <param name="random">A random instance passed by user.</param>
 /// <param name="excludedList">
 /// Excluded list, i.e., the randomly generated node
 /// cannot be one of the nodes in this list.
 /// </param>
 /// <returns>a random node from the tree.</returns>
 internal virtual SnapshotTestHelper.TestDirectoryTree.Node GetRandomDirNode(Random
                                                                             random, IList <SnapshotTestHelper.TestDirectoryTree.Node> excludedList)
 {
     while (true)
     {
         int level = random.Next(height);
         AList <SnapshotTestHelper.TestDirectoryTree.Node> levelList = levelMap[level];
         int index = random.Next(levelList.Count);
         SnapshotTestHelper.TestDirectoryTree.Node randomNode = levelList[index];
         if (excludedList == null || !excludedList.Contains(randomNode))
         {
             return(randomNode);
         }
     }
 }
Exemplo n.º 6
0
 /// <summary>Recursively generate the tree based on the height.</summary>
 /// <param name="parent">The parent node</param>
 /// <param name="level">The remaining levels to generate</param>
 /// <param name="fs">The FileSystem where to generate the files/dirs</param>
 /// <exception cref="System.Exception"/>
 private void GenChildren(SnapshotTestHelper.TestDirectoryTree.Node parent, int level
                          , FileSystem fs)
 {
     if (level == 0)
     {
         return;
     }
     parent.leftChild = new SnapshotTestHelper.TestDirectoryTree.Node(new Path(parent.
                                                                               nodePath, "left" + ++id), height - level, parent, fs);
     parent.rightChild = new SnapshotTestHelper.TestDirectoryTree.Node(new Path(parent
                                                                                .nodePath, "right" + ++id), height - level, parent, fs);
     AddDirNode(parent.leftChild, parent.leftChild.level);
     AddDirNode(parent.rightChild, parent.rightChild.level);
     GenChildren(parent.leftChild, level - 1, fs);
     GenChildren(parent.rightChild, level - 1, fs);
 }