Skip to content

Commit

Permalink
Test remaining world container methods.
Browse files Browse the repository at this point in the history
  • Loading branch information
Anders429 committed Aug 19, 2022
1 parent a744240 commit 5680e23
Showing 1 changed file with 84 additions and 2 deletions.
86 changes: 84 additions & 2 deletions src/world/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -627,9 +627,9 @@ where
unsafe {
self.entity_allocator.free_unchecked(entity_identifier);
}
}

self.len -= 1;
self.len -= 1;
}
}

/// Removes all entities.
Expand Down Expand Up @@ -1741,4 +1741,86 @@ mod tests {

assert_none!(world.entry(entity_identifier));
}

#[test]
fn remove() {
let mut world = World::<Registry>::new();

let entity_identifier = world.insert(entity!(A(1), B('a')));
world.insert(entity!(A(2)));
world.insert(entity!(B('b')));
world.insert(entity!());

world.remove(entity_identifier);

let mut result = world
.query::<views!(&A), filter::None>()
.map(|result!(a)| a.0)
.collect::<Vec<_>>();
result.sort();
assert_eq!(result, vec![2]);
assert_eq!(world.len(), 3);
}

#[test]
fn remove_already_removed() {
let mut world = World::<Registry>::new();

let entity_identifier = world.insert(entity!(A(1), B('a')));
world.insert(entity!(A(2)));
world.insert(entity!(B('b')));
world.insert(entity!());

world.remove(entity_identifier);
assert_eq!(world.len(), 3);
world.remove(entity_identifier);

assert_eq!(world.len(), 3);
}

#[test]
fn clear() {
let mut world = World::<Registry>::new();

world.insert(entity!(A(1), B('a')));
world.insert(entity!(A(2)));
world.insert(entity!(B('b')));
world.insert(entity!());

world.clear();

let mut result = world
.query::<views!(&A), filter::None>()
.map(|result!(a)| a.0)
.collect::<Vec<_>>();
result.sort();
assert_eq!(result, Vec::new());
assert_eq!(world.len(), 0);
}

#[test]
fn len() {
let mut world = World::<Registry>::new();

world.insert(entity!(A(1), B('a')));
world.insert(entity!(A(2)));
world.insert(entity!(B('b')));
world.insert(entity!());

assert_eq!(world.len(), 4);
}

#[test]
fn is_empty() {
let mut world = World::<Registry>::new();

assert!(world.is_empty());

world.insert(entity!(A(1), B('a')));
world.insert(entity!(A(2)));
world.insert(entity!(B('b')));
world.insert(entity!());

assert!(!world.is_empty());
}
}

0 comments on commit 5680e23

Please sign in to comment.