Ejemplo n.º 1
0
 public void testSpeed(IndexVotable x) {
   long start = System.currentTimeMillis();
   for (int i = 0; i < ivotes.length; i++) {
     x.voteIndexVoteSet(ivotes[i]);
   }
   NameVotingSystem.NameVote[] winners = x.getWinners();
   long end = System.currentTimeMillis();
   double vps = ivotes.length / ((double) (end - start) / 1000.0);
   System.out.println(x.name() + ": " + vps + " votes/second");
 }
Ejemplo n.º 2
0
 public void testSystem(Class ivc, int numc, int numv)
     throws java.lang.InstantiationException, java.lang.IllegalAccessException {
   IndexVotable iv = (IndexVotable) ivc.newInstance();
   IndexVotable nv = (IndexVotable) ivc.newInstance();
   generateRandomVotes(numc, numv);
   for (int i = 0; i < numv; i++) {
     iv.voteIndexVoteSet(ivotes[i]);
     nv.voteRating(votes[i]);
   }
   NameVotingSystem.NameVote[] ivw = iv.getWinners();
   NameVotingSystem.NameVote[] nvw = nv.getWinners();
   boolean good = SummableVotingSystemTest.winnersEq(ivw, nvw);
   if (!good) {
     StringBuffer sb = new StringBuffer("index vote=\n");
     sbWinners(sb, ivw);
     sb.append("name vote=\n");
     sbWinners(sb, nvw);
     fail(sb.toString());
   }
 }