@SuppressWarnings("MagicNumber")
  @Test
  public void checkDegreeBetweenPlayers() {
    GameProfile playerOne = new GameProfile();
    GameProfile playerTwo = new GameProfile();
    final double x1 = 100;
    playerOne.setX(x1);
    final double y1 = 100;
    playerOne.setY(y1);
    final double x2 = 150;
    playerTwo.setX(x2);
    final double y2 = 150;
    playerTwo.setY(y2);
    MoveActionStrategy actionStrategy = new MoveActionStrategy(gameServer);
    final double myDirection = 90;
    final double enemyDirection = 90;

    double playerOneDegree =
        Math.toDegrees(actionStrategy.getDegree(playerOne, myDirection, x2 - x1, y2 - y1));
    double playerTwoDegree =
        Math.toDegrees(actionStrategy.getDegree(playerTwo, enemyDirection, -x2 + x1, -y2 + y1));

    assertEquals("wrong degree for player 1", 45.0d, Math.floor(playerOneDegree), 0);
    assertEquals("wrong degree for player 2", 135.0d, Math.floor(playerTwoDegree), 0);
  }
Example #2
0
  // Note this is a bit of a integration test not a strict unit test
  @Test
  public void testFillingAMoreComplicatedBoundingRectangle() throws Exception {
    double xStart = 0.0;
    double xStop = 25.5;
    double yStart = 0.0;
    double yStop = 33.33;

    double xStep = 0.4;
    double yStep = 0.6;

    RectangularROI roi = new RectangularROI();
    roi.setPoint(Math.min(xStart, xStop), Math.min(yStart, yStop));
    roi.setLengths(Math.abs(xStop - xStart), Math.abs(yStop - yStart));

    RasterModel model = new RasterModel();
    model.setxStep(xStep);
    model.setyStep(yStep);

    // Get the point list
    IPointGenerator<RasterModel, Point> gen = service.createGenerator(model, roi);
    List<Point> pointList = gen.createPoints();

    int rows = (int) (Math.floor((xStop - xStart) / xStep) + 1);
    int cols = (int) (Math.floor((yStop - yStart) / yStep) + 1);
    // Check the list size
    assertEquals("Point list size should be correct", rows * cols, pointList.size());

    // Check some points
    assertEquals(new Point(0, xStart, 0, yStart), pointList.get(0));
    assertEquals(xStart + 3 * xStep, pointList.get(3).getX(), 1e-8);
    // TODO more

    GeneratorUtil.testGeneratorPoints(gen);
  }
  @Test
  public void testGetAverageAge3() {
    System.out.println("getAverageAge");

    dvdLibraryDao.create(dvd1);

    double result = Math.floor(dvdLibraryDao.getAverageAge());
    double expResult = dvd1.getReleaseDate().toInstant().getEpochSecond();
    expResult /= 1;
    expResult = new Date().toInstant().getEpochSecond() - expResult;
    expResult /= (3600 * 24);
    expResult = Math.floor(expResult);

    Assert.assertEquals(expResult, result, 0);
  }
  // Returns are randomly generated email id, part before the domain name
  private String shuffleEmail(String email) {

    String shuffledString = "";

    while (email.length() != 0) {
      int index = (int) Math.floor(Math.random() * email.length());
      char c = email.charAt(index);
      email = email.substring(0, index) + email.substring(index + 1);
      shuffledString += c;
    }

    return shuffledString;
  }
 /** Test of the D against B */
 @Test
 public void testPeriodgramIzAgainstD() {
   System.out.println("test slow Iz versus fast FFT computed D");
   final int N = 10;
   final double Tmin = 0.7;
   final double Tmax = 1.2;
   final double q = 10;
   final double[] y = new double[N];
   for (int i = 0; i < y.length; i++) y[i] = 1.0 * i;
   QuantisedPeriodogramFFT instance = new QuantisedPeriodogramFFT(N, Tmin, Tmax, q);
   instance.estimate(y);
   int M = instance.M(); // set M to minimum possible
   double W = q / M; // width of the search grid
   Complex[] D = instance.computeV(); // compute the vector D by FFT
   int K = (int) Math.floor((instance.fmax - instance.fmin) / W);
   for (int k = 0; k < K; k++) {
     double f = instance.fmin + W * k;
     assertEquals(instance.Iz(f), D[k].abs2(), 0.000001);
   }
 }
