Пример #1
0
  // Test the change plan when trying to change a student plan
  @Test
  public void transferpairtest() {
    Backend b = new Backend();
    String[] args = new String[1];
    args[0] = "MasterBankAccounts.txt";

    tlist.clear();

    Transaction t = new Transaction();
    t.setCode("10");
    t.setMisc("A");
    t.setName("");

    Transaction t2 = new Transaction();
    t2.setCode("02");
    t2.setNum("00005");

    Transaction t3 = new Transaction();
    t3.setCode("00");

    tlist.add(t);
    tlist.add(t2);
    tlist.add(t3);

    b.load(args);
    b.setTransactions(tlist);
    b.handletransactions();
    assertEquals("Transfer transactions must come in pairs\n", outContent.toString());
  }
 @Test
 public void testGetSecondOrderFriends() {
   FacePamphletDatabase theBase = new FacePamphletDatabase();
   FacePamphletProfile test = new FacePamphletProfile("Test Profile");
   FacePamphletProfile jimmy = new FacePamphletProfile("Jimmy");
   FacePamphletProfile timmy = new FacePamphletProfile("Timmy");
   FacePamphletProfile shimmy = new FacePamphletProfile("Shimmy");
   FacePamphletProfile joseph = new FacePamphletProfile("Joseph");
   FacePamphletProfile mom = new FacePamphletProfile("Your Mother");
   theBase.addProfile(test);
   theBase.addProfile(jimmy);
   theBase.addProfile(timmy);
   theBase.addProfile(shimmy);
   theBase.addProfile(joseph);
   theBase.addProfile(mom);
   jimmy.addFriend(timmy);
   jimmy.addFriend(mom);
   timmy.addFriend(shimmy);
   timmy.addFriend(joseph);
   timmy.addFriend(timmy);
   test.addFriend(jimmy);
   test.addFriend(timmy);
   ArrayList<String> testList = new ArrayList<String>();
   testList.add("Timmy");
   testList.add("Shimmy");
   testList.add("Joseph");
   testList.add("Your Mother");
   assertEquals(testList, test.getSecondOrderFriends());
 }
Пример #3
0
  @Test
  public void fromIterable() {
    ArrayList<String> items = new ArrayList<>();
    items.add("one");
    items.add("two");
    items.add("three");

    assertEquals((Long) 3L, Observable.fromIterable(items).count().toBlocking().single());
    assertEquals("two", Observable.fromIterable(items).skip(1).take(1).toBlocking().single());
    assertEquals("three", Observable.fromIterable(items).takeLast(1).toBlocking().single());
  }
 @Test
 public void testGetFriendsOf() {
   FacePamphletProfile test = new FacePamphletProfile("Test Profile");
   FacePamphletProfile jimmy = new FacePamphletProfile("Jimmy");
   FacePamphletProfile timmy = new FacePamphletProfile("Timmy");
   FacePamphletProfile mom = new FacePamphletProfile("Your Mother");
   test.addFriend(jimmy);
   jimmy.addFriend(timmy);
   jimmy.addFriend(mom);
   ArrayList<String> testList = new ArrayList<String>();
   testList.add("Timmy");
   testList.add("Your Mother");
   assertEquals(testList, test.getFriendsOf(jimmy));
 }
  @Test
  public void testBasic() {
    ArrayList<String> al = new ArrayList<>();
    al.add("x");
    al.add("y");
    al.add("z");

    assertThat(al.length(), is(3));
    assertThat(al.get(1), is("y"));
    assertThat(al.removeLast(), is("z"));
    assertThat(al.remove("y"), is(true));
    assertThat(al.length(), is(1));
    assertThat(al.remove("a"), is(false));
  }
Пример #6
0
  @Before
  public void init() {
    alist.add(a1);
    alist.add(a2);
    alist.add(a3);
    alist.add(a4);
    alist.add(a5);
    alist.add(a6);
    alist.add(a7);
    alist.add(a8);
    alist.add(a9);

    System.setOut(new PrintStream(outContent));
    System.setErr(new PrintStream(errContent));
  }
 @Test
 public void ataqueDe10ElfosNoturnosA10AnosSo3AtacamE29AnoesRecebemAtaques() {
   ExercitoDeElfos exercito = new ExercitoDeElfos();
   ArrayList<Dwarf> dwarves = new ArrayList<Dwarf>();
   for (int i = 0; i < 10; i++) {
     dwarves.add(new Dwarf("" + i));
     exercito.alistarElfo(new ElfoNoturno("" + i));
   }
   exercito.reunirElfosVivoEAtacarDwarves(dwarves);
   for (int i = 0; i < 10; i++) {
     if (i == 9) {
       assertEquals(90.0, dwarves.get(i).getVida(), .0);
       break;
     }
     assertEquals(80.0, dwarves.get(i).getVida(), .0);
   }
   exercito.reunirElfosVivoEAtacarDwarves(dwarves);
   for (int i = 0; i < 10; i++) {
     if (i == 9) {
       assertEquals(70.0, dwarves.get(i).getVida(), .0);
       break;
     }
     assertEquals(60.0, dwarves.get(i).getVida(), .0);
   }
 }
