- Timestamp:
- Oct 26, 2010, 6:37:15 AM (14 years ago)
- Location:
- liacs/TOOS/assignment1/src
- Files:
-
- 2 added
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
liacs/TOOS/assignment1/src/Census.java
r209 r210 22 22 * @return boolean with conjuction of voters or null on error. 23 23 */ 24 public static Boolean census(HashSet<Voter> voters) { 24 public Boolean census(HashSet<Voter> voters) { 25 logger.debug("Starting new comparison"); 25 26 26 27 /* Nobody likes voting on Tuesday don't they? */ 27 28 Calendar rightNow = Calendar.getInstance(); 28 29 if (rightNow.get(Calendar.DAY_OF_WEEK) == Calendar.WEDNESDAY) { 30 logger.debug("Sorry not today"); 29 31 return false; 32 } 33 34 /* No voters return error as result cannot be conclusive */ 35 if (voters == null) { 36 return null; 30 37 } 31 38 32 39 /* Check all votes to make it a fair voting system */ 33 40 for (Voter v: voters) { 34 logger.debug(v.getVote());35 41 /* 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))) { 38 43 return null; 39 44 } 40 45 46 logger.debug(v.getVote()); 41 47 /* All has to be in agreement */ 42 48 if (v.getVote() == false) { -
liacs/TOOS/assignment1/src/CensusTest.java
r209 r210 11 11 HashSet<Voter> v = null; 12 12 Census c = new Census(); 13 assert True(c.census(v).equals(null));13 assertNull(c.census(v)); 14 14 } 15 15 … … 35 35 assertFalse(c.census(v)); 36 36 } 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 } 37 66 }
Note:
See TracChangeset
for help on using the changeset viewer.