Пример #1
0
 public int computeScoreOfGame(Frame[] frames) {
   int scoreOfGame = 0;
   for (Frame frame : frames) {
     scoreOfGame += frame.getScore();
   }
   return scoreOfGame;
 }
Пример #2
0
  // ==========================================================================
  /*@Test*/ public void testBasicCRUD() {
    // Parse a file with many broken enum/string columns
    Key k = Key.make("zip.hex");
    try {
      Frame fr = TestUtil.parseFrame(k, "smalldata/zip_code/zip_code_database.csv.gz");
      System.out.println(fr);

      StringBuilder sb = new StringBuilder();
      String[] fs = fr.toStringHdr(sb);
      int lim = Math.min(40, (int) fr.numRows());
      for (int i = 0; i < lim; i++) fr.toString(sb, fs, i);
      System.out.println(sb.toString());
    } finally {
      UKV.remove(k);
    }
  }
Пример #3
0
  @Test
  public void test() {
    Frame frame = null;
    try {
      Futures fs = new Futures();
      Random random = new Random();
      Vec[] vecs = new Vec[1];
      AppendableVec vec = new AppendableVec(Vec.newKey(), Vec.T_NUM);
      for (int i = 0; i < 2; i++) {
        NewChunk chunk = new NewChunk(vec, i);
        for (int r = 0; r < 1000; r++) chunk.addNum(random.nextInt(1000));
        chunk.close(i, fs);
      }
      vecs[0] = vec.layout_and_close(fs);
      fs.blockForPending();
      frame = new Frame(Key.<Frame>make(), null, vecs);

      // Make sure we test the multi-chunk case
      vecs = frame.vecs();
      assert vecs[0].nChunks() > 1;
      long rows = frame.numRows();
      Vec v = vecs[0];
      double min = Double.POSITIVE_INFINITY, max = Double.NEGATIVE_INFINITY, mean = 0, sigma = 0;
      for (int r = 0; r < rows; r++) {
        double d = v.at(r);
        if (d < min) min = d;
        if (d > max) max = d;
        mean += d;
      }
      mean /= rows;
      for (int r = 0; r < rows; r++) {
        double d = v.at(r);
        sigma += (d - mean) * (d - mean);
      }
      sigma = Math.sqrt(sigma / (rows - 1));

      double epsilon = 1e-9;
      assertEquals(max, v.max(), epsilon);
      assertEquals(min, v.min(), epsilon);
      assertEquals(mean, v.mean(), epsilon);
      assertEquals(sigma, v.sigma(), epsilon);
    } finally {
      if (frame != null) frame.delete();
    }
  }
Пример #4
0
 void checkStr(String s) {
   Env env = null;
   try {
     env = Exec2.exec(s);
     if (env.isAry()) { // Print complete frames for inspection
       Frame res = env.popAry();
       String skey = env.key();
       System.out.println(res.toStringAll());
       env.subRef(res, skey); // But then end lifetime
     } else {
       System.out.println(env.resultString());
     }
   } catch (IllegalArgumentException iae) {
     System.out.println(iae.getMessage());
   }
   if (env != null) env.remove_and_unlock();
   debug_print(s);
 }
Пример #5
0
 protected Frame createFrameWithScore(int score) {
   Frame frame1 = mock(Frame.class);
   when(frame1.getScore()).thenReturn(score);
   return frame1;
 }