summaryrefslogtreecommitdiff
path: root/ayafs/src/tests/bitmap.rs
diff options
context:
space:
mode:
authorChuyan Zhang <me@zcy.moe>2023-11-30 02:15:06 -0800
committerChuyan Zhang <me@zcy.moe>2023-11-30 02:15:06 -0800
commit1eac97eea4ec0bcef0be061a2cba93a584355283 (patch)
treed98fb1f6e3811286a0733c9df21e467590635ad2 /ayafs/src/tests/bitmap.rs
parentb3db8a5a710aa0890c80241ffb3fd9792bf1cbe7 (diff)
downloadmyfs-1eac97eea4ec0bcef0be061a2cba93a584355283.tar.gz
myfs-1eac97eea4ec0bcef0be061a2cba93a584355283.zip
Add real disk i/o, add mkfs.aya (not yet implemented)
Diffstat (limited to 'ayafs/src/tests/bitmap.rs')
-rw-r--r--ayafs/src/tests/bitmap.rs38
1 files changed, 38 insertions, 0 deletions
diff --git a/ayafs/src/tests/bitmap.rs b/ayafs/src/tests/bitmap.rs
new file mode 100644
index 0000000..1a43f09
--- /dev/null
+++ b/ayafs/src/tests/bitmap.rs
@@ -0,0 +1,38 @@
+use crate::tests::common;
+use indexmap::IndexMap;
+
+#[test]
+fn test_allocate() {
+ let mut fs = common::setup();
+ for _ in 0..10 {
+ fs.data_bitmap.allocate().unwrap();
+ }
+ assert!(fs.data_bitmap.deallocate(5));
+ assert_eq!(fs.data_bitmap.allocate().unwrap(), 5);
+ assert_eq!(fs.data_bitmap.allocate().unwrap(), 11);
+}
+
+#[test]
+fn test_query() {
+ let mut fs = common::setup();
+ for _ in 0..10 {
+ fs.data_bitmap.allocate().unwrap();
+ }
+ assert_eq!(fs.data_bitmap.query(0), false);
+ assert_eq!(fs.data_bitmap.query(5), true);
+ assert_eq!(fs.data_bitmap.query(11), false);
+}
+
+#[test]
+fn test_index_map() {
+ let mut map: IndexMap<i32, i32> = IndexMap::new();
+ map.insert(1, 2);
+ map.insert(2, 3);
+ map.insert(3, 4);
+ map.insert(4, 5);
+ map.remove(&3);
+
+ for (entry_index, (key, value)) in map.iter().enumerate() {
+ println!("index {}, key {}, value {}", entry_index, key, value);
+ }
+}