Esempio n. 1
0
  @Test
  public void testFlatMapMaxConcurrent() {
    final int m = 4;
    final AtomicInteger subscriptionCount = new AtomicInteger();
    Observable<Integer> source =
        Observable.range(1, 10)
            .flatMap(
                new Func1<Integer, Observable<Integer>>() {
                  @Override
                  public Observable<Integer> call(Integer t1) {
                    return compose(Observable.range(t1 * 10, 2), subscriptionCount, m)
                        .subscribeOn(Schedulers.computation());
                  }
                },
                m);

    TestSubscriber<Integer> ts = new TestSubscriber<Integer>();

    source.subscribe(ts);

    ts.awaitTerminalEvent();
    ts.assertNoErrors();
    Set<Integer> expected =
        new HashSet<Integer>(
            Arrays.asList(
                10, 11, 20, 21, 30, 31, 40, 41, 50, 51, 60, 61, 70, 71, 80, 81, 90, 91, 100, 101));
    Assert.assertEquals(expected.size(), ts.getOnNextEvents().size());
    Assert.assertTrue(expected.containsAll(ts.getOnNextEvents()));
  }
Esempio n. 2
0
 @Test
 public void testWetherAfterAddingEntryAndRemovingItSizesAreChanging() {
   ImagesBuffer buffer = ImagesBuffer.getInstance();
   buffer.clear();
   buffer.addEntry("all", "cards.jpg");
   Assert.assertEquals(1, buffer.size());
   buffer.removeEntry("all");
   Assert.assertEquals(0, buffer.size());
 }
 /** Demonstrate toString() usage */
 @Test
 public void testToString() {
   // create tree
   DecisionTree t1 = new DecisionTree<String>(new Attribute<String>("Price", null));
   DecisionTree t2 = new DecisionTree<String>(new Attribute<String>("Est", null));
   DecisionTree t3 = new DecisionTree<String>(new Attribute<String>("Type", null));
   t1.addBranch("$$$", t2);
   t2.addBranch("0-10", t3);
   t2.addLeaf(">60", "No");
   t3.addLeaf("French", "Yes");
   // test
   Assert.assertEquals(
       "|- Price"
           + "\n"
           + "  |- $$$"
           + "\n"
           + "  |- Est"
           + "\n"
           + "    |- 0-10"
           + "\n"
           + "    |- Type"
           + "\n"
           + "      |- French -> Yes"
           + "\n"
           + "    |- >60 -> No"
           + "\n",
       t1.toString());
 }
Esempio n. 4
0
 @Test
 public void testGettingElementWhichIsNotPresent() {
   ImagesBuffer buffer = ImagesBuffer.getInstance();
   buffer.clear();
   BufferedImage im = buffer.getEntry("dasd");
   Assert.assertEquals(null, im);
 }
Esempio n. 5
0
 @Test
 public void formatTest1() {
   Formatter format = new Formatter();
   String result = formatter.format("{0:.2f}", 3.1415926);
   Assert.assertEquals(format.format("%.2f", 3.1415926).toString(), result);
   format.close();
 }
