Ejemplo n.º 1
0
 @Test
 public void extendedConstructorTest_ComponentsMatchGivenComponents_IllegalYComponent() {
   Vector v = new Vector(5, Double.NaN);
   assertTrue(Util.fuzzyEquals(v._X(), 5));
   assertFalse(Util.fuzzyEquals(v._Y(), 6));
   assertTrue(Util.fuzzyEquals(v._Y(), 0));
 }
Ejemplo n.º 2
0
 @Test
 public void getSumTest_PerfectParameters() {
   Vector v = new Vector(15, 5);
   Vector sumVector = testVector1.getSum(testVector2);
   assertTrue(Util.fuzzyEquals(sumVector._X(), v._X()));
   assertTrue(Util.fuzzyEquals(sumVector._Y(), v._Y()));
 }
Ejemplo n.º 3
0
 @Test
 public void GetUnitVectorInSameDirectionTest_LegalCase() {
   Vector v = new Vector(Math.sqrt(2) / 2, Math.sqrt(2) / 2);
   Vector result = testVector1.getUnitVectorInDirection();
   assertTrue(Util.fuzzyEquals(v._X(), result._X()));
   assertTrue(Util.fuzzyEquals(v._Y(), result._Y()));
 }
Ejemplo n.º 4
0
 @Test
 public void getDifferenceTest_PerfectParameters() {
   Vector v = new Vector(5, 15);
   Vector differenceVector = testVector1.getDifference(testVector2);
   assertTrue(Util.fuzzyEquals(differenceVector._X(), v._X()));
   assertTrue(Util.fuzzyEquals(differenceVector._Y(), v._Y()));
 }
Ejemplo n.º 5
0
 /**
  * Sets the angle of this direction to the given angle.
  *
  * @param angle The new angle for this direction.
  * @pre The given angle is not null. | angle != null
  * @post If this direction can have the given angle as its angle, then the angle of this direction
  *     is now equal to the given angle. | new.getAngle() == angle
  * @post The magnitude of this new direction is equal to one. | Util.fuzzyEquals(getMagnitude(),
  *     1.0)
  * @post The angle of this direction is a valid angle. | canHaveAsAngle(getAngle())
  */
 @Basic
 @Raw
 public void setAngle(Angle angle) {
   assert (canHaveAsAngle(angle));
   this.angle = angle;
   assert (getAngle().equals(angle));
   assert (Util.fuzzyEquals(getMagnitude(), 1.0));
   assert (canHaveAsAngle(getAngle()));
 }
Ejemplo n.º 6
0
 /**
  * Initializes this new direction with a default angle.
  *
  * @post The magnitude of this new direction is equal to one. | Util.fuzzyEquals(getMagnitude(),
  *     1.0)
  * @post The angle of this direction is a valid angle. | canHaveAsAngle(getAngle())
  */
 public Direction() {
   this(new Angle());
   assert (Util.fuzzyEquals(getMagnitude(), 1.0));
   assert (canHaveAsAngle(getAngle()));
 }
Ejemplo n.º 7
0
 /**
  * Initializes this new direction with a given angle.
  *
  * @param angle The given angle.
  * @pre The given angle is not null. | angle != null
  * @post The magnitude of this new direction is equal to one. | Util.fuzzyEquals(getMagnitude(),
  *     1.0)
  * @post The angle of this direction is a valid angle. | canHaveAsAngle(getAngle())
  */
 public Direction(Angle angle) {
   assert (angle != null);
   setAngle(angle);
   assert (Util.fuzzyEquals(getMagnitude(), 1.0));
   assert (canHaveAsAngle(getAngle()));
 }
Ejemplo n.º 8
0
 /**
  * Rotates this direction by the given angle.
  *
  * @pre The given angle is not null. | angle != null
  * @param angle The given angle.
  * @post The magnitude of this new direction is equal to one. | Util.fuzzyEquals(getMagnitude(),
  *     1.0)
  * @post The angle of this direction is a valid angle. | canHaveAsAngle(getAngle())
  */
 public void rotate(Angle angle) {
   assert (angle != null);
   getAngle().add(angle);
   assert (Util.fuzzyEquals(getMagnitude(), 1.0));
   assert (canHaveAsAngle(getAngle()));
 }
Ejemplo n.º 9
0
 @Test
 public void setYComponentTest_IllegalCase() {
   testVector1.setY(Double.NaN);
   assertFalse(Util.fuzzyEquals(testVector1._Y(), Double.NaN));
 }
Ejemplo n.º 10
0
 @Test
 public void setYComponentTest_LegalCase() {
   testVector1.setY(5);
   assertTrue(Util.fuzzyEquals(testVector1._Y(), 5));
 }
Ejemplo n.º 11
0
 @Test
 public void simpleConstructorTest_ComponentsMatchZero() {
   Vector v = new Vector();
   assertTrue(Util.fuzzyEquals(v._X(), 0));
   assertTrue(Util.fuzzyEquals(v._Y(), 0));
 }
Ejemplo n.º 12
0
 @Test
 public void byVectorConstructorTest_ComponentsMatchGivenVectorsComponents_PerfectParameters() {
   Vector v = new Vector(testVector1);
   assertTrue(Util.fuzzyEquals(v._X(), testVector1._X()));
   assertTrue(Util.fuzzyEquals(v._Y(), testVector1._Y()));
 }
Ejemplo n.º 13
0
 @Test
 public void extendedConstructorTest_ComponentsMatchGivenComponents_PerfectParameters() {
   Vector v = new Vector(5, 6);
   assertTrue(Util.fuzzyEquals(v._X(), 5));
   assertTrue(Util.fuzzyEquals(v._Y(), 6));
 }
Ejemplo n.º 14
0
 @Test
 public void distanceToTest_PerfectParameters() {
   double result = testVector1.getDistanceTo(testVector2);
   assertTrue(Util.fuzzyEquals(result, 15.811388300841896));
 }
Ejemplo n.º 15
0
 @Test
 public void magnitudeTest() {
   double vectorMagnitude = testVector1.getMagnitude();
   assertTrue(Util.fuzzyEquals(vectorMagnitude, Math.sqrt(200.0)));
 }
Ejemplo n.º 16
0
 @Test
 public void dotTest_PerfectParameters() {
   double vectorProduct = testVector1.dotProduct(testVector2);
   assertTrue(Util.fuzzyEquals(vectorProduct, 0));
 }
Ejemplo n.º 17
0
 @Test
 public void scaleByTest_PerfectParameters() {
   Vector scaleVector = testVector1.getScaledBy(2.0);
   assertTrue(Util.fuzzyEquals(scaleVector._X(), 20.0));
   assertTrue(Util.fuzzyEquals(scaleVector._Y(), 20.0));
 }