From 69a2026c843a278c2a1b2f48e0aced63ba0f89de Mon Sep 17 00:00:00 2001 From: Alivecow Date: Sat, 23 Nov 2024 13:33:51 +0100 Subject: [PATCH] fix: Make all polynomials monic in task fn --- src/tasks/tasks01/pfmath.rs | 2 +- src/utils/poly.rs | 16 +++++++++++++++- 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/src/tasks/tasks01/pfmath.rs b/src/tasks/tasks01/pfmath.rs index ea60e78..4fc686e 100644 --- a/src/tasks/tasks01/pfmath.rs +++ b/src/tasks/tasks01/pfmath.rs @@ -112,7 +112,7 @@ pub fn gfpoly_gcd(args: &Value) -> Result { let poly_a = Polynomial::from_c_array(&args["A"].clone()); let poly_b = Polynomial::from_c_array(&args["B"].clone()); - let result = gcd(poly_a, poly_b); + let result = gcd(poly_a.monic(), poly_b.monic()); Ok(result) } diff --git a/src/utils/poly.rs b/src/utils/poly.rs index 0be3b89..b820e01 100644 --- a/src/utils/poly.rs +++ b/src/utils/poly.rs @@ -1267,7 +1267,7 @@ mod tests { assert_eq!(json!(result.to_c_array()), expected); } - + #[test] fn test_poly_gcd() { let a = json!([ @@ -1304,4 +1304,18 @@ mod tests { assert_eq!(json!(result.to_c_array()), expected); } + + #[test] + fn test_poly_gcd_zero() { + let a = json!(["AAAAAAAAAAAAAAAAAAAAAA==",]); + let b = json!(["AAAAAAAAAAAAAAAAAAAAAA=="]); + let expected = json!(["AAAAAAAAAAAAAAAAAAAAAA=="]); + + let a: Polynomial = Polynomial::from_c_array(&a); + let b: Polynomial = Polynomial::from_c_array(&b); + + let result = gcd(a.monic(), b.monic()); + + assert_eq!(json!(result.to_c_array()), expected); + } } -- 2.49.1