beam_calc 0.1.1

A simple crate that calculates the stress on a beam.
Documentation
//! # beam_calc
//! 
//! `beam_calc` is a simple crate that calculates the stress on a beam. The purpose of this crate
//! is to practice publishing on crates.io, so it's neither optimized nor tested.


/// Calculates the stress on a beam using the following expression:
/// 
/// Create a new Beam object that contains the maximum bending moment, 
/// the length of the beam from the point of reference, and the moment of inertia of 
/// the beam with respect to its cross section.
/// 
/// # Examples
/// ```
/// use beam_calc::Beam;
/// 
/// let beam_1 = Beam::new(12.0, 3.12, 44.3);
/// let stress = beam_1.stress_calc();
/// 
/// assert_eq!(0.8451467, stress);
/// ```
/// 

    #[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)
    }
}