135 lines
4.3 KiB
Rust
135 lines
4.3 KiB
Rust
use crate::*;
|
|
|
|
#[test]
|
|
fn list_initialize()
|
|
{
|
|
let list = List::new(natural());
|
|
assert_eq!(0, list.capacity(), "New list has capacity of 0.");
|
|
assert_eq!(0, list.length(), "New list has length of 0.");
|
|
}
|
|
|
|
#[test]
|
|
fn list_from()
|
|
{
|
|
let list = List::new(natural());
|
|
let mut list_ref = List::try_from(*list).unwrap();
|
|
list_ref.append(*Natural::with(10));
|
|
|
|
assert_eq!(1, list.length(), "List has length 1 after append to reference.");
|
|
assert_eq!(10, Natural::try_from(list.at(0)).unwrap().get());
|
|
}
|
|
|
|
#[test]
|
|
fn list_with()
|
|
{
|
|
let list = List::with(natural(), vec![
|
|
*Natural::with(5),
|
|
*Natural::with(10),
|
|
*Natural::with(15),
|
|
*Natural::with(20),
|
|
]);
|
|
assert_eq!(4, list.length());
|
|
assert_eq!(15, Natural::try_from(list.at(2)).unwrap().get());
|
|
}
|
|
|
|
#[test]
|
|
fn list_clear()
|
|
{
|
|
let mut list = List::with(natural(), vec![
|
|
*Natural::with(33),
|
|
*Natural::with(66),
|
|
*Natural::with(99),
|
|
]);
|
|
assert_eq!(3, list.length(), "List initialized with 3 elements has length of 3.");
|
|
list.clear();
|
|
assert_eq!(0, list.length(), "Cleared list has length of 0.");
|
|
}
|
|
|
|
#[test]
|
|
fn list_insert()
|
|
{
|
|
let mut list = List::with(natural(), vec![
|
|
*Natural::with(21),
|
|
*Natural::with(23),
|
|
*Natural::with(24),
|
|
]);
|
|
assert_eq!(3, list.length(), "List initialized with 3 elements has length of 3.");
|
|
list.insert(1, *Natural::with(22));
|
|
assert_eq!(21, list.length(), "First element has value of 21.");
|
|
assert_eq!(22, list.length(), "Second element has value of 22.");
|
|
assert_eq!(23, list.length(), "Third element has value of 23.");
|
|
}
|
|
|
|
#[test]
|
|
fn list_prepend()
|
|
{
|
|
let mut list = List::with(natural(), vec![
|
|
*Natural::with(1000),
|
|
*Natural::with(2000),
|
|
*Natural::with(3000),
|
|
]);
|
|
assert_eq!(3, list.length(), "List initialized with 3 elements has length of 3.");
|
|
list.prepend(*Natural::with(0));
|
|
assert_eq!(4, list.length(), "List of 3 elements has length of 4 after prepend.");
|
|
assert_eq!(0, Natural::try_from(list.at(0)).unwrap().get(), "First element in list has value 0.");
|
|
assert_eq!(1000, Natural::try_from(list.at(1)).unwrap().get(), "Second element in list has value 1000.");
|
|
}
|
|
|
|
#[test]
|
|
fn list_append()
|
|
{
|
|
let mut list = List::with(natural(), vec![
|
|
*Natural::with(1000),
|
|
*Natural::with(2000),
|
|
*Natural::with(3000),
|
|
]);
|
|
assert_eq!(3, list.length(), "List initialized with 3 elements has length of 3.");
|
|
list.append(*Natural::with(4000));
|
|
assert_eq!(4, list.length(), "List of 3 elements has length of 4 after prepend.");
|
|
assert_eq!(3000, Natural::try_from(list.at(2)).unwrap().get(), "Third element in list has value 3000.");
|
|
assert_eq!(4000, Natural::try_from(list.at(3)).unwrap().get(), "Last element in list has value 4000.");}
|
|
|
|
#[test]
|
|
fn list_set()
|
|
{
|
|
let mut list = List::with(natural(), vec![
|
|
*Natural::with(1),
|
|
*Natural::with(1),
|
|
*Natural::with(3),
|
|
]);
|
|
assert_eq!(3, list.length(), "List initialized with 3 elements has length of 3.");
|
|
list.set(1, *Natural::with(2));
|
|
assert_eq!(2, Natural::try_from(list.at(1)).unwrap().get(), "Second element in list has value 2.");
|
|
}
|
|
|
|
#[test]
|
|
fn list_remove()
|
|
{
|
|
let mut list = List::with(natural(), vec![
|
|
*Natural::with(0),
|
|
*Natural::with(1),
|
|
*Natural::with(2),
|
|
*Natural::with(3),
|
|
*Natural::with(4),
|
|
*Natural::with(5),
|
|
]);
|
|
assert_eq!(6, list.length(), "List initialized with 6 elements has length of 6.");
|
|
list.remove(5);
|
|
list.remove(0);
|
|
list.remove(2);
|
|
assert_eq!(3, list.length(), "List with 3/6 elements removed has length of 3.");
|
|
assert_eq!(1, Natural::try_from(list.at(0)).unwrap().get(), "First element in list is 1.");
|
|
assert_eq!(2, Natural::try_from(list.at(1)).unwrap().get(), "Second element in list is 2.");
|
|
assert_eq!(4, Natural::try_from(list.at(2)).unwrap().get(), "Last element in list is 4.");
|
|
}
|
|
|
|
#[test]
|
|
fn list_reserve()
|
|
{
|
|
let capacity :usize = 10;
|
|
let mut list = List::new(natural());
|
|
assert_eq!(0, list.capacity(), "List has initial capacity of 0.");
|
|
list.reserve(capacity);
|
|
assert_eq!(capacity, list.capacity(), "List has updated capacity.");
|
|
}
|