#[derive(Debug)]
pub struct Beam {
pub bending_moment: f32,
pub length: f32,
pub moment_of_inertia: f32,
}
impl Beam {
pub fn new(bending_moment: f32, length: f32, moment_of_inertia: f32) -> Beam {
Beam {
bending_moment,
length,
moment_of_inertia
}
}
pub fn stress_calc(&self) -> f32 {
(self.bending_moment*self.length)/(self.moment_of_inertia)
}
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn good_output() {
let beam_1 = Beam::new(11.0, 2.0, 44.0);
assert_eq!(beam_1.stress_calc(), 0.5)
}
#[test]
fn bad_output() {
let beam_1 = Beam::new(11.0, 2.0, 44.0);
assert_ne!(beam_1.stress_calc(), 2.0)
}
}