Пример #8
0
 /** helper method to insert elements in an iterator into a list. */
 private ArrayList<Position> convertIteration2List(Iterator<Position> iter) {
   neighborhood = new ArrayList<Position>();
   while (iter.hasNext()) {
     p = iter.next();
     neighborhood.add(p);
   }
   return neighborhood;
 }
Пример #9
0
  @Test
  public void string_formats_compatible_no_prefix() throws IOException {
    ArrayList keys = new ArrayList();
    for (int i = 0; i < 1000; i++) {
      keys.add(TT.randomString(10 + new Random().nextInt(100), 0));
    }

    checkStringSerializers(keys);
  }
Пример #10
0
  @Test
  public void string_formats_compatible_equal_size() throws IOException {
    ArrayList keys = new ArrayList();
    for (int i = 0; i < 1000; i++) {
      keys.add("common prefix " + TT.randomString(10, 0));
    }

    checkStringSerializers(keys);
  }
Пример #11
0
 private HostMessenger createHostMessenger(int index, boolean start) throws Exception {
   HostMessenger.Config config = new HostMessenger.Config();
   config.internalPort = config.internalPort + index;
   config.zkInterface = "127.0.0.1:" + (2181 + index);
   HostMessenger hm = new HostMessenger(config);
   createdMessengers.add(hm);
   if (start) {
     hm.start();
   }
   return hm;
 }
Пример #12
0
 /**
  * Test.
  *
  * @throws Throwable throwable
  */
 @Test
 public void test() throws Throwable {
   // generate reference result
   result = query(QUERY);
   // generate results to be compared
   final ArrayList<Query> queries = new ArrayList<>();
   for (int i = 0; i < 10; i++) queries.add(new Query());
   for (final Query q : queries) q.start();
   for (final Query q : queries) q.join();
   if (error != null) throw error;
 }
 @Test
 public void ataqueDe6ElfosA6AnoesResultaEmUmAtaqueDeCadaIntercalado() {
   ExercitoDeElfos exercito = new ExercitoDeElfos();
   ArrayList<Dwarf> dwarves = new ArrayList<Dwarf>();
   for (int i = 3; i < 6; i++) {
     dwarves.add(new Dwarf("" + i));
     exercito.alistarElfo(new ElfoNoturno("" + i));
   }
   for (int i = 0; i < 3; i++) {
     dwarves.add(new Dwarf("" + i));
     exercito.alistarElfo(new ElfoVerde("" + i));
   }
   exercito.alterarEstrategiaDeAtaque(new EstrategiaIntercalada());
   exercito.reunirElfosVivoEAtacarDwarves(dwarves);
   for (int i = 0; i < 36; i++) {
     assertEquals(
         true,
         i % 2 == 0
             ? exercito.getOrdemDoUltimoAtaque().get(i) instanceof ElfoVerde
             : exercito.getOrdemDoUltimoAtaque().get(i) instanceof ElfoNoturno);
   }
 }
 @Test
 public void ataqueDe5ElfosACincoAnoes() {
   ExercitoDeElfos exercito = new ExercitoDeElfos();
   ArrayList<Dwarf> dwarves = new ArrayList<Dwarf>();
   for (int i = 0; i < 5; i++) {
     dwarves.add(new Dwarf("" + i));
     exercito.alistarElfo(new ElfoVerde("" + i));
   }
   exercito.reunirElfosVivoEAtacarDwarves(dwarves);
   for (int i = 0; i < 5; i++) {
     assertEquals(60.0, dwarves.get(i).getVida(), .0);
   }
 }
 @Test
 public void
     ataqueDe4ElfosA4AnoesResultaEm8PrimeirosAtaquesDeElfosVerdesE8UltimosEmAtaquesDeElfosNoturnos() {
   ExercitoDeElfos exercito = new ExercitoDeElfos();
   ArrayList<Dwarf> dwarves = new ArrayList<Dwarf>();
   for (int i = 2; i < 4; i++) {
     dwarves.add(new Dwarf("" + i));
     exercito.alistarElfo(new ElfoNoturno("" + i));
   }
   for (int i = 0; i < 2; i++) {
     dwarves.add(new Dwarf("" + i));
     exercito.alistarElfo(new ElfoVerde("" + i));
   }
   exercito.alterarEstrategiaDeAtaque(new EstrategiaGreenFirst());
   exercito.reunirElfosVivoEAtacarDwarves(dwarves);
   for (int i = 0; i < 16; i++) {
     assertEquals(
         true,
         i < 8
             ? exercito.getOrdemDoUltimoAtaque().get(i) instanceof ElfoVerde
             : exercito.getOrdemDoUltimoAtaque().get(i) instanceof ElfoNoturno);
   }
 }
