Imports NUnit.Framework <TestFixture()> _ PublicClass Class1Class Class1 ''' ----------------------------------------------------------------------------- ''' <summary> ''' 查找最大值 ''' </summary> ''' <param name="list">传入整数数组</param> ''' <returns>返回数组中的最大值</returns> ''' <remarks> ''' </remarks> ''' <history> ''' [TonyGong] 5/25/2006 Created ''' </history> ''' ----------------------------------------------------------------------------- Function FindMax()Function FindMax(ByVal list As Int32()) As Int32 Dim i As Int32 Dim max As Int32 = Int32.MinValue For i =0To list.Length -1 If list(i) > max Then max = list(i) EndIf Next Return max End Function ''' ----------------------------------------------------------------------------- ''' <summary> ''' 测试Class1类的FindMax方法 ''' </summary> ''' <remarks> ''' </remarks> ''' <history> ''' [TonyGong] 5/25/2006 Created ''' </history> ''' ----------------------------------------------------------------------------- <Test()> _ PublicSub FindMaxTest()Sub FindMaxTest() ' Dim list1() As Int32 = {1, 3, 10, 4} Dim list2() As Int32 = {1, 3, 4, 10} Dim list3() As Int32 = {10, 3, 1, 4} Dim list4() As Int32 = {-2, -1, -3} Dim my AsNew Class1 '测试数组list1中的最大整数是不是10。 Assert.AreEqual(10, my.FindMax(list1)) '测试边界值 Assert.AreEqual(10, my.FindMax(list2)) Assert.AreEqual(10, my.FindMax(list3)) '测试负数数组,数组中最大值应该是-1 Assert.AreEqual(-1, my.FindMax(list4)) End Sub End Class
PublicClass Class1Class Class1 ''' ----------------------------------------------------------------------------- ''' <summary> ''' 查找最大值 ''' </summary> ''' <param name="list">传入整数数组</param> ''' <returns>返回数组中的最大值</returns> ''' <remarks> ''' </remarks> ''' <history> ''' [TonyGong] 5/25/2006 Created ''' </history> ''' ----------------------------------------------------------------------------- Function FindMax()Function FindMax(ByVal list As Int32()) As Int32 Dim i As Int32 Dim max As Int32 = Int32.MinValue For i =0To list.Length -1 If list(i) > max Then max = list(i) EndIf Next Return max End Function End Class
Imports NUnit.Framework Imports ClassLibrary3 <TestFixture()> _ PublicClass Class1TestClass Class1Test PublicSub New()SubNew() End Sub ''' ----------------------------------------------------------------------------- ''' <summary> ''' 测试Class1类的FindMax方法 ''' </summary> ''' <remarks> ''' </remarks> ''' <history> ''' [TonyGong] 5/25/2006 Created ''' </history> ''' ----------------------------------------------------------------------------- <Test()> _ PublicSub FindMaxTest()Sub FindMaxTest() ' Dim list1() As Int32 = {1, 3, 10, 4} Dim list2() As Int32 = {1, 3, 4, 10} Dim list3() As Int32 = {10, 3, 1, 4} Dim list4() As Int32 = {-2, -1, -3} Dim my AsNew Class1 '测试数组list1中的最大整数是不是10。 Assert.AreEqual(10, my.FindMax(list1)) '测试边界值 Assert.AreEqual(10, my.FindMax(list2)) Assert.AreEqual(10, my.FindMax(list3)) '测试负数数组,数组中最大值应该是-1 Assert.AreEqual(-1, my.FindMax(list4)) End Sub End Class