test stackless iteration
All checks were successful
buildbot/cargo fmt (1.72) Build done.
buildbot/cargo clippy (1.65) Build done.
buildbot/cargo doc (1.72) Build done.
buildbot/cargo clippy (1.72) Build done.
buildbot/cargo test (1.65) Build done.

This commit is contained in:
AF 2023-10-15 11:48:13 +00:00
parent 8818d0c53e
commit 8473208362

View File

@ -262,6 +262,8 @@ impl<'a> Monad<'a> for StacklessInstance {
#[cfg(test)]
mod stackless_test {
use crate::func::*;
use super::{test_suite, tests, Stackless};
use super::StacklessInstance as T;
@ -303,6 +305,17 @@ mod stackless_test {
}
}
fn iterate(n: u32) -> Stackless<'static, u32> {
T::iterate_mut((n, 0), |(a, b)| {
if a > 0 {
ControlFlow::Continue((a - 1, b + 1))
} else {
ControlFlow::Break(b)
}
.into()
})
}
#[test]
fn test_factorial() {
assert_eq!(factorial(10).evaluate(), 3628800);
@ -313,4 +326,10 @@ mod stackless_test {
let n = 1000;
assert_eq!(dumb(n).evaluate(), n);
}
#[test]
fn test_iterate() {
let n = 1000;
assert_eq!(iterate(n).evaluate(), n);
}
}