# This code was developed during our class as a (partial) example demonstrating use of # Python's unittest module for testing our previous Television class. To facilitate testing, # we modified the earlier Television class to provide accessors isOn(), isMuted(), getVolume() and getChannel() # # Note well that this file only represents a small portion of the testing that should be done to ensure # the rich set of functionality that the Television supports from Television import Television import unittest class TelevisionTest(unittest.TestCase): def testInitialization(self): tv = Television() self.assertEquals(tv.getChannel(), 2) self.assertEquals(tv.getVolume(), 5) self.assertFalse(tv.isOn()) self.assertFalse(tv.isMuted()) def testChannelUp(self): tv = Television() tv.togglePower() c = tv.getChannel() tv.channelUp() self.assertEquals(c+1, tv.getChannel()) def testNoPower(self): tv = Television() c = tv.getChannel() tv.channelUp() self.assertEquals(c, tv.getChannel()) tv.toggleMute() self.assertFalse(tv.isMuted()) # ... could test other functions in similar fashion def testAutoUnmute(self): tv = Television() tv.togglePower() tv.toggleMute() self.assertTrue(tv.isMuted()) tv.volumeUp() self.assertFalse(tv.isMuted()) def testUnmuteOnPower(self): tv = Television() tv.togglePower() tv.toggleMute() self.assertTrue(tv.isMuted()) tv.togglePower() tv.togglePower() self.assertFalse(tv.isMuted()) # many more functions should follow for complete testing... if __name__ == '__main__': unittest.main() # this starts the testing process