From bc4d45fa639e32394081f726cbb1f093eb469b0a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Juan=20Manuel=20Tom=C3=A1s?= Date: Sun, 17 Jan 2021 18:08:45 -0300 Subject: Remove dead code --- src/poly.rs | 40 ++++------------------------------------ 1 file changed, 4 insertions(+), 36 deletions(-) (limited to 'src/poly.rs') diff --git a/src/poly.rs b/src/poly.rs index bae3a15..c76e481 100644 --- a/src/poly.rs +++ b/src/poly.rs @@ -1,18 +1,17 @@ mod iter; -use crate::number::Number; use iter::Iter; use std::fmt; use std::ops::{Add, Mul, Sub}; #[derive(PartialEq, Debug, Clone)] pub struct Poly { - data: Vec, + data: Vec, degree: usize, } impl Poly { - pub fn new(data: Vec) -> Poly { + pub fn new(data: Vec) -> Poly { let mut i = data.len() - 1; while data[i] == 0.0 && i > 0 { i -= 1; @@ -20,16 +19,6 @@ impl Poly { Poly { data, degree: i } } - fn mono(degree: usize, coefficient: Number) -> Poly { - if coefficient != 0.0 { - let mut p = vec![0.0; degree + 1]; - p[degree] = coefficient; - Poly::new(p) - } else { - Poly::new(vec![0.0]) - } - } - pub fn degree(&self) -> usize { self.degree } @@ -37,15 +26,6 @@ impl Poly { fn iter(&self) -> Iter { Iter::new(self.data.clone(), self.degree()) } - - fn is_zero(&self) -> bool { - for i in 0..self.data.len() { - if self.data[i] != 0.0 { - return false; - } - } - true - } } impl Add for &Poly { @@ -71,7 +51,7 @@ impl Mul for &Poly { let mut r = Vec::new(); for i in 0..other.degree() + 1 { let mut prefix = vec![0.0; i]; - let mut suffix: Vec = self + let mut suffix: Vec = self .iter() .take(self.degree() + 1) .map(|x| x * other.data[i]) @@ -121,21 +101,9 @@ mod tests { assert_eq!(&a - &b, Poly::new(vec![0.0, 1.0, 2.0])); } - #[test] - fn poly_is_zero() { - let p = Poly::new(vec![0.0; 5]); - assert_eq!(p.is_zero(), true); - } - - #[test] - fn poly_is_not_zero() { - let p = Poly::mono(5, 8.0); - assert_eq!(p.is_zero(), false); - } - #[test] fn degree_is_five() { - let p = Poly::mono(5, 2.0); + let p = Poly::new(vec![0.0, 0.0, 0.0, 0.0, 0.0, 2.0]); assert_eq!(p.degree(), 5); } -- cgit v1.2.3