Пример #16
0
    @Override
    public ArrayList<String> call(JobContext jc) {
      String inputFile = "src/test/resources/testweet.json";
      SQLContext sqlctx = jc.sqlctx();
      DataFrame input = sqlctx.jsonFile(inputFile);
      input.registerTempTable("tweets");

      DataFrame topTweets =
          sqlctx.sql("SELECT text, retweetCount FROM tweets ORDER BY retweetCount LIMIT 10");
      ArrayList<String> tweetList = new ArrayList<>();
      for (Row r : topTweets.collect()) {
        tweetList.add(r.toString());
      }
      return tweetList;
    }
 @Test
 public void ataqueDe6ElfosACincoAnoesMasUmElfoEstaMortoENaoAtaca() {
   ExercitoDeElfos exercito = new ExercitoDeElfos();
   ArrayList<Dwarf> dwarves = new ArrayList<Dwarf>();
   for (int i = 0; i < 5; i++) {
     dwarves.add(new Dwarf("" + i));
     exercito.alistarElfo(new ElfoVerde("" + i));
   }
   Elfo elfinhoSpec = new Elfo("Elfinho");
   elfinhoSpec.perderVida(200); // E Morreu...
   exercito.alistarElfo(elfinhoSpec);
   exercito.reunirElfosVivoEAtacarDwarves(dwarves);
   for (int i = 0; i < 5; i++) {
     assertEquals(60.0, dwarves.get(i).getVida(), .0);
   }
 }
Пример #18
0
  @Test
  public void test_basic_long_stack() throws IOException {
    // dirty hack to make sure we have lock
    engine.lock.writeLock().lock();
    final long max = 150;
    ArrayList<Long> list = new ArrayList<Long>();
    for (long i = 1; i < max; i++) {
      engine.longStackPut(TEST_LS_RECID, i);
      list.add(i);
    }

    Collections.reverse(list);
    commit();

    assertEquals(list, getLongStack(TEST_LS_RECID));
  }
  @Test
  public void testAdd() {
    ArrayList<String> al = new ArrayList<>("x0");

    for (int i = 1; i < 38; i++) {
      al.add(("x" + i).intern());
    }

    assertThat(al.length(), is(38));
    assertThat(al.get(0), is("x0"));
    assertThat(al.get(1), is("x1"));
    assertThat(al.get(37), is("x37"));

    assertThat(al.removeLast(), is("x37"));
    assertThat(al.remove("x2"), is(true));
    assertThat(al.remove("x"), is(false));
    assertThat(al.length(), is(36));
  }
Пример #20
0
  @Test
  public void appendMustCorrectlyMoveChildrenInsideOneParentElement() {
    Document doc = new Document("");
    Element body = doc.appendElement("body");
    body.appendElement("div1");
    body.appendElement("div2");
    final Element div3 = body.appendElement("div3");
    div3.text("Check");
    final Element div4 = body.appendElement("div4");

    ArrayList<Element> toMove = new ArrayList<Element>();
    toMove.add(div3);
    toMove.add(div4);

    body.insertChildren(0, toMove);

    String result = doc.toString().replaceAll("\\s+", "");
    assertEquals("<body><div3>Check</div3><div4></div4><div1></div1><div2></div2></body>", result);
  }
Пример #21
0
  @Test
  public void testOfTypeWithPolymorphism() {
    ArrayList<Integer> l1 = new ArrayList<>();
    l1.add(1);
    LinkedList<Integer> l2 = new LinkedList<>();
    l2.add(2);

    @SuppressWarnings("rawtypes")
    Observable<List> observable = Observable.<Object>just(l1, l2, "123").ofType(List.class);

    Subscriber<Object> observer = TestHelper.mockSubscriber();

    observable.subscribe(observer);

    verify(observer, times(1)).onNext(l1);
    verify(observer, times(1)).onNext(l2);
    verify(observer, never()).onNext("123");
    verify(observer, never()).onError(org.mockito.Matchers.any(Throwable.class));
    verify(observer, times(1)).onComplete();
  }
