Fix Direction Unit test
This commit is contained in:
parent
33e3949af6
commit
2d78cb2481
@ -27,14 +27,9 @@ namespace LinearAlgebra {
|
|||||||
public Direction(Angle horizontal, Angle vertical) {
|
public Direction(Angle horizontal, Angle vertical) {
|
||||||
this.horizontal = horizontal.inDegrees;
|
this.horizontal = horizontal.inDegrees;
|
||||||
this.vertical = vertical.inDegrees;
|
this.vertical = vertical.inDegrees;
|
||||||
|
this.Normalize();
|
||||||
}
|
}
|
||||||
|
|
||||||
// public Direction(float horizontal, float vertical) {
|
|
||||||
// this.horizontal = horizontal;
|
|
||||||
// this.vertical = vertical;
|
|
||||||
// //Normalize();
|
|
||||||
// }
|
|
||||||
|
|
||||||
public static Direction Degrees(float horizontal, float vertical) {
|
public static Direction Degrees(float horizontal, float vertical) {
|
||||||
Direction d = new() {
|
Direction d = new() {
|
||||||
horizontal = horizontal,
|
horizontal = horizontal,
|
||||||
@ -83,6 +78,33 @@ namespace LinearAlgebra {
|
|||||||
Vector3Float v = new(x, y, z);
|
Vector3Float v = new(x, y, z);
|
||||||
return v;
|
return v;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static bool operator ==(Direction d1, Direction d2) {
|
||||||
|
bool horizontalEq = d1.horizontal == d2.horizontal;
|
||||||
|
bool verticalEq = d1.vertical == d2.vertical;
|
||||||
|
return horizontalEq && verticalEq;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static bool operator !=(Direction d1, Direction d2) {
|
||||||
|
bool horizontalNEq = d1.horizontal != d2.horizontal;
|
||||||
|
bool verticalNEq = d1.vertical != d2.vertical;
|
||||||
|
return horizontalNEq || verticalNEq;
|
||||||
|
}
|
||||||
|
|
||||||
|
public override bool Equals(object obj) {
|
||||||
|
if (obj is not Direction d)
|
||||||
|
return false;
|
||||||
|
|
||||||
|
bool horizontalEq = this.horizontal == d.horizontal;
|
||||||
|
bool verticalEq = this.vertical == d.vertical;
|
||||||
|
return horizontalEq && verticalEq;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public override int GetHashCode() {
|
||||||
|
return (this.horizontal, this.vertical).GetHashCode();
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
@ -9,10 +9,12 @@ namespace LinearAlgebra.Test {
|
|||||||
|
|
||||||
[Test]
|
[Test]
|
||||||
public void Compare() {
|
public void Compare() {
|
||||||
Direction d = Direction.Degrees(45, 135);
|
Direction d1 = Direction.Degrees(45, 135);
|
||||||
|
Direction d2 = new(Angle.Degrees(45), Angle.Degrees(135));
|
||||||
bool r;
|
bool r;
|
||||||
r = d == new Direction(Angle.Degrees(45), Angle.Degrees(135));
|
r = d1 == d2;
|
||||||
Assert.True(r);
|
Assert.True(r);
|
||||||
|
Assert.AreEqual(d1, d2);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user