Esempio n. 6
0
  @Test
  public void testPCTiles() {
    // Simplified version of tests in runit_quantile_1_golden.R. There we test
    // probs=seq(0,1,by=0.01)
    Vec vec = vec(5, 8, 9, 12, 13, 16, 18, 23, 27, 28, 30, 31, 33, 34, 43, 45, 48, 161);
    double[] pctiles = vec.pctiles();
    // System.out.println(java.util.Arrays.toString(pctiles));
    Assert.assertEquals(13.75, pctiles[4], 1e-5);
    vec.remove();

    vec = vec(5, 8, 9, 9, 9, 16, 18, 23, 27, 28, 30, 31, 31, 34, 43, 43, 43, 161);
    pctiles = vec.pctiles();
    // System.out.println(java.util.Arrays.toString(pctiles));
    Assert.assertEquals(10.75, pctiles[4], 1e-5);
    vec.remove();
  }
 @Test
 public void studentInformationIsPrintedOutCorrectly() {
   GsonReader mockGson = mock(GsonReader.class);
   String studentNr = "13865669";
   Palautukset palautukset = new Palautukset();
   ArrayList<Palautus> palautusLista = new ArrayList<Palautus>();
   Palautus p = new Palautus();
   p.setEtunimi("Tony");
   p.setSukunimi("Kovanen");
   p.setGithubtunnus("rase-");
   p.setOpiskelijanumero("13865669");
   p.setTehtavat("1,2,3,4,5");
   p.setTehtavia(5);
   p.setTunteja(2);
   p.setViikko(1);
   palautusLista.add(p);
   Palautus b = new Palautus();
   b.setEtunimi("Bottleneck");
   b.setSukunimi("");
   b.setGithubtunnus("");
   b.setOpiskelijanumero("13865669");
   b.setTehtavat("Bottleneck");
   b.setTehtavia(0);
   b.setTunteja(0);
   b.setViikko(0);
   palautusLista.add(b);
   palautukset.setPalautukset(palautusLista);
   when(mockGson.read(studentNr)).thenReturn(palautukset);
   StudentInformation info = new StudentInformation(studentNr, mockGson);
   System.out.println(info);
   Assert.assertEquals(
       "Tony Kovanen 13865669\n\nminiprojekti: Bottleneck\n\nviikko 1: 5 tehtävää 1,2,3,4,5 aikaa kului 2 tuntia.\n\nyhteensä: 5 tehtävää 2 tuntia",
       info.toString());
 }
Esempio n. 8
0
 @Test
 public void testRemovingElementWhichIsNotPresent() {
   ImagesBuffer buffer = ImagesBuffer.getInstance();
   buffer.clear();
   buffer.removeEntry("dasd");
   Assert.assertEquals(0, buffer.size());
 }
  /** Test CassandraOutputStream.write(int); */
  private void testWriteWith(
      int blockSize,
      int subblockSize,
      int bufferSize,
      int totalBytesToWrite,
      int storedSubBlockesExpectation)
      throws Exception {

    StoreMock storeMock = new StoreMock();
    out =
        new CassandraOutputStream(
            null, storeMock, null, null, blockSize, subblockSize, null, bufferSize);

    Assert.assertEquals(0, out.getPos());

    for (int i = 0; i < totalBytesToWrite; i++) {
      out.write(i);
    }

    Assert.assertEquals(totalBytesToWrite, out.getPos());

    out.close();

    // Validate the expectations.
    Assert.assertEquals(storedSubBlockesExpectation, storeMock.storeSubBlockCount);

    // This is always one.
    Assert.assertEquals(1, storeMock.storeINodeCount);

    int totalBlocks = calculateTotalBlocks(totalBytesToWrite, blockSize);

    // Assert the total blocks per file
    Assert.assertEquals(totalBlocks, storeMock.inodesStored.get(0).getBlocks().length);

    // Assert SubBlocks per Block
    int totalSubBlocksPerBlock =
        blockSize % subblockSize == 0 ? blockSize / subblockSize : (blockSize / subblockSize) + 1;
    assertSubBlocksInBlocks(
        storeMock.inodesStored.get(0).getBlocks(),
        totalSubBlocksPerBlock,
        storedSubBlockesExpectation);

    // Assert and print for debug.
    for (Block block : storeMock.inodesStored.get(0).getBlocks()) {
      logger.info(block);
    }
  }
 @Test
 public void returningNullvaluedStudentReturnsASpecialToString() {
   GsonReader mockGson = mock(GsonReader.class);
   String studentNr = "13865669";
   when(mockGson.read(studentNr)).thenReturn(new Palautukset());
   StudentInformation info = new StudentInformation(studentNr, mockGson);
   Assert.assertEquals("Käyttäjää ei löytynyt", info.toString());
 }
Esempio n. 11
0
 @Test
 public void testAddingTheSameEntires() {
   ImagesBuffer buffer = ImagesBuffer.getInstance();
   buffer.clear();
   buffer.addEntry("all", "cards.jpg");
   buffer.addEntry("all", "cards.jpg");
   Assert.assertEquals(1, buffer.size());
 }
