class TestChallenge(unittest.TestCase): def setUp(self): self.challenge = Challenge(2, 3, 6) def testSetParameters(self): self.challenge.catsTotal == 2 self.challenge.dogsTotal == 3 self.challenge.votesTotal == 6 def testCastVotes(self): self.challenge.cast(Vote('C1', 'D1')) self.challenge.cast(Vote('D1', 'C1')) self.assertEquals(len(self.challenge.nodes_u), 1) self.assertEquals(len(self.challenge.nodes_v), 1) self.challenge.drawIncompatibilityGraph() self.assertEquals(self.challenge.nodes_u[0].getCollisionsId(), [ 1 ]) self.assertEquals(self.challenge.nodes_v[0].getCollisionsId(), []) def testIncompatibilityMatcher(self): c = Challenge(1, 1, 2) c.cast(Vote('C1', 'D1')) c.cast(Vote('D1', 'C1')) c.cast(Vote('D1', 'C1')) c.drawIncompatibilityGraph() assert c.nodes_u[0].collisionsId == [ 1, 2 ] total = c.minimumNodesCoverage() self.assertEquals(c.nodes_v_explored, [ 1 ])
def testSampleEquity(self): c = Challenge(3, 3, 6) c.cast(Vote('C1', 'D1')) c.cast(Vote('C2', 'D2')) c.cast(Vote('C3', 'D3')) c.cast(Vote('D1', 'C1')) c.cast(Vote('D2', 'C2')) c.cast(Vote('D3', 'C3')) self.assertEquals(c.maximizedTotal(), 3)
def testIncompatibilityMatcher(self): c = Challenge(1, 1, 2) c.cast(Vote('C1', 'D1')) c.cast(Vote('D1', 'C1')) c.cast(Vote('D1', 'C1')) c.drawIncompatibilityGraph() assert c.nodes_u[0].collisionsId == [ 1, 2 ] total = c.minimumNodesCoverage() self.assertEquals(c.nodes_v_explored, [ 1 ])
def testSampleLargeMajority(self): c = Challenge(1, 2, 4) c.cast(Vote('C1', 'D1')) c.cast(Vote('C1', 'D1')) c.cast(Vote('C1', 'D2')) c.cast(Vote('D2', 'C1')) self.assertEquals(c.maximizedTotal(), 3)
#! /usr/bin/env python2.6 import sys from catvsdog import Vote, Challenge if __name__=='__main__': lines = [] for line in sys.stdin: lines.append(line) lines.reverse() cases = int(lines.pop()) for i in range(0, cases): [ catsTotal, dogsTotal, votesTotal ] = map(int, lines.pop().split()) c = Challenge(catsTotal, dogsTotal, votesTotal) for x in range(0, votesTotal): [ keepName, throwName ] = lines.pop().split() v = Vote(keepName, throwName) c.cast(v) print c.maximizedTotal()
#! /usr/bin/env python2.6 import sys from catvsdog import Vote, Challenge if __name__ == '__main__': lines = [] for line in sys.stdin: lines.append(line) # tutto questo codice non è testato lines.reverse() cases = int(lines.pop()) for i in range(0, cases): [catsTotal, dogsTotal, votesTotal] = map(int, lines.pop().split()) c = Challenge(catsTotal, dogsTotal, votesTotal) for x in range(0, votesTotal): [keepName, throwName] = lines.pop().split() v = Vote(keepName, throwName) c.cast(v) print c.maximizedTotal()
def testSampleGeneric(self): c = Challenge(2, 2, 11) c.cast(Vote('C2', 'D1')) c.cast(Vote('C2', 'D1')) c.cast(Vote('C2', 'D1')) c.cast(Vote('C1', 'D2')) c.cast(Vote('D2', 'C2')) c.cast(Vote('D2', 'C2')) c.cast(Vote('D2', 'C2')) c.cast(Vote('D2', 'C1')) c.cast(Vote('D2', 'C1')) c.cast(Vote('D2', 'C1')) c.cast(Vote('D2', 'C1')) self.assertEquals(c.maximizedTotal(), 7)
def testSampleOneToOne(self): c = Challenge(1, 1, 2) c.cast(Vote('C1', 'D1')) c.cast(Vote('D1', 'C1')) c.drawIncompatibilityGraph() self.assertEquals(c.maximizedTotal(), 1)
def setUp(self): self.challenge = Challenge(2, 3, 6)