Esempio n. 1
0
 /** Tests: public synchronized long getFirstVoteTime() method of the Voter class. */
 @Test
 public void testGetFirstVoteTime() {
   Voter v1 = new Voter("david", "123");
   assertTrue(v1.vote(new Vote("a")));
   long firstVoteTime = v1.getFirstVoteTime();
   assertEquals(v1.getFirstVoteTime(), firstVoteTime);
   assertTrue(v1.vote(new Vote("b")));
   assertEquals(v1.getFirstVoteTime(), firstVoteTime);
   assertTrue(v1.vote(new Vote("a")));
   assertEquals(v1.getFirstVoteTime(), firstVoteTime);
   assertTrue(!v1.vote(new Vote("c")));
   assertEquals(v1.getFirstVoteTime(), firstVoteTime);
 }
Esempio n. 2
0
 /** Tests: public synchronized boolean isVoted() method of the Voter class. */
 @Test
 public void testIsVoted() {
   Voter v1 = new Voter("david", "123");
   assertTrue(!v1.isVoted());
   assertTrue(v1.vote(new Vote("a")));
   assertTrue(v1.isVoted());
   assertTrue(v1.vote(new Vote("b")));
   assertTrue(v1.isVoted());
   assertTrue(v1.vote(new Vote("a")));
   assertTrue(v1.isVoted());
   assertTrue(!v1.vote(new Vote("c")));
   assertTrue(v1.isVoted());
 }
Esempio n. 3
0
 /** Tests: public synchronized Vote getVote() method of the Voter class. */
 @Test
 public void testGetVote() {
   Voter v1 = new Voter("david", "123");
   assertTrue(v1.vote(new Vote("a")));
   assertEquals(v1.getVote(), new Vote("a"));
   assertTrue(v1.vote(new Vote("b")));
   assertEquals(v1.getVote(), new Vote("b"));
   assertTrue(v1.vote(new Vote("c")));
   assertEquals(v1.getVote(), new Vote("c"));
   assertTrue(!v1.vote(new Vote("d")));
   assertEquals(v1.getVote(), new Vote("c"));
 }
Esempio n. 4
0
 /** Tests: public boolean canChangeVote() method of the Voter class. */
 @Test
 public void testCanChangeVote() {
   Voter v1 = new Voter("david", "123");
   assertTrue(v1.canChangeVote());
   assertTrue(v1.vote(new Vote("a")));
   assertTrue(v1.canChangeVote());
   assertTrue(v1.vote(new Vote("b")));
   assertTrue(v1.canChangeVote());
   assertTrue(v1.vote(new Vote("a")));
   assertTrue(!v1.canChangeVote());
   assertTrue(!v1.vote(new Vote("c")));
 }
Esempio n. 5
0
 /** Tests: public synchronized String getName() method of the Voter class. */
 @Test
 public void testGetName() {
   Voter v1 = new Voter("david", "123");
   Voter v2 = new Voter("dan", "1234");
   Voter v3 = new Voter("david", "123");
   assertTrue(v1.getName() == "david");
   assertEquals(v1.getName(), v3.getName());
   assertTrue(v2.getName() == "dan");
 }
Esempio n. 6
0
 /** Tests: public synchronized int getVoterCount() method of the Voter class. */
 @Test
 public void testGetVoterCount() {
   Voter v1 = new Voter("david", "123");
   assertTrue(!v1.isVoted());
   assertTrue(v1.getVoterCount() == 0);
   assertTrue(v1.vote(new Vote("a")));
   assertTrue(v1.getVoterCount() == 1);
   assertTrue(v1.vote(new Vote("b")));
   assertTrue(v1.getVoterCount() == 2);
   assertTrue(v1.vote(new Vote("c")));
   assertTrue(v1.getVoterCount() == 3);
   assertTrue(!v1.vote(new Vote("d")));
   assertTrue(v1.getVoterCount() == 3);
 }
Esempio n. 7
0
 /** Tests: public boolean vote(Vote _vote) method of the Voter class. */
 @Test
 public void testVote() {
   Voter v1 = new Voter("david", "123");
   assertTrue(!v1.isVoted());
   assertTrue(v1.vote(new Vote("a")));
   long firstVoteTime = v1.getFirstVoteTime();
   assertEquals(v1.getFirstVoteTime(), firstVoteTime);
   assertTrue(v1.isVoted());
   assertEquals(v1.getVote(), new Vote("a"));
   assertTrue(v1.getVoterCount() == 1);
   assertTrue(v1.vote(new Vote("b")));
   assertEquals(v1.getFirstVoteTime(), firstVoteTime);
   assertEquals(v1.getVote(), new Vote("b"));
   assertTrue(v1.getVoterCount() == 2);
   assertTrue(v1.vote(new Vote("a")));
   assertEquals(v1.getVote(), new Vote("a"));
   assertTrue(v1.getVoterCount() == 3);
   assertTrue(!v1.vote(new Vote("c")));
   assertTrue(v1.getVoterCount() == 3);
   assertTrue(v1.isVoted());
   assertEquals(v1.getFirstVoteTime(), firstVoteTime);
 }
Esempio n. 8
0
 /** Tests: public Voter(Voter other) method of the Voter class. */
 @Test
 public void testVoter() {
   Voter v1 = new Voter("david", "123");
   v1.vote(new Vote("a"));
   v1.vote(new Vote("a"));
   Voter v2 = new Voter(v1);
   assertEquals(v2.getId(), v1.getId());
   assertEquals(v2.getName(), v1.getName());
   assertEquals(v2.getFirstVoteTime(), v1.getFirstVoteTime());
   assertEquals(v2.getVoterCount(), v1.getVoterCount());
   assertEquals(v2.getVote(), v1.getVote());
   v1.vote(new Vote("b"));
   assertTrue(!v1.canChangeVote());
   assertTrue(v2.canChangeVote());
   v2.vote(new Vote("c"));
   assertEquals(v1.getVote(), new Vote("b"));
   assertEquals(v2.getVote(), new Vote("c"));
 }