Pythonのテストコード

# coding:utf-8

import unittest
import fizzbuzz as fb

class FizzBuzzTest(unittest.TestCase):
	def setUp(self):
		pass

	def tearDown(self):
		pass

	def test_normal(self):
		self.assertEqual(1, fb.fizzbuzz(1))

	def test_fizz(self):
		self.assertEqual("Fizz", fb.fizzbuzz(3))

	def test_buzz(self):
		self.assertEqual("Buzz", fb.fizzbuzz(5))

	def test_fizzbuzz(self):
		self.assertEqual("FizzBuzz", fb.fizzbuzz(3))

if __name__ == "__main__":
	unittest.main()

メインコード

# coding:utf-8

def fizzbuzz(number):
	if number % 15 == 0:
		return "FizzBuzz"
	if number % 5 == 0:
		return "Buzz"
	if number % 3 == 0:
		return "Fizz"

	return number

if __name__ == "__main__":
	for i in range(1, 101):
		print(fizzbuzz(i)) 

t$ python3 test_fizzbuzz.py
..F.
======================================================================
FAIL: test_fizzbuzz (__main__.FizzBuzzTest)
———————————————————————-
Traceback (most recent call last):
File “test_fizzbuzz.py”, line 23, in test_fizzbuzz
self.assertEqual(“FizzBuzz”, fb.fizzbuzz(3))
AssertionError: ‘FizzBuzz’ != ‘Fizz’
– FizzBuzz
+ Fizz

———————————————————————-
Ran 4 tests in 0.002s

FAILED (failures=1)