Example #6
0
  /**
   * Duplicate because I need DocumentLengthTEST!
   *
   * @param valueOf
   * @return [0] - passageCount in collection and [1] - the average legnth of passages
   * @throws URISyntaxException
   * @throws IOException
   */
  private double[] getNumberOfPassages(Integer windowSize) throws IOException, URISyntaxException {

    double count = 0.0;
    double avg = 0.0;
    double[] res = new double[2];

    List<String> documentLengthList =
        Utils.readFileToList("/DocumentLengthTEST.txt"); // I uses TEST!!! for testing only!!
    for (String length : documentLengthList) {

      double docLength = Double.valueOf(length);
      double ceil = Math.ceil(docLength / (double) windowSize);
      double floor = Math.floor(docLength / (double) windowSize);
      count += ceil;
      avg += ((floor * windowSize) + (docLength - (floor * windowSize)));
    }
    avg = avg / count;
    res[0] = count;
    res[1] = avg;
    return res;
  }
  @Test
  public void serializationUnencrypted() throws UnreadableWalletException {
    Utils.setMockClock();
    Date now = Utils.now();
    final ECKey key1 = new ECKey();
    Utils.rollMockClock(5000);
    final ECKey key2 = new ECKey();
    chain.importKeys(ImmutableList.of(key1, key2));
    List<Protos.Key> keys = chain.serializeToProtobuf();
    assertEquals(2, keys.size());
    assertArrayEquals(key1.getPubKey(), keys.get(0).getPublicKey().toByteArray());
    assertArrayEquals(key2.getPubKey(), keys.get(1).getPublicKey().toByteArray());
    assertArrayEquals(key1.getPrivKeyBytes(), keys.get(0).getSecretBytes().toByteArray());
    assertArrayEquals(key2.getPrivKeyBytes(), keys.get(1).getSecretBytes().toByteArray());
    long normTime = (long) (Math.floor(now.getTime() / 1000) * 1000);
    assertEquals(normTime, keys.get(0).getCreationTimestamp());
    assertEquals(normTime + 5000 * 1000, keys.get(1).getCreationTimestamp());

    chain = BasicKeyChain.fromProtobufUnencrypted(keys);
    assertEquals(2, chain.getKeys().size());
    assertEquals(key1, chain.getKeys().get(0));
    assertEquals(key2, chain.getKeys().get(1));
  }
Example #8
0
  @Test
  public void testInsertOrUpdateItemAssocs() {
    List<ItemAssocVO<Integer, Integer>> itemAssocs = new ArrayList<ItemAssocVO<Integer, Integer>>();

    Date date = new Date();
    // shave off milliseconds since they can't be stored in mysql
    long time = (long) Math.floor(date.getTime() / 1000) * 1000L;
    date = new Date(time);

    itemAssocs.add(
        new ItemAssocVO<Integer, Integer>(
            null,
            1,
            new ItemVO<Integer, Integer>(1, 1, 1),
            1,
            1.0,
            new ItemVO<Integer, Integer>(1, 2, 1),
            1,
            "sourceInfo",
            1,
            true,
            date));
    itemAssocs.add(
        new ItemAssocVO<Integer, Integer>(
            null,
            1,
            new ItemVO<Integer, Integer>(1, 2, 1),
            1,
            1.0,
            new ItemVO<Integer, Integer>(1, 3, 1),
            1,
            "sourceInfo\t\n\r\bwith escape characters\\",
            1,
            true,
            date));
    itemAssocs.add(
        new ItemAssocVO<Integer, Integer>(
            null,
            1,
            new ItemVO<Integer, Integer>(1, 3, 1),
            1,
            1.0,
            new ItemVO<Integer, Integer>(1, 4, 1),
            1,
            "sourceInfo",
            1,
            null,
            date));
    itemAssocs.add(
        new ItemAssocVO<Integer, Integer>(
            null,
            1,
            new ItemVO<Integer, Integer>(1, 4, 1),
            1,
            1.0,
            new ItemVO<Integer, Integer>(1, 5, 1),
            1,
            "sourceInfo",
            1,
            false,
            date));

    int noRowsAdded = itemAssocDAO.insertOrUpdateItemAssocs(itemAssocs);

    assertEquals(itemAssocs.size(), noRowsAdded);

    Iterator<ItemAssocVO<Integer, Integer>> it = itemAssocDAO.getItemAssocIterator(5000);
    int itemsEqual = 0;

    // need to set active since null gets the default value true when storing
    itemAssocs.get(2).setActive(true);

    while (it.hasNext()) {
      ItemAssocVO<Integer, Integer> itemAssocGot = it.next();
      itemAssocGot.setId(null);

      if (itemAssocs.contains(itemAssocGot)) itemsEqual++;
    }

    assertEquals(itemAssocs.size(), itemsEqual);
  }