]> projects.mako.cc - selectricity/commitdiff
Add several testcases for casting quickvotes with invalid information
authorJohn Dong <jdong@mit.edu>
Fri, 17 Aug 2007 23:33:00 +0000 (19:33 -0400)
committerJohn Dong <jdong@mit.edu>
Fri, 17 Aug 2007 23:33:00 +0000 (19:33 -0400)
test/unit/selectricityservice_test.rb

index 65da4d1ccde52c96535e3dda0f23b6ea8bafbddc..0596dc715fe8d17ed1401c6cd2f6b0f01ae1584a 100644 (file)
@@ -23,11 +23,32 @@ class SelectricityServiceTest < Test::Unit::TestCase
     casted_vote = election.candidate_ids.sort_by {rand} #Shuffles
     assert_cast_quickvote_succeeds "TestVote", 42, [casted_vote]
   end
+  def test_cast_nil_quickvote
+    assert_cast_quickvote_fails nil, nil, nil
+    assert_cast_quickvote_fails "foo", nil, nil
+    assert_cast_quickvote_fails "foo",33, []
+    test_create_quickvote
+    assert_cast_quickvote_fails "TestVote",42,nil
+    assert_cast_quickvote_fails "TestVote",nil,[]
+  end
+  def test_cast_malformed_votelist
+    test_create_quickvote
+    election = invoke_delegated :vote, :get_quickvote, "TestVote"
+    assert_cast_quickvote_fails "TestVote", 11, [election.candidate_ids[0]]
+    assert_cast_quickvote_fails "TestVote", 11, [1,2]
+    assert_cast_quickvote_fails "TestVote", 11, [election.candidate_ids[0],election.candidate_ids[0], election.candidate_ids[1], election.candidate_ids[1], election.candidate_ids[2]]
+  end
   def test_get_nonexistent_quickvote
     assert_raises ArgumentError do
       qv = invoke_delegated :vote, :get_quickvote, "asdfasdfasdf"
     end
   end
+  def test_get_voters_nonexistent_quickvote
+    assert_raises(ArgumentError) {invoke_delegated :vote, :get_quickvote_votes, "asdfasdf"}
+  end
+  def test_get_candidate_map_nonexistent_quickvote
+    assert_raises(ArgumentError) { invoke_delegated :vote, :get_quickvote_candidate_map, "asdfasdf"}
+  end
   def test_cast_mass_quickvote
     test_create_quickvote
     election = invoke_delegated :vote, :get_quickvote, "TestVote"

Benjamin Mako Hill || Want to submit a patch?