2019-11-06 22:57:54 +00:00
|
|
|
use super::*;
|
|
|
|
use lazy_static::lazy_static;
|
|
|
|
lazy_static! {
|
|
|
|
static ref TEST_ITEMS: Vec<Item> = vec![
|
2020-09-17 23:02:14 +00:00
|
|
|
Item::new_from_asset_expect("common.items.debug.boost"),
|
|
|
|
Item::new_from_asset_expect("common.items.debug.possess")
|
2019-11-06 22:57:54 +00:00
|
|
|
];
|
|
|
|
}
|
|
|
|
|
|
|
|
/// Attempting to push into a full inventory should return the same item.
|
|
|
|
#[test]
|
|
|
|
fn push_full() {
|
|
|
|
let mut inv = Inventory {
|
|
|
|
slots: TEST_ITEMS.iter().map(|a| Some(a.clone())).collect(),
|
2020-03-23 23:23:21 +00:00
|
|
|
amount: 0,
|
2019-11-06 22:57:54 +00:00
|
|
|
};
|
|
|
|
assert_eq!(
|
|
|
|
inv.push(TEST_ITEMS[0].clone()).unwrap(),
|
|
|
|
TEST_ITEMS[0].clone()
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
|
|
|
/// Attempting to push a series into a full inventory should return them all.
|
|
|
|
#[test]
|
|
|
|
fn push_all_full() {
|
|
|
|
let mut inv = Inventory {
|
|
|
|
slots: TEST_ITEMS.iter().map(|a| Some(a.clone())).collect(),
|
2020-03-23 23:23:21 +00:00
|
|
|
amount: 0,
|
2019-11-06 22:57:54 +00:00
|
|
|
};
|
|
|
|
let Error::Full(leftovers) = inv
|
2020-06-08 18:37:41 +00:00
|
|
|
.push_all(TEST_ITEMS.iter().cloned())
|
2019-11-06 22:57:54 +00:00
|
|
|
.expect_err("Pushing into a full inventory somehow worked!");
|
|
|
|
assert_eq!(leftovers, TEST_ITEMS.clone())
|
|
|
|
}
|
|
|
|
|
2020-02-01 20:39:39 +00:00
|
|
|
/// Attempting to push uniquely into an inventory containing all the items
|
|
|
|
/// should work fine.
|
2019-11-06 22:57:54 +00:00
|
|
|
#[test]
|
|
|
|
fn push_unique_all_full() {
|
|
|
|
let mut inv = Inventory {
|
|
|
|
slots: TEST_ITEMS.iter().map(|a| Some(a.clone())).collect(),
|
2020-03-23 23:23:21 +00:00
|
|
|
amount: 0,
|
2019-11-06 22:57:54 +00:00
|
|
|
};
|
2020-06-08 18:37:41 +00:00
|
|
|
inv.push_all_unique(TEST_ITEMS.iter().cloned())
|
2019-11-07 01:57:05 +00:00
|
|
|
.expect("Pushing unique items into an inventory that already contains them didn't work!");
|
2019-11-06 22:57:54 +00:00
|
|
|
}
|
|
|
|
|
2020-02-01 20:39:39 +00:00
|
|
|
/// Attempting to push uniquely into an inventory containing all the items
|
|
|
|
/// should work fine.
|
2019-11-06 22:57:54 +00:00
|
|
|
#[test]
|
|
|
|
fn push_all_empty() {
|
|
|
|
let mut inv = Inventory {
|
|
|
|
slots: vec![None, None],
|
2020-03-23 23:23:21 +00:00
|
|
|
amount: 0,
|
2019-11-06 22:57:54 +00:00
|
|
|
};
|
2020-06-08 18:37:41 +00:00
|
|
|
inv.push_all(TEST_ITEMS.iter().cloned())
|
2019-11-06 22:57:54 +00:00
|
|
|
.expect("Pushing items into an empty inventory didn't work!");
|
|
|
|
}
|
|
|
|
|
2020-02-01 20:39:39 +00:00
|
|
|
/// Attempting to push uniquely into an inventory containing all the items
|
|
|
|
/// should work fine.
|
2019-11-06 22:57:54 +00:00
|
|
|
#[test]
|
|
|
|
fn push_all_unique_empty() {
|
|
|
|
let mut inv = Inventory {
|
|
|
|
slots: vec![None, None],
|
2020-03-23 23:23:21 +00:00
|
|
|
amount: 0,
|
2019-11-06 22:57:54 +00:00
|
|
|
};
|
2020-06-08 18:37:41 +00:00
|
|
|
inv.push_all_unique(TEST_ITEMS.iter().cloned()).expect(
|
|
|
|
"Pushing unique items into an empty inventory that didn't contain them didn't work!",
|
|
|
|
);
|
2019-11-06 22:57:54 +00:00
|
|
|
}
|