From fc4dd400064107f70229fdf94ea93318d6a167b3 Mon Sep 17 00:00:00 2001 From: Olivia Appleton Date: Wed, 14 Aug 2024 22:35:41 -0500 Subject: [PATCH] Fix some web changes --- README.rst | 2 +- docs/_static/test-rs.html | 73 ++++++++++++++++++------------------ docs/index.rst | 2 +- docs/rust.rst | 5 +++ rust/src/include/problems.rs | 70 +++++++++++++++++----------------- rust/src/lib.rs | 6 +-- rust/src/main.rs | 6 +-- 7 files changed, 86 insertions(+), 78 deletions(-) diff --git a/README.rst b/README.rst index a20deb89..10de4c58 100644 --- a/README.rst +++ b/README.rst @@ -110,7 +110,7 @@ Olivia's Project Euler Solutions and these tests not yet automated as in Nodejs and Bun. To run these tests yourself, |test-js-link| .. [3] While these solutions do run in most browsers, they need to be bundled with Pyodide 0.26.2+ first, and these tests are not yet automated as in CPython and pypy. To run these tests yourself, |test-py-link| -.. [4] This feature is in progress. While these solutions will run in most browsers, they need to be bundled with wasm-pack 0.2+ first, and these +.. [4] While these solutions will run in most browsers, they need to be bundled with wasm-pack 0.2+ first, and these tests are not yet automated as on non-web platforms. To run these tests yourself, |test-rs-link| Coverage diff --git a/docs/_static/test-rs.html b/docs/_static/test-rs.html index 4ebd1815..7a7c4154 100644 --- a/docs/_static/test-rs.html +++ b/docs/_static/test-rs.html @@ -11,49 +11,50 @@
diff --git a/docs/index.rst b/docs/index.rst index 4242b58c..07f2ac4d 100644 --- a/docs/index.rst +++ b/docs/index.rst @@ -202,7 +202,7 @@ Problems Solved +-----------+------------+------------+------------+------------+------------+------------+------------+ |:prob:`74` | | | | | |:py-d:`0074`| | +-----------+------------+------------+------------+------------+------------+------------+------------+ -|:prob:`76` |:c-d:`0076` |:cp-d:`0076`|:cs-s:`0076`|:ja-d:`0076`|:js-s:`0076`|:py-d:`0076`|:rs-d:`0076`| +|:prob:`76` |:c-d:`0076` |:cp-d:`0076`|:cs-s:`0076`|:ja-d:`0076`|:js-s:`0076`|:py-d:`0076`|:rs-s:`0076`| +-----------+------------+------------+------------+------------+------------+------------+------------+ |:prob:`77` | | | | | |:py-d:`0077`| | +-----------+------------+------------+------------+------------+------------+------------+------------+ diff --git a/docs/rust.rst b/docs/rust.rst index 9df0df17..0bd34e47 100644 --- a/docs/rust.rst +++ b/docs/rust.rst @@ -34,6 +34,11 @@ build or test processes. Alias for ``cargo clean``. +Live Tests +---------- + +To run these problems in your browser, :live-test:`rs` + Library Code ------------ diff --git a/rust/src/include/problems.rs b/rust/src/include/problems.rs index d523e467..90718dfe 100644 --- a/rust/src/include/problems.rs +++ b/rust/src/include/problems.rs @@ -16,50 +16,52 @@ use crate::p0357::p0357; use crate::p0836::p0836; type ProblemType = fn() -> Answer; -type ProblemRef<'a> = (&'a usize, ProblemType, bool); +type ProblemRef<'a> = (&'a ProblemType, bool); pub fn get_problem<'b>(n: usize) -> Option> { return match n { - 1 => Some(( &1, p0001, false)), - 2 => Some(( &2, p0002, false)), - 3 => Some(( &3, p0003, false)), - 4 => Some(( &4, p0004, false)), - 5 => Some(( &5, p0005, false)), - 6 => Some(( &6, p0006, false)), - 7 => Some(( &7, p0007, false)), - 8 => Some(( &8, p0008, false)), - 9 => Some(( &9, p0009, false)), - 10 => Some(( &10, p0010, false)), - 11 => Some(( &11, p0011, false)), - 12 => Some(( &12, p0012, false)), - 13 => Some(( &13, p0013, false)), - 14 => Some(( &14, p0014, false)), - 15 => Some(( &15, p0015, false)), - 16 => Some(( &16, p0016, false)), - 17 => Some(( &17, p0017, false)), - 18 => Some(( &18, p0018, false)), - 19 => Some(( &19, p0019, false)), - 20 => Some(( &20, p0020, false)), - 22 => Some(( &22, p0022, false)), - 24 => Some(( &24, p0024, false)), - 27 => Some(( &27, p0027, false)), - 34 => Some(( &34, p0034, false)), - 69 => Some(( &69, p0069, false)), - 76 => Some(( &76, p0076, false)), - 77 => Some(( &77, p0077, false)), - 87 => Some(( &87, p0087, false)), - 357 => Some((&357, p0357, true)), - 836 => Some((&836, p0836, false)), + 1 => Some((&p0001, false)), + 2 => Some((&p0002, false)), + 3 => Some((&p0003, false)), + 4 => Some((&p0004, false)), + 5 => Some((&p0005, false)), + 6 => Some((&p0006, false)), + 7 => Some((&p0007, false)), + 8 => Some((&p0008, false)), + 9 => Some((&p0009, false)), + 10 => Some((&p0010, false)), + 11 => Some((&p0011, false)), + 12 => Some((&p0012, false)), + 13 => Some((&p0013, false)), + 14 => Some((&p0014, false)), + 15 => Some((&p0015, false)), + 16 => Some((&p0016, false)), + 17 => Some((&p0017, false)), + 18 => Some((&p0018, false)), + 19 => Some((&p0019, false)), + 20 => Some((&p0020, false)), + 22 => Some((&p0022, false)), + 24 => Some((&p0024, false)), + 27 => Some((&p0027, true)), + 34 => Some((&p0034, false)), + 69 => Some((&p0069, false)), + 76 => Some((&p0076, false)), + 77 => Some((&p0077, false)), + 87 => Some((&p0087, false)), + 357 => Some((&p0357, true)), + 836 => Some((&p0836, false)), _ => None, }; } -pub fn generate_supported_problems() -> Vec { +pub fn generate_supported_problems(include_slow: bool) -> Vec { let mut supported_problems = Vec::new(); for n in 1..10000 { - if get_problem(n).is_some() { - supported_problems.push(n); + let Some((_, slow)) = get_problem(n) { + if !slow || include_slow { + supported_problems.push(n); + } } } diff --git a/rust/src/lib.rs b/rust/src/lib.rs index d843a18b..4ffda2ca 100644 --- a/rust/src/lib.rs +++ b/rust/src/lib.rs @@ -27,7 +27,7 @@ pub use crate::include::utils::{Answer,get_answer}; #[cfg(any(target_arch="wasm32", target_arch="wasm64"))] #[wasm_bindgen] pub fn run_problem(n: usize) -> JsValue { - let Some((_, problem_function, _)) = get_problem(n) else { panic!() }; + let Some((problem_function, _)) = get_problem(n) else { panic!() }; let answer = problem_function(); return match answer { Answer::String(e) => JsValue::from_str(&e), @@ -37,8 +37,8 @@ pub fn run_problem(n: usize) -> JsValue { #[cfg(any(target_arch="wasm32", target_arch="wasm64"))] #[wasm_bindgen] -pub fn get_problems() -> JsValue { - let problems = generate_supported_problems(); +pub fn get_problems(include_slow: bool) -> JsValue { + let problems = generate_supported_problems(include_slow); let js_array = Array::new_with_length(problems.len() as u32); for (i, &item) in problems.iter().enumerate() { diff --git a/rust/src/main.rs b/rust/src/main.rs index fbe774bb..38486abd 100644 --- a/rust/src/main.rs +++ b/rust/src/main.rs @@ -41,11 +41,11 @@ fn main() { for i in sieve { println!("{}", i); } - let supported = generate_supported_problems(); + let supported = generate_supported_problems(false); for id in supported { match get_problem(id) { - Some((_, func, _)) => { + Some((func, _)) => { let answer = get_answer(id); let result = func(); match (answer, result) { @@ -76,7 +76,7 @@ seq!(N in 01..=20 { // #[case::problem_357(357)] #[case::problem_836(836)] fn test_problem(#[case] id: usize) -> Result<(), String> { - let Some((_, func, _slow)) = get_problem(id) else { panic!() }; + let Some((func, _slow)) = get_problem(id) else { panic!() }; let answer = get_answer(id); let start = Instant::now(); let result = func();