// 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()); }
/** * Tests that the system.peers table is not updated after a node has been removed. (See * CASSANDRA-6053) */ @Test public void testStateChangeOnRemovedNode() throws UnknownHostException { StorageService ss = StorageService.instance; VersionedValue.VersionedValueFactory valueFactory = new VersionedValue.VersionedValueFactory(partitioner); // create a ring of 2 nodes ArrayList<Token> endpointTokens = new ArrayList<>(); List<InetAddress> hosts = new ArrayList<>(); Util.createInitialRing( ss, partitioner, endpointTokens, new ArrayList<Token>(), hosts, new ArrayList<UUID>(), 2); InetAddress toRemove = hosts.get(1); SystemKeyspace.updatePeerInfo(toRemove, "data_center", "dc42"); SystemKeyspace.updatePeerInfo(toRemove, "rack", "rack42"); assertEquals("rack42", SystemKeyspace.loadDcRackInfo().get(toRemove).get("rack")); // mark the node as removed Gossiper.instance.injectApplicationState( toRemove, ApplicationState.STATUS, valueFactory.left( Collections.singleton(endpointTokens.get(1)), Gossiper.computeExpireTime())); assertTrue( Gossiper.instance.isDeadState(Gossiper.instance.getEndpointStateForEndpoint(hosts.get(1)))); // state changes made after the endpoint has left should be ignored ss.onChange(hosts.get(1), ApplicationState.RACK, valueFactory.rack("rack9999")); assertEquals("rack42", SystemKeyspace.loadDcRackInfo().get(toRemove).get("rack")); }
@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()); }
@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); }
@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); }
@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. * * @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 testWarnings() throws ParseException, TokeniserException { ArrayList<Warning> warnings = new ArrayList<>(); Policy p1 = Parser.parse("frame-src aaa", "https://origin", warnings); assertEquals("frame-src aaa", p1.show()); assertEquals(1, warnings.size()); assertEquals( "The frame-src directive is deprecated as of CSP version 1.1. Authors who wish to govern nested browsing contexts SHOULD use the child-src directive instead.", warnings.iterator().next().message); }
@Test public void shouldGive3PositionsForP15_15() { center = new Position(15, 15); iter = Utility.get8NeighborhoodIterator(center); neighborhood = convertIteration2List(iter); assertTrue("Must contain (14,15)", neighborhood.contains(new Position(14, 15))); assertTrue("Must contain (14,14)", neighborhood.contains(new Position(14, 14))); assertTrue("Must contain (15,14)", neighborhood.contains(new Position(15, 14))); assertEquals("Should be 3 positions in the iterator", 3, neighborhood.size()); }
@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 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)); }
/** * Compare if the two ArrayList is the same * * @return true/false */ public static boolean isCompareList( ArrayList<String> unsortedList, ArrayList<String> sortedList) { if (unsortedList.size() != sortedList.size()) { return false; } else { for (int i = 0; i < unsortedList.size(); i++) { if (!unsortedList.get(i).equals(sortedList.get(i))) { return false; } } } return true; }
@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; }
@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)); }
@After public void tearDown() throws Exception { for (HostMessenger hm : createdMessengers) { hm.shutdown(); } createdMessengers.clear(); }
@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); } }
@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)); }
/** 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; }
@Test public void shouldGive8PositionsForP8_8() { center = new Position(8, 8); iter = Utility.get8NeighborhoodIterator(center); neighborhood = convertIteration2List(iter); assertTrue("Must contain (7,7)", neighborhood.contains(new Position(7, 7))); assertTrue("Must contain (9,9)", neighborhood.contains(new Position(9, 9))); assertTrue("Must contain (7,9)", neighborhood.contains(new Position(7, 9))); assertTrue("Must contain (8,7)", neighborhood.contains(new Position(8, 7))); assertFalse("Must not contain center position", neighborhood.contains(center)); assertFalse("Must not contain (5,5) position", neighborhood.contains(new Position(5, 5))); assertEquals("Should be 8 positions in the iterator", 8, neighborhood.size()); }
@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)); }
@Test public void testStateJumpToLeft() throws UnknownHostException { StorageService ss = StorageService.instance; TokenMetadata tmd = ss.getTokenMetadata(); tmd.clearUnsafe(); IPartitioner partitioner = RandomPartitioner.instance; VersionedValue.VersionedValueFactory valueFactory = new VersionedValue.VersionedValueFactory(partitioner); ArrayList<Token> endpointTokens = new ArrayList<Token>(); ArrayList<Token> keyTokens = new ArrayList<Token>(); List<InetAddress> hosts = new ArrayList<InetAddress>(); List<UUID> hostIds = new ArrayList<UUID>(); // create a ring of 6 nodes Util.createInitialRing(ss, partitioner, endpointTokens, keyTokens, hosts, hostIds, 7); // node hosts.get(2) goes jumps to left ss.onChange( hosts.get(2), ApplicationState.STATUS, valueFactory.left( Collections.singleton(endpointTokens.get(2)), Gossiper.computeExpireTime())); assertFalse(tmd.isMember(hosts.get(2))); // node hosts.get(4) goes to bootstrap Gossiper.instance.injectApplicationState( hosts.get(3), ApplicationState.TOKENS, valueFactory.tokens(Collections.singleton(keyTokens.get(1)))); ss.onChange( hosts.get(3), ApplicationState.STATUS, valueFactory.bootstrapping(Collections.<Token>singleton(keyTokens.get(1)))); assertFalse(tmd.isMember(hosts.get(3))); assertEquals(1, tmd.getBootstrapTokens().size()); assertEquals(hosts.get(3), tmd.getBootstrapTokens().get(keyTokens.get(1))); // and then directly to 'left' Gossiper.instance.injectApplicationState( hosts.get(2), ApplicationState.TOKENS, valueFactory.tokens(Collections.singleton(keyTokens.get(1)))); ss.onChange( hosts.get(2), ApplicationState.STATUS, valueFactory.left(Collections.singleton(keyTokens.get(1)), Gossiper.computeExpireTime())); assertTrue(tmd.getBootstrapTokens().size() == 0); assertFalse(tmd.isMember(hosts.get(2))); assertFalse(tmd.isLeaving(hosts.get(2))); }
@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); }
@Test public void test1() throws Exception { File historyFile = new File("src/main/java/history/EURUSDD1"); MarketDataFromFile mdff = new MarketDataFromFile("EURUSD", 1440, historyFile); MarketData data1 = new MarketData("EURUSD", "2015-02-26 06:00:00", 1.1100, 1.1110, 1.1150, 1.1000, 1000); mdff.Update(data1); ArrayList<MarketData> series = mdff.getMarketData(); MarketData currData = series.get(series.size() - 1); MarketData prevData = series.get(series.size() - 2); assertEquals(currData.getHigh(), 1.13895, 0.000001); assertEquals(currData.getLow(), 1.13364, 0.000001); assertEquals(currData.getOpen(), 1.13422, 0.000001); assertEquals(currData.getClose(), 1.13619, 0.000001); assertEquals(prevData.getHigh(), 1.13589, 0.000001); assertEquals(prevData.getLow(), 1.12890, 0.000001); assertEquals(prevData.getOpen(), 1.13353, 0.000001); assertEquals(prevData.getClose(), 1.13422, 0.000001); }
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; }
@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(); }
@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); } }
@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)); }
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; }
@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 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); } }