1

我只需要测试函数是否运行没有失败或测试返回的值是否是以下之一:

('NDP', None) or ('CPC', None) or ('GREEN', None) or ('LIBERAL', None)

def test_single_zero_ballot(self):
    self.assertEqual(voting_systems.voting_irv({('NDP','CPC','LIBERAL','GREEN'):0}),
                     (('NDP', None) or ('CPC', None) or ('GREEN', None) or ('LIBERAL', None)),
    'Fails to run when there is a single ballot with zero votes')
4

1 回答 1

1

我建议使用assertIn,因为您正在检查该值是否是几个值之一:

def test_single_zero_ballot(self):
    valid_values = [('NDP', None), ('CPC', None), ('GREEN', None), ('LIBERAL', None)]    
    self.assertIn(voting_systems.voting_irv({('NDP','CPC','LIBERAL','GREEN'):0}),
                     valid_values,
    'Fails to run when there is a single ballot with zero votes')

有关完整详细信息,请参阅文档

于 2013-04-05T03:45:12.863 回答