Exemplo n.º 1
0
  @Ignore // don't care for any reordering
  @Test(timeout = 10000)
  public void flatMapRangeAsyncLoop() {
    for (int i = 0; i < 2000; i++) {
      if (i % 10 == 0) {
        System.out.println("flatMapRangeAsyncLoop > " + i);
      }
      TestSubscriber<Integer> ts = new TestSubscriber<Integer>();
      Observable.range(0, 1000)
          .flatMap(
              new Func1<Integer, Observable<Integer>>() {
                @Override
                public Observable<Integer> call(Integer t) {
                  return Observable.just(t);
                }
              })
          .observeOn(Schedulers.computation())
          .subscribe(ts);

      ts.awaitTerminalEvent(2500, TimeUnit.MILLISECONDS);
      if (ts.getOnCompletedEvents().isEmpty()) {
        System.out.println(ts.getOnNextEvents().size());
      }
      ts.assertTerminalEvent();
      ts.assertNoErrors();
      List<Integer> list = ts.getOnNextEvents();
      assertEquals(1000, list.size());
      boolean f = false;
      for (int j = 0; j < list.size(); j++) {
        if (list.get(j) != j) {
          System.out.println(j + " " + list.get(j));
          f = true;
        }
      }
      if (f) {
        Assert.fail("Results are out of order!");
      }
    }
  }
Exemplo n.º 2
0
 /** Test predictions */
 @Test
 public void testPredict() {
   // get restaurant data
   DataSet restaurantData = null;
   try {
     restaurantData = DataSetTest.loadRestaurantData();
   } catch (IOException e) {
     Assert.fail("Could not load restaurant data from URL.");
   }
   // create tree
   DecisionTree t = new DecisionTree<String>(new Attribute<String>("Price", null));
   t.addBranch("$", new DecisionTreeLeaf("No"));
   t.addLeaf("$$", "Yes"); // alternate form, preferred
   t.addLeaf("$$$", "Maybe");
   // test
   Assert.assertEquals("No", t.predict(restaurantData.getExample(1)));
   Assert.assertEquals("Yes", t.predict(restaurantData.getExample(5)));
   Assert.assertEquals("Maybe", t.predict(restaurantData.getExample(0)));
   // test tree coverage
   for (Example e : restaurantData) {
     Assert.assertNotNull(t.predict(e));
   }
 }