Example #1
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()));
 }
Example #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()));
 }
Example #3
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));
 }
Example #4
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()));
 }
 public void sendFactory(Factory factory) {
   try {
     oos.writeObject(factory);
     oos.flush();
   } catch (IOException ioe) {
     Util.printExceptionToCommand(ioe);
   }
 }
 public void sendResource(Resource resource) {
   try {
     oos.writeObject(resource);
     oos.flush();
   } catch (IOException e) {
     Util.printExceptionToCommand(e);
     e.printStackTrace();
   }
 }
Example #7
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()));
 }
Example #8
0
  public MarketBtce(Currency cur1, Currency cur2) throws ExchangeError {
    super(cur1, cur2, "btce");

    // JSON mapper inialisation
    mapper = new ObjectMapper();
    mapper.configure(DeserializationConfig.Feature.FAIL_ON_UNKNOWN_PROPERTIES, false);
    mapper.configure(DeserializationConfig.Feature.USE_BIG_DECIMAL_FOR_FLOATS, false);

    // Ajout d'un deserializer d'ordre customis� pour passer de "[ prix, amount ]" dans le json �
    // "new Order(prix,amount,Type.XXX) en java"
    SimpleModule testModule = new SimpleModule("MyModule", new Version(1, 0, 0, null));
    testModule.addDeserializer(Order.class, new OrderDeserializer());
    mapper.registerModule(testModule);

    // Ajout d'un deserializer des types customis� pour passer de "ask"(resp. "bid") dans le json �
    // "Type.ASK" (resp. "Type.BID") en java
    testModule = new SimpleModule("MyModule2", new Version(1, 0, 0, null));
    testModule.addDeserializer(Type.class, new TypeDeserializer(true));
    mapper.registerModule(testModule);

    // Verification si la pair <cur1, cur2> est accepte par l'exchange
    URL fee_url;
    Fee f;
    try {
      fee_url =
          new URL(
              "https://btc-e.com/api/2/"
                  + cur1.name().toLowerCase()
                  + "_"
                  + cur2.name().toLowerCase()
                  + "/fee");
      String is = Util.getData(fee_url);
      f = mapper.readValue(is, Fee.class);
      Assert.checkPrecond(
          f.error == null,
          "BTC-E n'autorise pas la pair: <" + cur1.name() + "," + cur2.name() + ">");
      // On set les frais de transaction maintenant qu'on est sur que Btc-e autorise la paire
      // <cur1,cur2>
      fee_percent = Op.mult(f.trade, new Decimal("0.01"));
    } catch (JsonParseException e) {
      e.printStackTrace();
      throw new ExchangeError("JsonParseException: Erreur jackson");
    } catch (JsonMappingException e) {
      e.printStackTrace();
      throw new ExchangeError("JsonMappingException: Erreur jackson");
    } catch (IOException e) {
      e.printStackTrace();
      throw new ExchangeError("IOException: Erreur jackson");
    }
  }
 // reading a message
 public void run() {
   try {
     String line = br.readLine();
     while (line != null) {
       FactoryServerGUI.addMessage(
           socket.getInetAddress() + ":" + socket.getPort() + " - " + line);
       line = br.readLine();
     }
   } catch (IOException ioe) {
     serverListener.removeServerClientCommunicator(this);
     FactoryServerGUI.addMessage(
         socket.getInetAddress() + ":" + socket.getPort() + " - " + Constants.clientDisconnected);
     // this means that the socket is closed since no more lines are being received
     try {
       socket.close();
     } catch (IOException ioe1) {
       Util.printExceptionToCommand(ioe1);
     }
   }
 }
Example #10
0
  @Override
  public void updateTrades() throws ExchangeError {
    try {

      String is = getJsonTrades();
      last_trades =
          Util.filterRecentTrade(
              mapper.readValue(is, Trade[].class),
              trades); // On conserve uniquement les echanges pas encore check�s

    } catch (JsonParseException e) {
      e.printStackTrace();
      throw new ExchangeError("JsonParseException: Erreur jackson");
    } catch (JsonMappingException e) {
      e.printStackTrace();
      throw new ExchangeError("JsonMappingException: Erreur jackson");
    } catch (IOException e) {
      e.printStackTrace();
      throw new ExchangeError("IOException: Erreur jackson");
    }
  }
  /**
   * Initializes the gyro
   *
   * @throws GyroException If the initialization routine fails for any reason
   */
  public void initializeGyro() throws GyroException {
    // start a self-check
    int result = doTransaction(SENSOR_DATA_CMD | CHK_GENERATE_FAULTS_BIT);
    if (result != 1) {
      System.out.println(
          "Unexpected self-check response: 0x"
              + Integer.toHexString(result)
              + " errors: "
              + Util.joinStrings(", ", extractErrors(result)));
    }
    // wait for the fault conditions to occur
    try {
      Thread.sleep(50);
    } catch (InterruptedException ignored) {
    }

    // clear latched non-fault data
    doTransaction(SENSOR_DATA_CMD);

    // actually read the self-test data
    int selfCheckResult = doTransaction(SENSOR_DATA_CMD);
    if (extractStatus(selfCheckResult) != StatusFlag.SELF_TEST_DATA) {
      throw new GyroException("Gyro not in self test: 0x" + Integer.toHexString(selfCheckResult));
    }
    if (!extractErrors(selfCheckResult).containsAll(ALL_ERRORS)) {
      throw new GyroException(
          "Gyro self-test didn't include all errors: 0x" + Integer.toHexString(selfCheckResult));
    }

    // clear the latched self-test data
    selfCheckResult = doTransaction(SENSOR_DATA_CMD);
    if (extractStatus(selfCheckResult) != StatusFlag.SELF_TEST_DATA) {
      throw new GyroException(
          "Gyro second self test read failed: 0x" + Integer.toHexString(selfCheckResult));
    }
  }
Example #12
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));
 }
Example #13
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()));
 }
Example #14
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()));
 }
Example #15
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()));
 }
Example #16
0
 @Test
 public void setYComponentTest_IllegalCase() {
   testVector1.setY(Double.NaN);
   assertFalse(Util.fuzzyEquals(testVector1._Y(), Double.NaN));
 }
Example #17
0
 @Test
 public void setYComponentTest_LegalCase() {
   testVector1.setY(5);
   assertTrue(Util.fuzzyEquals(testVector1._Y(), 5));
 }
Example #18
0
 @Test
 public void simpleConstructorTest_ComponentsMatchZero() {
   Vector v = new Vector();
   assertTrue(Util.fuzzyEquals(v._X(), 0));
   assertTrue(Util.fuzzyEquals(v._Y(), 0));
 }
Example #19
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()));
 }
Example #20
0
 @Test
 public void distanceToTest_PerfectParameters() {
   double result = testVector1.getDistanceTo(testVector2);
   assertTrue(Util.fuzzyEquals(result, 15.811388300841896));
 }
Example #21
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));
 }
Example #22
0
 @Test
 public void magnitudeTest() {
   double vectorMagnitude = testVector1.getMagnitude();
   assertTrue(Util.fuzzyEquals(vectorMagnitude, Math.sqrt(200.0)));
 }
Example #23
0
 @Test
 public void dotTest_PerfectParameters() {
   double vectorProduct = testVector1.dotProduct(testVector2);
   assertTrue(Util.fuzzyEquals(vectorProduct, 0));
 }