coremem_types: list: minor test refactoring

This commit is contained in:
2022-07-20 14:37:08 -07:00
parent d0ae25e28b
commit 24b0b3d680

View File

@@ -206,6 +206,49 @@ mod test {
use crate::compound::peano::{P1, P2}; use crate::compound::peano::{P1, P2};
use core::cell::Cell; use core::cell::Cell;
#[test]
fn test_into_list() {
let list = (5u32, 4i32, 3f32).into_list();
assert_eq!(list.get::<P0>(), &5u32);
assert_eq!(list.get::<P1>(), &4i32);
assert_eq!(list.get::<P2>(), &3f32);
}
#[test]
fn test_list_default() {
let defaulted = List::<(i32, f32, u32)>::default();
let explicit = (0i32, 0f32, 0u32).into_list();
assert!(defaulted == explicit);
}
#[test]
fn get() {
let list = (5u32, 4i32, 3f32).into_list();
assert_eq!(list.get::<P0>(), &5u32);
assert_eq!(list.get::<P1>(), &4i32);
assert_eq!(list.get::<P2>(), &3f32);
}
#[test]
fn set() {
let mut list = List::<(u32, i32, f32)>::default();
list.set::<P0>(5u32);
assert_eq!(list.get::<P0>(), &5u32);
assert_eq!(list.get::<P1>(), &0i32);
assert_eq!(list.get::<P2>(), &0f32);
list.set::<P2>(3f32);
list.set::<P1>(4i32);
assert_eq!(list.get::<P0>(), &5u32);
assert_eq!(list.get::<P1>(), &4i32);
assert_eq!(list.get::<P2>(), &3f32);
}
#[derive(Default)] #[derive(Default)]
struct ApplyAccumulator<T> { struct ApplyAccumulator<T> {
delayed0: Cell<T>, delayed0: Cell<T>,
@@ -227,7 +270,7 @@ mod test {
#[test] #[test]
fn test_apply_single() { fn test_apply_single() {
let list = Node::new_terminal(5u32); let list = (5u32,).into_list();
let acc = ApplyAccumulator::default(); let acc = ApplyAccumulator::default();
list.apply_all(&acc); list.apply_all(&acc);
@@ -272,8 +315,7 @@ mod test {
#[test] #[test]
fn test_apply_2() { fn test_apply_2() {
let list = Node::new_terminal(V0(5u32)) let list = (V1(4f32), V0(5u32)).into_list();
.prepend(V1(4f32));
let acc = ApplyAccumulator::default(); let acc = ApplyAccumulator::default();
list.apply_all(&acc); list.apply_all(&acc);
@@ -284,9 +326,7 @@ mod test {
#[test] #[test]
fn test_apply_3() { fn test_apply_3() {
let list = Node::new_terminal(V0(5u32)) let list = (V0(2u32), V1(4f32), V0(5u32)).into_list();
.prepend(V1(4f32))
.prepend(V0(2u32));
let acc = ApplyAccumulator::default(); let acc = ApplyAccumulator::default();
list.apply_all(&acc); list.apply_all(&acc);
@@ -297,9 +337,7 @@ mod test {
#[test] #[test]
fn test_apply_at() { fn test_apply_at() {
let list = Node::new_terminal(V0(5u32)) let list = (V0(2u32), V1(4f32), V0(5u32)).into_list();
.prepend(V1(4f32))
.prepend(V0(2u32));
let acc = ApplyAccumulator::default(); let acc = ApplyAccumulator::default();
list.apply_at(0, &acc); list.apply_at(0, &acc);
@@ -327,59 +365,10 @@ mod test {
} }
} }
let list = Node::new_terminal(V0(5u32)) let list = (V0(2u32), V1(4f32), V0(5u32)).into_list();
.prepend(V1(4f32))
.prepend(V0(2u32));
assert_eq!(list.apply_at(0, ApplyAtRetOp), V0(2u32).to_flat()); assert_eq!(list.apply_at(0, ApplyAtRetOp), V0(2u32).to_flat());
assert_eq!(list.apply_at(1, ApplyAtRetOp), V1(4f32).to_flat()); assert_eq!(list.apply_at(1, ApplyAtRetOp), V1(4f32).to_flat());
assert_eq!(list.apply_at(2, ApplyAtRetOp), V0(5u32).to_flat()); assert_eq!(list.apply_at(2, ApplyAtRetOp), V0(5u32).to_flat());
} }
#[test]
fn get() {
let list = Node::new_terminal(3f32)
.prepend(4i32)
.prepend(5u32);
assert_eq!(list.get::<P0>(), &5u32);
assert_eq!(list.get::<P1>(), &4i32);
assert_eq!(list.get::<P2>(), &3f32);
}
#[test]
fn set() {
let mut list = List::<(u32, i32, f32)>::default();
list.set::<P0>(5u32);
assert_eq!(list.get::<P0>(), &5u32);
assert_eq!(list.get::<P1>(), &0i32);
assert_eq!(list.get::<P2>(), &0f32);
list.set::<P2>(3f32);
list.set::<P1>(4i32);
assert_eq!(list.get::<P0>(), &5u32);
assert_eq!(list.get::<P1>(), &4i32);
assert_eq!(list.get::<P2>(), &3f32);
}
#[test]
fn test_list_default() {
let type_level = List::<(i32, f32, u32)>::default();
let value_level = Node::new_terminal(0u32)
.prepend(0f32)
.prepend(0i32);
assert!(type_level == value_level);
}
#[test]
fn test_into_list() {
let list = (5u32, 4i32, 3f32).into_list();
assert_eq!(list.get::<P0>(), &5u32);
assert_eq!(list.get::<P1>(), &4i32);
assert_eq!(list.get::<P2>(), &3f32);
}
} }