ブックマーク / qiita.com/mia_0032 (1)

  • Pythonでランダムな値を返すメソッドのテスト - Qiita

    # -*- coding: utf-8 -*- import random class Dice(object): def throw(self): return random.randint(1, 6) # -*- coding: utf-8 -*- import collections import unittest import dice from scipy import stats class TestDice(unittest.TestCase): def setUp(self): self.__target = dice.Dice() def test_throw(self): # 6000回実行する result = [self.__target.throw() for n in range(0, 6000)] # 実行結果の集計 counted = collections

    Pythonでランダムな値を返すメソッドのテスト - Qiita
    chii_gyuu
    chii_gyuu 2022/05/15
    統計的な検定を行うことで偏りがないかテストしている。サイコロの6個の目をテストするだけで数千回の試行が必要で計算量的にも注意が必要。運が悪いとただしく実装できていても検定に失敗する可能性もある。
  • 1