Пример #22
0
  List<Long> getLongStack(long recid) {

    ArrayList<Long> ret = new ArrayList<Long>();

    long pagePhysid = engine.index.getLong(recid * 8) & StorageDirect.PHYS_OFFSET_MASK;

    while (pagePhysid != 0) {
      final byte numberOfRecordsInPage = engine.phys.getByte((int) (pagePhysid % Volume.BUF_SIZE));

      for (int rec = numberOfRecordsInPage; rec > 0; rec--) {
        final long l = engine.phys.getLong((int) (pagePhysid % Volume.BUF_SIZE + rec * 8));
        ret.add(l);
      }

      // read location of previous page
      pagePhysid =
          engine.phys.getLong((int) (pagePhysid % Volume.BUF_SIZE))
              & StorageDirect.PHYS_OFFSET_MASK;
    }

    return ret;
  }
Пример #23
0
  @Test
  public void recover_with_interrupt() throws InterruptedException {
    int scale = TT.scale();
    if (scale == 0) return;
    e = openEngine();
    if (!e.canRollback()
        || e instanceof StoreHeap) // TODO engine might have crash recovery, but no rollbacks
    return;

    // fill recids
    final int max = scale * 1000;
    final ArrayList<Long> recids = new ArrayList<Long>();
    final AtomicLong a = new AtomicLong(10);
    final long counterRecid = e.put(a.get(), Serializer.LONG);
    Random r = new Random(a.get());
    for (int j = 0; j < max; j++) {
      byte[] b = new byte[r.nextInt(100000)];
      r.nextBytes(b);
      long recid = e.put(b, Serializer.BYTE_ARRAY_NOSIZE);
      recids.add(recid);
    }

    e.commit();

    long endTime = TT.nowPlusMinutes(10);

    while (endTime > System.currentTimeMillis()) {

      final CountDownLatch latch = new CountDownLatch(1);
      Thread t =
          new Thread() {
            @Override
            public void run() {
              try {
                for (; ; ) {
                  long A = a.incrementAndGet();
                  Random r = new Random(A);
                  e.update(counterRecid, A, Serializer.LONG);

                  for (long recid : recids) {
                    byte[] b = new byte[r.nextInt(100000)];
                    r.nextBytes(b);
                    e.update(recid, b, Serializer.BYTE_ARRAY_NOSIZE);
                  }
                  e.commit();
                }
              } finally {
                latch.countDown();
              }
            }
          };
      t.start();
      Thread.sleep(5000);
      t.stop();
      latch.await();
      if (!e.isClosed()) {
        close();
      }

      // reopen and check the content
      e = openEngine();

      // check if A-1 was commited
      long A = e.get(counterRecid, Serializer.LONG);
      assertTrue("" + A + " - " + a.get(), A == a.get() || A == a.get() - 1);
      r = new Random(A);
      for (long recid : recids) {
        byte[] b = new byte[r.nextInt(100000)];
        r.nextBytes(b);
        byte[] b2 = e.get(recid, Serializer.BYTE_ARRAY_NOSIZE);
        assertTrue("Data were not commited recid=" + recid, Arrays.equals(b, b2));
      }
      a.set(A);
    }
    e.close();
  }
 private static Collection<InetAddress> makeAddrs(String... hosts) throws UnknownHostException {
   ArrayList<InetAddress> addrs = new ArrayList<InetAddress>(hosts.length);
   for (String host : hosts) addrs.add(InetAddress.getByName(host));
   return addrs;
 }