Esempio n. 12
0
 @Test
 public void testWetherAfterAddingEntryNumberOfEntriesEcountered() {
   ImagesBuffer buffer = ImagesBuffer.getInstance();
   buffer.clear();
   buffer.addEntry("all", "cards.jpg");
   int size = buffer.size();
   Assert.assertEquals(1, size);
 }
Esempio n. 13
0
  @Test
  public void extractorFieldNotFound() {
    class TestClass {
      public int a = 10;
    }

    String result = formatter.format("Test {0.a}, {0.b}", new TestClass());
    Assert.assertEquals("Test 10, ", result);
  }
  @Test
  public void shouldReturnUnparsableClassIfErrorOccursWhileParsing() {
    ClassParser parser = mock(ClassParser.class);
    when(parser.getClass("MyClassName")).thenThrow(new RuntimeException(new NotFoundException("")));

    builder = new JavaClassBuilder(parser);

    Assert.assertThat(builder.createClass("MyClassName"), instanceOf(UnparsableClass.class));
  }
Esempio n. 15
0
  @Test
  public void otherExtractorError() {
    class TestClass {
      public Object a = null;
    }

    String result = formatter.format("Test {0.a.b}", new TestClass());
    Assert.assertEquals("Test ", result);
  }
  /** Verify that the Blocks have the expected amount of SubBlocks. */
  private void assertSubBlocksInBlocks(
      Block[] blocks, int totalSubBlocksPerBlock, int storedSubBlockesExpectation) {
    int totalSubBlocksSoFar = 0;
    for (Block block : blocks) {
      if (storedSubBlockesExpectation - totalSubBlocksSoFar < totalSubBlocksPerBlock) {
        // This is the last block. Assert the remaining subBlocks
        Assert.assertEquals(
            storedSubBlockesExpectation - totalSubBlocksSoFar, block.subBlocks.length);
      } else {
        Assert.assertEquals(totalSubBlocksPerBlock, block.subBlocks.length);
      }

      // Keep accumulating
      totalSubBlocksSoFar += block.subBlocks.length;
    }

    // Validate the total Sub Blocks.
    Assert.assertEquals(storedSubBlockesExpectation, totalSubBlocksSoFar);
  }
Esempio n. 17
0
  @Test
  public void testAddingBufferedImageUnderKeyAndRetrievingIt() {
    ImagesBuffer buffer = ImagesBuffer.getInstance();
    buffer.addEntry("all", "cards.jpg");
    BufferedImage image = buffer.getEntry("all");
    Assert.assertNotNull(image);
    // buffer.splitImagesFromSource("cards.jpg",50,100);
    // CardNode node= new CardNode(new Card(Card.Name.ACE,Card.Suit.SPADE));

  }
Esempio n. 18
0
 /**
  * Run the String getRefreshTimeSeconds() method test.
  *
  * @throws Exception
  * @generatedBy CodePro at 12/15/14 3:52 PM
  */
 @Test
 public void testGetRefreshTimeSeconds_1() throws Exception {
   JobQueueManager fixture = new JobQueueManager();
   fixture.tableState = new TableViewState();
   fixture.tablePrefs = new TablePreferences(new LinkedList());
   fixture.setRefreshTimeSeconds("30");
   String result = fixture.getRefreshTimeSeconds();
   assertNotNull(result);
   Assert.assertEquals("30", fixture.getRefreshTimeSeconds());
 }
Esempio n. 19
0
 @Test
 public void testFuzzySearch() throws Exception {
   CertTypeService c = CertTypeService.getService();
   try {
     Assert.assertNotNull(c.fuzzySearch("id", "1"));
   } catch (Exception e) {
     // TODO Auto-generated catch block
     e.printStackTrace();
   }
 }
