Remove unwrap operators

This commit is contained in:
Brendan Zabarauskas 2012-12-01 22:55:14 +10:00
parent 4ce43ff18e
commit 4515c9f7e0

View file

@ -7,35 +7,35 @@ use vec::{Vec3, Vec4};
#[test] #[test]
fn test_radians() { fn test_radians() {
assert Radians(0.0).to_degrees() == Degrees(0.0); assert Radians(0.0).to_degrees() == Degrees(0.0);
assert *Radians(pi / 4.0).to_degrees() == *Degrees(45.0); // Removing the unwrap operators causes an ICE. assert Radians(pi / 4.0).to_degrees() == Degrees(45.0);
assert *Radians(pi / 2.0).to_degrees() == *Degrees(90.0); // I think it only happens on operations where assert Radians(pi / 2.0).to_degrees() == Degrees(90.0);
assert *Radians(pi).to_degrees() == *Degrees(180.0); // Rust has to do a bit of type inference. assert Radians(pi).to_degrees() == Degrees(180.0);
assert *Radians(2.0 * pi).to_degrees() == *Degrees(360.0); assert Radians(2.0 * pi).to_degrees() == Degrees(360.0);
assert *Radians(5.0 * pi).to_degrees() == *Degrees(900.0); assert Radians(5.0 * pi).to_degrees() == Degrees(900.0);
assert *Radians(-pi).to_degrees() == *Degrees(-180.0); assert Radians(-pi).to_degrees() == Degrees(-180.0);
assert Radians(0.0).to_radians() == Radians(0.0); assert Radians(0.0).to_radians() == Radians(0.0);
assert *Radians(5.0 * pi).to_radians() == *Radians(5.0 * pi); assert Radians(5.0 * pi).to_radians() == Radians(5.0 * pi);
assert *Radians(-pi).to_radians() == *Radians(-pi); assert Radians(-pi).to_radians() == Radians(-pi);
assert *Radians(pi).wrap() == *Radians(pi); assert Radians(pi).wrap() == Radians(pi);
assert *Radians(3.0 * pi).wrap() == *Radians(pi); assert Radians(3.0 * pi).wrap() == Radians(pi);
assert *Radians(2.0 * pi).wrap() == *Radians(0.0); assert Radians(2.0 * pi).wrap() == Radians(0.0);
assert *Radians(-pi).wrap() == *Radians(-pi); // FIXME: should be in the domain of 0 to two_pi assert Radians(-pi).wrap() == Radians(-pi); // FIXME: should be in the domain of 0 to two_pi
assert *Radians(-3.0 * pi).wrap() == *Radians(-pi); // FIXME: should be in the domain of 0 to two_pi assert Radians(-3.0 * pi).wrap() == Radians(-pi); // FIXME: should be in the domain of 0 to two_pi
assert *Radians(-2.0 * pi).wrap() == *Radians(0.0); assert Radians(-2.0 * pi).wrap() == Radians(0.0);
assert *Radians(0.0).opposite() == *Radians(pi as float); assert Radians(0.0).opposite() == Radians(pi as float);
assert *Radians(pi / 2.0).opposite() == *Radians((pi / 2.0) * 3.0); assert Radians(pi / 2.0).opposite() == Radians((pi / 2.0) * 3.0);
assert *Radians(pi * 3.0).opposite() == *Radians(0.0); assert Radians(pi * 3.0).opposite() == Radians(0.0);
assert *Radians(-2.0 * pi).opposite() == *Radians(-pi); // FIXME: should be in the domain of 0 to two_pi assert Radians(-2.0 * pi).opposite() == Radians(-pi); // FIXME: should be in the domain of 0 to two_pi
assert *(Radians(pi) + Radians(pi)) == *Radians(2.0 * pi); assert Radians(pi) + Radians(pi) == Radians(2.0 * pi);
assert *(Radians(2.0 * pi) - Radians(pi)) == *Radians(pi); assert Radians(2.0 * pi) - Radians(pi) == Radians(pi);
assert *(Radians(pi) * 2.0) == *Radians(2.0 * pi); assert Radians(pi) * 2.0 == Radians(2.0 * pi);
assert *(Radians(pi) / 2.0) == *Radians(pi / 2.0); assert Radians(pi) / 2.0 == Radians(pi / 2.0);
assert *(Radians(3.0 * pi) % (2.0 * pi)) == *Radians(pi); assert Radians(3.0 * pi) % (2.0 * pi) == Radians(pi);
assert *(-Radians(pi)) == *Radians(-pi); assert -Radians(pi) == Radians(-pi);
assert fmt!("%s", Radians(1).to_str()) == ~"1 rad"; assert fmt!("%s", Radians(1).to_str()) == ~"1 rad";
} }
@ -61,17 +61,17 @@ fn test_degrees() {
assert Degrees(-450.0).wrap() == Degrees(-90.0); // FIXME: should be in the domain of 0 to 360 assert Degrees(-450.0).wrap() == Degrees(-90.0); // FIXME: should be in the domain of 0 to 360
assert Degrees(-360.0).wrap() == Degrees(0.0); assert Degrees(-360.0).wrap() == Degrees(0.0);
assert Degrees(0.0).opposite() == Degrees(180.0); assert Degrees(0.0).opposite() == Degrees(180.0);
assert Degrees(90.0).opposite() == Degrees(270.0); assert Degrees(90.0).opposite() == Degrees(270.0);
assert Degrees(540.0).opposite() == Degrees(0.0); assert Degrees(540.0).opposite() == Degrees(0.0);
assert Degrees(-360.0).opposite() == Degrees(-180.0); // FIXME: should be in the domain of 0 to 360 assert Degrees(-360.0).opposite() == Degrees(-180.0); // FIXME: should be in the domain of 0 to 360
assert (Degrees(180.0) + Degrees(180.0)) == Degrees(360.0); assert Degrees(180.0) + Degrees(180.0) == Degrees(360.0);
assert (Degrees(360.0) - Degrees(180.0)) == Degrees(180.0); assert Degrees(360.0) - Degrees(180.0) == Degrees(180.0);
assert (Degrees(360.0) * 2.0) == Degrees(720.0); assert Degrees(360.0) * 2.0 == Degrees(720.0);
assert (Degrees(180.0) / 2.0) == Degrees(90.0); assert Degrees(180.0) / 2.0 == Degrees(90.0);
assert (Degrees(540.0) % (360.0)) == Degrees(180.0); assert Degrees(540.0) % (360.0) == Degrees(180.0);
assert (-Degrees(180.0)) == Degrees(-180.0); assert -Degrees(180.0) == Degrees(-180.0);
assert fmt!("%s", Degrees(180.0).to_str()) == ~"180°"; assert fmt!("%s", Degrees(180.0).to_str()) == ~"180°";
} }