Skip to content

Instantly share code, notes, and snippets.

@typosone
Last active August 29, 2015 14:25
Show Gist options
  • Save typosone/e418cf54326e2f7cef56 to your computer and use it in GitHub Desktop.
Save typosone/e418cf54326e2f7cef56 to your computer and use it in GitHub Desktop.
fizzbuzz の簡単なユニットテストする
import sys
from io import StringIO
import unittest
import fizzbuzz
pattern10 = """1\n2\nfizz\n4\nbuzz\nfizz\n7\n8\nfizz\nbuzz\n"""
pattern100 = """1\n2\nfizz\n4\nbuzz\nfizz\n7\n8\nfizz\nbuzz
11\nfizz\n13\n14\nfizz buzz\n16\n17\nfizz\n19\nbuzz
fizz\n22\n23\nfizz\nbuzz\n26\nfizz\n28\n29\nfizz buzz
31\n32\nfizz\n34\nbuzz\nfizz\n37\n38\nfizz\nbuzz
41\nfizz\n43\n44\nfizz buzz\n46\n47\nfizz\n49\nbuzz
fizz\n52\n53\nfizz\nbuzz\n56\nfizz\n58\n59\nfizz buzz
61\n62\nfizz\n64\nbuzz\nfizz\n67\n68\nfizz\nbuzz
71\nfizz\n73\n74\nfizz buzz\n76\n77\nfizz\n79\nbuzz
fizz\n82\n83\nfizz\nbuzz\n86\nfizz\n88\n89\nfizz buzz
91\n92\nfizz\n94\nbuzz\nfizz\n97\n98\nfizz
"""
class FizzBuzzTest(unittest.TestCase):
def setUp(self):
self.held, sys.stdout = sys.stdout, StringIO()
def test_to_10(self):
fizzbuzz.fizzbuzz(11)
self.assertEqual(pattern10, sys.stdout.getvalue().lower())
def test_to_100(self):
fizzbuzz.fizzbuzz(100)
self.assertEqual(pattern100, sys.stdout.getvalue().lower())
def tearDown(self):
sys.stdout = self.held
if __name__ == '__main__':
unittest.main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment