summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSebastian Thiel <sthiel@thoughtworks.com>2019-06-02 16:00:35 +0530
committerSebastian Thiel <sthiel@thoughtworks.com>2019-06-02 16:00:35 +0530
commitdec4afc358aa30521d564068b219eca129245782 (patch)
treee4ab122ff07671b9e31fe002105c09d159bc9217
parent5a7ee1bf881518b6cd33a1880fabd12aa53553bf (diff)
Add test showing sizes don't work, and graph traversal neither :D
-rw-r--r--src/interactive.rs25
-rw-r--r--tests/fixtures/sample-01/z123.b1
-rw-r--r--tests/interactive.rs10
-rw-r--r--tests/snapshots/success-bytes-binary1
-rw-r--r--tests/snapshots/success-bytes-only3
-rw-r--r--tests/snapshots/success-no-arguments1
-rw-r--r--tests/snapshots/success-no-arguments-multiple-input-paths-statistics2
-rw-r--r--tests/snapshots/success-no-arguments-no-sort1
8 files changed, 31 insertions, 13 deletions
diff --git a/src/interactive.rs b/src/interactive.rs
index e03674b..7f20728 100644
--- a/src/interactive.rs
+++ b/src/interactive.rs
@@ -58,6 +58,8 @@ mod app {
let root_index = tree.add_node(EntryData::default());
let (mut previous_node_idx, mut parent_node_idx) = (root_index, root_index);
+ let mut sizes_per_depth_level = Vec::new();
+ let mut current_size_at_depth = 0;
let mut previous_depth = 0;
for path in input.into_iter() {
@@ -66,6 +68,7 @@ mod app {
let mut data = EntryData::default();
match entry {
Ok(entry) => {
+ dbg!(entry.depth);
data.name = entry.file_name;
let file_size = match entry.metadata {
Some(Ok(ref m)) if !m.is_dir() => m.len(),
@@ -80,13 +83,21 @@ mod app {
),
};
- parent_node_idx = match (entry.depth, previous_depth) {
- (n, p) if n > p => previous_node_idx,
- (n, p) if n < p => tree
- .neighbors_directed(parent_node_idx, Direction::Incoming)
- .next()
- .expect("every node in the iteration has a parent"),
- _ => parent_node_idx,
+ match (entry.depth, previous_depth) {
+ (n, p) if n > p => {
+ sizes_per_depth_level.push(current_size_at_depth);
+ current_size_at_depth = 0;
+ parent_node_idx = previous_node_idx;
+ }
+ (n, p) if n < p => {
+ parent_node_idx = tree
+ .neighbors_directed(parent_node_idx, Direction::Incoming)
+ .next()
+ .expect("every node in the iteration has a parent");
+ }
+ _ => {
+ current_size_at_depth += file_size;
+ }
};
previous_depth = entry.depth;
diff --git a/tests/fixtures/sample-01/z123.b b/tests/fixtures/sample-01/z123.b
new file mode 100644
index 0000000..11321e2
--- /dev/null
+++ b/tests/fixtures/sample-01/z123.b
@@ -0,0 +1 @@
+aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa \ No newline at end of file
diff --git a/tests/interactive.rs b/tests/interactive.rs
index 4e6a44a..a181362 100644
--- a/tests/interactive.rs
+++ b/tests/interactive.rs
@@ -18,8 +18,8 @@ mod app {
let expected_tree = sample_01_tree();
assert_eq!(
- debug(app.tree.raw_edges()),
- debug(expected_tree.raw_edges()),
+ debug(app.tree),
+ debug(expected_tree),
"filesystem graph is stable and matches the directory structure"
);
Ok(())
@@ -58,9 +58,10 @@ mod app {
}
n
};
- let r = add_node("", 0, None);
+ let root_size = 1259325;
+ let r = add_node("", root_size, None);
{
- let s = add_node("sample-01", 0, Some(r));
+ let s = add_node("sample-01", root_size, Some(r));
{
add_node(".hidden.666", 666, Some(s));
add_node("a", 256, Some(s));
@@ -80,6 +81,7 @@ mod app {
add_node("dir-sub-a.256kb", 256_000, Some(sub));
}
}
+ add_node("z123.b", 123, Some(s));
}
}
t
diff --git a/tests/snapshots/success-bytes-binary b/tests/snapshots/success-bytes-binary
index acc26fc..7a43a1a 100644
--- a/tests/snapshots/success-bytes-binary
+++ b/tests/snapshots/success-bytes-binary
@@ -1,4 +1,5 @@
0.00 B b.empty
+ 123.00 B z123.b
256.00 B a
256.00 B c.lnk
666.00 B .hidden.666
diff --git a/tests/snapshots/success-bytes-only b/tests/snapshots/success-bytes-only
index b83f090..bf6466a 100644
--- a/tests/snapshots/success-bytes-only
+++ b/tests/snapshots/success-bytes-only
@@ -1,6 +1,7 @@
0 b b.empty
+ 123 b z123.b
256 b a
256 b c.lnk
666 b .hidden.666
1258024 b dir
- 1259202 b total \ No newline at end of file
+ 1259325 b total \ No newline at end of file
diff --git a/tests/snapshots/success-no-arguments b/tests/snapshots/success-no-arguments
index e85cf4b..8348016 100644
--- a/tests/snapshots/success-no-arguments
+++ b/tests/snapshots/success-no-arguments
@@ -1,4 +1,5 @@
0.00 B b.empty
+ 123.00 B z123.b
256.00 B a
256.00 B c.lnk
666.00 B .hidden.666
diff --git a/tests/snapshots/success-no-arguments-multiple-input-paths-statistics b/tests/snapshots/success-no-arguments-multiple-input-paths-statistics
index 5925329..36024d6 100644
--- a/tests/snapshots/success-no-arguments-multiple-input-paths-statistics
+++ b/tests/snapshots/success-no-arguments-multiple-input-paths-statistics
@@ -4,4 +4,4 @@
1.26 MB .
1.26 MB .
5.29 MB total
-Statistics { files_traversed: 44, smallest_file_in_bytes: 0, largest_file_in_bytes: 1000000 } \ No newline at end of file
+Statistics { entries_traversed: 46, smallest_file_in_bytes: 0, largest_file_in_bytes: 1000000 } \ No newline at end of file
diff --git a/tests/snapshots/success-no-arguments-no-sort b/tests/snapshots/success-no-arguments-no-sort
index 42f24a4..126d918 100644
--- a/tests/snapshots/success-no-arguments-no-sort
+++ b/tests/snapshots/success-no-arguments-no-sort
@@ -3,4 +3,5 @@
0.00 B b.empty
256.00 B c.lnk
1.26 MB dir
+ 123.00 B z123.b
1.26 MB total \ No newline at end of file