Пример #25
0
  public PalindromeTest() {
    ArrayList<String> words = new ArrayList<String>();
    ArrayList<String> palis;

    try {
      for (String line : Files.readAllLines(Paths.get("com/jsanders/web2"))) {
        words.add(line);
      }
    } catch (IOException ex) {
      System.out.println("IO error");
      System.exit(1);
    }

    palis = Palindrome.palindromes(words);
    assertEquals(palis.size(), 161, 0.01);

    int shortest = Word.shortestLength(words);
    assertEquals(shortest, 1, 0.01);

    int longest = Word.longestLength(words);
    assertEquals(longest, 24, 0.01);

    ArrayList<String> shortestWords = Word.shortestWords(words);
    assertEquals(shortestWords.size(), 52, 0.01);

    ArrayList<String> longestWords = Word.longestWords(words);
    assertEquals(longestWords.size(), 5, 0.01);

    int totalWords = Word.totalWords(words);
    double avgLen = Word.averageLength(words);

    assertEquals(totalWords, 235886, 0.01);
    assertEquals(avgLen, 9.56, 0.01);

    ArrayList<Double> letterFreq = Word.letterFrequency(words);
    assertEquals(letterFreq.get(0), 0.087, 0.01);

    double properFreq = Word.properFrequency(words);
    assertEquals(properFreq, 0.106, 0.01);

    ArrayList<Integer> startFreq = Word.startFrequency(words);
    assertEquals(startFreq.get(0), 17096, 0.01);

    ArrayList<String> sameStartEnd = Word.startEndWords(words);
    assertEquals(sameStartEnd.size(), 11505, 0.01);

    try {
      PrintWriter f = new PrintWriter("short.txt");
      for (String w : shortestWords) f.println(w);
      f.close();

      f = new PrintWriter("long.txt");
      for (String w : longestWords) f.println(w);
      f.close();

      f = new PrintWriter("same.txt");
      for (String w : sameStartEnd) f.println(w);
      f.close();

      f = new PrintWriter("statistics.txt");
      f.println("avg word len: " + avgLen);
      f.println("freq of letters: " + letterFreq);
      f.println("freq of proper nouns/names: " + properFreq);
      f.println("words that start with each letter:: " + startFreq);

      f.close();
    } catch (IOException ex) {
      System.out.println("IO error");
      System.exit(1);
    }
  }
Пример #26
0
  @Test
  public void testRangeTombstones() throws IOException, ExecutionException, InterruptedException {
    Keyspace keyspace = Keyspace.open(KEYSPACE1);
    ColumnFamilyStore cfs = keyspace.getColumnFamilyStore("Standard2");
    cfs.clearUnsafe();

    // disable compaction while flushing
    cfs.disableAutoCompaction();

    final CFMetaData cfmeta = cfs.metadata;
    Directories dir = cfs.directories;

    ArrayList<DecoratedKey> keys = new ArrayList<DecoratedKey>();

    for (int i = 0; i < 4; i++) {
      keys.add(Util.dk("" + i));
    }

    ArrayBackedSortedColumns cf = ArrayBackedSortedColumns.factory.create(cfmeta);
    cf.addColumn(Util.column("01", "a", 1)); // this must not resurrect
    cf.addColumn(Util.column("a", "a", 3));
    cf.deletionInfo()
        .add(
            new RangeTombstone(
                Util.cellname("0"),
                Util.cellname("b"),
                2,
                (int) (System.currentTimeMillis() / 1000)),
            cfmeta.comparator);

    SSTableWriter writer =
        new SSTableWriter(
            cfs.getTempSSTablePath(dir.getDirectoryForNewSSTables()),
            0,
            0,
            cfs.metadata,
            StorageService.getPartitioner(),
            new MetadataCollector(cfs.metadata.comparator));

    writer.append(Util.dk("0"), cf);
    writer.append(Util.dk("1"), cf);
    writer.append(Util.dk("3"), cf);

    cfs.addSSTable(writer.closeAndOpenReader());
    writer =
        new SSTableWriter(
            cfs.getTempSSTablePath(dir.getDirectoryForNewSSTables()),
            0,
            0,
            cfs.metadata,
            StorageService.getPartitioner(),
            new MetadataCollector(cfs.metadata.comparator));

    writer.append(Util.dk("0"), cf);
    writer.append(Util.dk("1"), cf);
    writer.append(Util.dk("2"), cf);
    writer.append(Util.dk("3"), cf);
    cfs.addSSTable(writer.closeAndOpenReader());

    Collection<SSTableReader> toCompact = cfs.getSSTables();
    assert toCompact.size() == 2;

    // Force compaction on first sstables. Since each row is in only one sstable, we will be using
    // EchoedRow.
    Util.compact(cfs, toCompact);
    assertEquals(1, cfs.getSSTables().size());

    // Now assert we do have the 4 keys
    assertEquals(4, Util.getRangeSlice(cfs).size());

    ArrayList<DecoratedKey> k = new ArrayList<DecoratedKey>();
    for (Row r : Util.getRangeSlice(cfs)) {
      k.add(r.key);
      assertEquals(ByteBufferUtil.bytes("a"), r.cf.getColumn(Util.cellname("a")).value());
      assertNull(r.cf.getColumn(Util.cellname("01")));
      assertEquals(3, r.cf.getColumn(Util.cellname("a")).timestamp());
    }

    for (SSTableReader sstable : cfs.getSSTables()) {
      StatsMetadata stats = sstable.getSSTableMetadata();
      assertEquals(ByteBufferUtil.bytes("0"), stats.minColumnNames.get(0));
      assertEquals(ByteBufferUtil.bytes("b"), stats.maxColumnNames.get(0));
    }

    assertEquals(keys, k);
  }