掲示板システム
ホーム
アクセス解析
カテゴリ
ログアウト
乱数について (ID:146018)
名前
ホームページ(ブログ、Twitterなど)のURL (省略可)
本文
> 意図した動きをしているので問題はないと思っているのですが > やはり何かちがうのでしょうか? パターンテストしたら平均で50%くらいはバグを含む結果と出ました。 Dim omikuzi() As String = New String() {"○", "△", "×"} Dim oldlots As Integer = -1 '前々回の結果 Dim lots As Integer = -1 '前回の結果 Dim lots2 As Integer '今回の結果 ''-------------------------------------------------------------------------- Const max As Integer = 3 Dim Kinshi As Integer = -1 ' 3回目に出さない結果 ''-------------------------------------------------------------------------- Private m_Target As String = String.Empty Private m_Double As Boolean = False ''-------------------------------------------------------------------------- Private Enum PG masaru singo maruru End Enum Private m_TestPG As PG = PG.masaru '誰のプログラムをテストするか。 Private m_AllOutput As Boolean = False '全てのおみくじ結果を表示するか。 Private m_TestRowCount As Integer Private m_TestColCount As Integer Private m_BeforeTestRowCount As Integer Private m_BeforeTestColCount As Integer Private m_omikuziAll As String Private m_TestPattern As Integer(,) = New Integer(,) {{0, 0, 0} _ , {0, 0, 1} _ , {0, 0, 2} _ , {0, 1, 0} _ , {0, 1, 1} _ , {0, 1, 2} _ , {0, 2, 0} _ , {0, 2, 1} _ , {0, 2, 2} _ , {1, 0, 0} _ , {1, 0, 1} _ , {1, 0, 2} _ , {1, 1, 0} _ , {1, 1, 1} _ , {1, 1, 2} _ , {1, 2, 0} _ , {1, 2, 1} _ , {1, 2, 2} _ , {2, 0, 0} _ , {2, 0, 1} _ , {2, 0, 2} _ , {2, 1, 0} _ , {2, 1, 1} _ , {2, 1, 2} _ , {2, 2, 0} _ , {2, 2, 1} _ , {2, 2, 2} _ } Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click Dim strExpect As String Dim strResult As String Dim strOutput As String Dim strOmikujiTmp As String Dim strTarget As String Dim blnDouble As Boolean Dim blnTurkey As Boolean If m_AllOutput Then Debug.WriteLine("期待値 結果 合否 (全ての結果)") Debug.WriteLine("--------------------------------------------") Else Debug.WriteLine("期待値 結果 合否 ") Debug.WriteLine("----------------------") End If m_BeforeTestRowCount = -1 m_BeforeTestColCount = -1 For m_TestRowCount = 0 To m_TestPattern.GetLength(0) - 1 '-- テスト結果用変数の初期化 strExpect = String.Empty strTarget = String.Empty blnDouble = False blnTurkey = False m_omikuziAll = String.Empty '-- テスト開始条件を揃える oldlots = -1 '前々回の結果 lots = -1 '前回の結果 ''-------------------------------------------------------------------------- oldlots = -1 '前々回の結果 lots = -1 '前回の結果 Kinshi = -1 ''-------------------------------------------------------------------------- m_Target = String.Empty m_Double = False ''-------------------------------------------------------------------------- '-- 判定基準作成 For col As Integer = 0 To m_TestPattern.GetLength(1) - 1 strOmikujiTmp = omikuzi(m_TestPattern(m_TestRowCount, col)) If strTarget = strOmikujiTmp Then If blnDouble Then blnTurkey = True Else blnDouble = True End If Else blnDouble = False strTarget = strOmikujiTmp End If strExpect &= strOmikujiTmp Next '-- テスト strResult = String.Empty For m_TestColCount = 0 To m_TestPattern.GetLength(1) - 1 'If m_TestRowCount = 19 - 1 AndAlso m_TestColCount = 1 - 1 Then ' Debug.WriteLine("Break Point") 'End If Call Button1_Click(Nothing, Nothing) strResult &= Me.Label1.Text Next strOutput = strExpect & " " & strResult & " " '-- テスト結果の判定 If blnTurkey Then If strExpect.Substring(0, 2) = strResult.Substring(0, 2) _ AndAlso strExpect <> strResult Then strOutput = strOutput & "合格 " Else strOutput = strOutput & "不合格" End If Else If strExpect = strResult Then strOutput = strOutput & "合格 " Else strOutput = strOutput & "不合格" End If End If If m_AllOutput Then strOutput &= "(" & m_omikuziAll & ")" End If Debug.WriteLine(strOutput) Next End Sub Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click Select Case m_TestPG Case PG.masaru Call masaruPG() Case PG.singo Call singoPG() Case PG.maruru Call maruruPG() End Select End Sub Sub masaruPG() 'omikuzi = New String() {"○", "△", "×"} oldlots = lots lots = lots2 lots2 = kansu(3) If lots2 = oldlots Then 'もし今回と前々回の結果が同じなら以下を繰り返す Do Until lots2 <> oldlots lots2 = kansu(3) Loop End If Select Case lots2 Case 0 Label1.Text = omikuzi(lots2) Case 1 Label1.Text = omikuzi(lots2) Case 2 Label1.Text = omikuzi(lots2) End Select End Sub Sub singoPG() 'omikuzi = New String() {"やりました。大吉です", "まあまあ、吉です", "がっかり凶です"} lots = kansu(max) If lots = Kinshi Then Do lots = kansu(max) Loop Until lots <> Kinshi End If Label1.Text = omikuzi(lots) If oldlots = lots Then Kinshi = lots Else Kinshi = -1 End If oldlots = lots End Sub Sub maruruPG() Dim strOmikujiTmp As String strOmikujiTmp = omikuzi(kansu(3)) If m_Target = strOmikujiTmp Then If m_Double Then Do strOmikujiTmp = omikuzi(kansu(3)) Loop Until m_Target <> strOmikujiTmp Else m_Double = True End If Else m_Double = False End If m_Target = strOmikujiTmp Label1.Text = strOmikujiTmp End Sub Function kansu(ByVal i As Integer) As Integer Try '-- 規定のテストパターン内ならテストパターンを返す If m_BeforeTestRowCount <> m_TestRowCount _ OrElse m_BeforeTestColCount <> m_TestColCount Then m_BeforeTestRowCount = m_TestRowCount m_BeforeTestColCount = m_TestColCount If m_TestRowCount <= m_TestPattern.GetLength(0) - 1 _ AndAlso m_TestColCount <= m_TestPattern.GetLength(1) - 1 Then Return m_TestPattern(m_TestRowCount, m_TestColCount) End If End If Dim myrandom As Random = New Random() Return myrandom.Next(i) Catch ex As Exception Debug.WriteLine(ex.Message) Finally '-- 全てのおみくじ結果を記録 m_omikuziAll &= omikuzi(kansu) End Try End Function
←解決時は質問者本人がここをチェックしてください。
更新する
戻る
掲示板システム
Copyright 2021 Takeshi Okamoto All Rights Reserved.