のんちゃんのVBお勉強に協力する試み (3) のコメント:
今ふと思ったのですがNUnitのテストプログラムを書くのも良いかと。
チェックをパスする=正解!とわかりやすくていいです。
それはVBおんちな僕への挑発かね? それとも'いやがらせ'かね?
受けて立とうぢゃないかちくしょー
' NUnit 2.4.7 を使ったテスト
' テスト対象アセンブリはこんなの
'
' Namespace non_Sort
' Public Class SortCollections
' Public Shared Sub Sort(ByVal data() As Integer)
' Array.Sort(data)
' End Sub
' End Class
' End Namespace
Imports NUnit.Framework
Namespace non_Sort
<TestFixture()> Public Class non_Sort_Test
Private data() As Integer
Private R As New Random
Private Sub Setup()
ReDim data(R.Next(100))
End Sub
Private Sub Randomize()
Dim I As Integer
Setup()
For I = 0 To data.Length - 1
data(I) = R.Next(100)
Next
End Sub
Private Sub Ascend()
Dim I As Integer
Setup()
For I = 0 To data.Length - 1
data(I) = I
Next
End Sub
Private Sub Descend()
Dim I As Integer
Setup()
For I = 0 To data.Length - 1
data(I) = -I
Next
End Sub
Function IsSorted(ByVal data() As Integer) As Boolean
Dim I As Integer
If data.Length = 0 OrElse data.Length = 1 Then Return True
For I = 0 To data.Length - 2
If data(I) > data(I + 1) Then Return False
Next
Return True
End Function
<Test()> Public Sub TestAscend()
Dim I As Integer
For I = 1 To 10
Ascend()
SortCollections.Sort(data)
Assert.IsTrue(IsSorted(data))
Next
End Sub
<Test()> Public Sub TestDescend()
Dim I As Integer
For I = 1 To 10
Descend()
SortCollections.Sort(data)
Assert.IsTrue(IsSorted(data))
Next
End Sub
<Test()> Public Sub TestRandom()
Dim I As Integer
For I = 1 To 10
Randomize()
SortCollections.Sort(data)
Assert.IsTrue(IsSorted(data))
Next
End Sub
End Class
End Namespace