Skip to content

Instantly share code, notes, and snippets.

@gpedro
Created September 18, 2014 16:29
Show Gist options
  • Save gpedro/ba15cced7d4ceb20ecc6 to your computer and use it in GitHub Desktop.
Save gpedro/ba15cced7d4ceb20ecc6 to your computer and use it in GitHub Desktop.
unit test
from random import randint
import unittest
class TestSequenceFunctions(unittest.TestCase):
def setUp(self):
self.animals = ['dog', 'cat', 'bird', 'mouse', 'cow', 'frog', 'elephant', 'duck', 'fox']
self.says = ['woof', 'meow', 'tweet', 'squeek', 'moo', 'croak', 'toot', 'quack']
self.fox = ['Ring-ding-ding-ding-dingeringeding!', 'Gering-ding-ding-ding-dingeringeding!', 'Wa-pa-pa-pa-pa-pa-pow!', 'Hatee-hatee-hatee-ho!', 'Joff-tchoff-tchoffo-tchoffo-tchoff!', 'Tchoff-tchoff-tchoffo-tchoffo-tchoff!', 'Jacha-chacha-chacha-chow!', 'Chacha-chacha-chacha-chow!', 'Fraka-kaka-kaka-kaka-kow!', 'A-hee-ahee ha-hee!']
def test_choice(self):
global element
element = raw_input('Which animal you want to know what he says?: ')
if element not in self.animals:
self.assertTrue(0)
else:
self.assertTrue(1)
def test_does(self):
if element == 'fox':
print 'What does the fox say? %s' % self.fox[randint(0,9)]
else:
print 'What does the %s say? %s' % (element, self.says[self.animals.index(element)])
if __name__ == '__main__':
unittest.main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment