Changeset 210 for liacs/TOOS/assignment1


Ignore:
Timestamp:
Oct 26, 2010, 6:37:15 AM (14 years ago)
Author:
Rick van der Zwet
Message:

Some more test cases and a working program. Let's go to the University.

Location:
liacs/TOOS/assignment1/src
Files:
2 added
2 edited

Legend:

Unmodified
Added
Removed
  • liacs/TOOS/assignment1/src/Census.java

    r209 r210  
    2222   * @return boolean with conjuction of voters or null on error.
    2323   */
    24   public static Boolean census(HashSet<Voter> voters) {
     24  public Boolean census(HashSet<Voter> voters) {
     25    logger.debug("Starting new comparison");
    2526
    2627    /* Nobody likes voting on Tuesday don't they? */
    2728    Calendar rightNow = Calendar.getInstance();
    2829    if (rightNow.get(Calendar.DAY_OF_WEEK) == Calendar.WEDNESDAY) {
     30      logger.debug("Sorry not today");
    2931      return false;
     32    }
     33
     34    /* No voters return error as result cannot be conclusive */
     35    if (voters == null) {
     36      return null;
    3037    }
    3138
    3239    /* Check all votes to make it a fair voting system */
    3340    for (Voter v: voters) {
    34       logger.debug(v.getVote());
    3541      /* Some vote is not set correctly or of wrong return value */
    36       if (v.getVote() == null || (!(v.getVote() instanceof Boolean))) {
    37         logger.debug("Invalid type");
     42      if (v == null || v.getVote() == null || (!(v.getVote() instanceof Boolean))) {
    3843        return null;
    3944      }
    4045
     46      logger.debug(v.getVote());
    4147      /* All has to be in agreement */
    4248      if (v.getVote() == false) {
  • liacs/TOOS/assignment1/src/CensusTest.java

    r209 r210  
    1111      HashSet<Voter> v = null;
    1212      Census c = new Census();
    13       assertTrue(c.census(v).equals(null));   
     13      assertNull(c.census(v));   
    1414    }
    1515
     
    3535      assertFalse(c.census(v));   
    3636    }
     37
     38    public void testInvalidVoter() {
     39      HashSet<Voter> v = new HashSet<Voter>();
     40      v.add(new Voter(true));
     41      v.add(new Voter(true));
     42      v.add(new Voter(false));
     43      v.add(null);
     44
     45      Census c = new Census();
     46      assertNull(c.census(v));   
     47    }
     48
     49    public void testDuplicateVote() {
     50      HashSet<Voter> v = new HashSet<Voter>();
     51      Voter d = new Voter(true);
     52      assertTrue(v.add(d));
     53      assertFalse(v.add(d));
     54    }
     55
     56    public void testUnusedVote() {
     57      HashSet<Voter> v = new HashSet<Voter>();
     58      v.add(new Voter(true));
     59      v.add(new Voter(true));
     60      v.add(new Voter(false));
     61      v.add(new Voter());
     62
     63      Census c = new Census();
     64      assertNull(c.census(v));   
     65    }
    3766}
Note: See TracChangeset for help on using the changeset viewer.