Esempio n. 20
0
 @Test(expected = RuntimeException.class)
 public void testPredictWithDepth() throws Exception {
   // get restaurant data
   DataSet restaurant = DataSetTest.loadRestaurantData();
   // create tree
   DecisionTree t1 = new DecisionTree<String>(new Attribute<String>("Price", null));
   DecisionTree t2 = new DecisionTree<String>(new Attribute<String>("Est", null));
   DecisionTree t3 = new DecisionTree<String>(new Attribute<String>("Type", null));
   t1.addBranch("$$$", t2);
   t2.addBranch("0-10", t3);
   t3.addLeaf("French", "Yes");
   // test
   Assert.assertEquals("Yes", t1.predict(restaurant.getExample(0)));
   Assert.assertEquals(
       null,
       t1.predict(
           restaurant.getExample(
               4))); // should throw RuntimeException since no branch is set for ">60"
 }
  /** Test CassandraOutputStream.write(buffer, off, len); */
  private void testWriteBufferWith(
      int blockSize,
      int subblockSize,
      int bufferSize,
      int totalBytesToWrite,
      int storedSubBlockesExpectation)
      throws Exception {

    // Null object here are not needed or irrelevant for this test case.
    // buffer size different from bytes to write is intentional.
    StoreMock storeMock = new StoreMock();
    out =
        new CassandraOutputStream(
            null, storeMock, null, null, blockSize, subblockSize, null, bufferSize);

    Assert.assertEquals(0, out.getPos());

    // Fill up the buffer
    byte[] buffer = new byte[totalBytesToWrite];
    for (int i = 0; i < totalBytesToWrite; i++) {
      buffer[i] = (byte) i;
    }

    // Invoke the method being tested.
    out.write(buffer, 0, totalBytesToWrite);

    Assert.assertEquals(totalBytesToWrite, out.getPos());

    out.close();

    // Validate the expectations.
    Assert.assertEquals(storedSubBlockesExpectation, storeMock.storeSubBlockCount);

    // This is always one.
    Assert.assertEquals(1, storeMock.storeINodeCount);

    int totalBlocks = calculateTotalBlocks(totalBytesToWrite, blockSize);

    // Assert the total blocks per file
    Assert.assertEquals(totalBlocks, storeMock.inodesStored.get(0).getBlocks().length);
  }
Esempio n. 22
0
  @Test
  public void moreComplexExctractor() {
    class TestClassA {
      public int a = 10;
    }

    class TestClassB {
      TestClassA b = new TestClassA();
    }

    String result = formatter.format("Test {0.b.a}", new TestClassB());
    Assert.assertEquals("Test 10", result);
  }
Esempio n. 23
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));
   }
 }
  @Test
  public void test35() throws Exception {

    driver.get(baseUrl + "/accountType/list");

    driver.findElement(By.xpath("//strong[text()='Direct Customer']")).click();

    driver.findElement(By.cssSelector("a.submit.edit > span")).click();
    driver.findElement(By.id("creditLimitAsDecimal")).clear();
    driver.findElement(By.id("creditLimitAsDecimal")).sendKeys("300.00");
    driver.findElement(By.cssSelector("a.submit.save > span")).click();
    driver.findElement(By.xpath("//strong[text()='Direct Customer']")).click();
    driver.findElement(By.cssSelector("a.submit.edit > span")).click();
    driver.findElement(By.id("creditLimitAsDecimal")).clear();
    driver.findElement(By.id("creditLimitAsDecimal")).sendKeys("200.00");
    driver.findElement(By.cssSelector("a.submit.save > span")).click();
    driver.findElement(By.xpath("//strong[text()='Direct Customer']")).click();

    Assert.assertEquals(driver.getPageSource().contains("US$200.00"), true);
  }
Esempio n. 25
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!");
      }
    }
  }
Esempio n. 26
0
 @Test
 public void formatterNothingToDoHere() {
   String result = formatter.format("Test", 1, 2, 3);
   Assert.assertEquals(result, "Test");
 }
Esempio n. 27
0
 @Test
 public void simpleFormat() {
   String result = formatter.format("Test {{ {0}, {1}, }} {{, {2} }}{{}}", 1, 2, 3);
   Assert.assertEquals(result, "Test { 1, 2, } {, 3 }{}");
 }
Esempio n. 28
0
 @Test
 public void formatterNullArgs() {
   String result = formatter.format("test{0}test", null);
   Assert.assertEquals("testtest", result);
 }
Esempio n. 29
0
 @Test
 public void formatTest2() {
   String result = formatter.format("{0:04d}", new BigInteger("31"));
   Assert.assertEquals("0031", result);
 }