summaryrefslogtreecommitdiff
path: root/ayafs-core/src/tests/bitmap.rs
blob: 1a43f09b0623b5e3e6536ccb2faadde77d1b411e (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
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);
    }
}