newton 0.5.1

A Newtonian physics simulator written in Rust.
Documentation
// Newton - A Newtonian physics simulator written in Rust.
// Copyright (C) 2017 Cooper Paul EdenDay
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program.  If not, see <http://www.gnu.org/licenses/>.
//
// Electronic mail: cedenday@protonmail.com

use units::{self, Eval};
use vector::Vector;
use body::Body;

#[test]
fn simple_body() {
    let _ = Body::new(units::Time::new(1.0),
                      units::Mass::new(1.0),
                      Vector::new([units::Length::new(0.0); 3]),
                      None);
}

#[test]
fn body_get_position() {
    let position = Vector::new([units::Length::new(5.0); 3]);
    let body = Body::new(units::Time::new(1.0), units::Mass::new(1.0), position, None);
    assert_eq!(body.get_position(), position);
}

#[test]
fn body_get_velocity() {
    let velocity = Vector::new([units::Velocity::new(5.0); 3]);
    let body = Body::new(units::Time::new(1.0),
                         units::Mass::new(1.0),
                         Vector::new([units::Length::new(0.0); 3]),
                         Some(velocity));
    assert_eq!(body.get_velocity(), velocity);
}

#[test]
fn body_force() {
    let mut body = Body::new(units::Time::new(1.0),
                             units::Mass::new(2.0),
                             Vector::new([units::Length::new(0.0); 3]),
                             None);

    let force = Vector::new([units::Force::new(1.0); 3]);
    body.apply_force(force);

    let acceleration = Vector::new([units::Acceleration::new(0.5); 3]);
    assert_eq!(body.get_acceleration(), acceleration);
}

#[test]
fn body_direction() {
    let b0 = Body::new(units::Time::new(1.0),
                       units::Mass::new(1.0),
                       Vector::new([units::Length::new(0.0); 3]),
                       None);
    let b1 = Body::new(units::Time::new(1.0),
                       units::Mass::new(1.0),
                       Vector::new([units::Length::new(1.0); 3]),
                       None);

    let expected = Vector::new([units::Length::new(1.0); 3]).normalize();

    assert_eq!(b0.direction(&b1), expected);
}