Skip to content
This repository has been archived by the owner on Jan 6, 2020. It is now read-only.

Commit

Permalink
Merge pull request #21 from Fraser999/keys_test
Browse files Browse the repository at this point in the history
test/lib: added missing test.
  • Loading branch information
madadam committed Apr 22, 2016
2 parents 0b4d3e8 + 98e9b15 commit 5a534e9
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 2 deletions.
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ version = "0.4.0"

[dependencies]
clippy = {version = "~0.0.63", optional = true}
maidsafe_utilities = "~0.5.1"
maidsafe_utilities = "~0.5.3"
quick-error = "1.0.0"
rustc-serialize = "~0.3.19"
tempdir = "~0.3.4"
Expand Down
26 changes: 25 additions & 1 deletion src/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,10 @@ mod test {
assert!(chunk_store.used_space() <= chunks.total_size);
};

for (index, &(ref data, ref size)) in chunks.data_and_sizes.iter().enumerate().rev() {
for (index, &(ref data, ref size)) in chunks.data_and_sizes
.iter()
.enumerate()
.rev() {
put(index, data, size);
}
}
Expand Down Expand Up @@ -186,4 +189,25 @@ mod test {
let key = rand::random();
assert_err!(chunk_store.get(&key), Error::NotFound);
}

#[test]
fn keys() {
let chunks = generate_random_chunks();
let mut chunk_store = unwrap_result!(ChunkStore::new("test", chunks.total_size));

for (index, &(ref data, _)) in chunks.data_and_sizes.iter().enumerate() {
assert!(!chunk_store.keys().contains(&index));
unwrap_result!(chunk_store.put(&index, data));
assert!(chunk_store.keys().contains(&index));
assert_eq!(chunk_store.keys().len(), index + 1);
}

for (index, _) in chunks.data_and_sizes.iter().enumerate() {
assert!(chunk_store.keys().contains(&index));
unwrap_result!(chunk_store.delete(&index));
assert!(!chunk_store.keys().contains(&index));
assert_eq!(chunk_store.keys().len(),
chunks.data_and_sizes.len() - index - 1);
}
}
}

0 comments on commit 5a534e9

Please sign in to comment.