[GB.GSL]
* BUG: Remove from the Test project the files that must not be present in the subversion repository. git-svn-id: svn://localhost/gambas/trunk@4560 867c0c6c-44f3-4631-809d-bfa615b0a4ec
This commit is contained in:
parent
5da2463da1
commit
09330f7501
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@ -1,247 +0,0 @@
|
||||
' Gambas module file
|
||||
|
||||
Private ts As New TestSuite
|
||||
|
||||
'------------------------------------------------------------------
|
||||
'Creates a new test object and adds it to the test suite
|
||||
'------------------------------------------------------------------
|
||||
Public Function AddTest(name As String, result As Variant, expected As Variant, Optional note As String) As Test
|
||||
|
||||
Dim t As New Test
|
||||
|
||||
ts.AddTest(t)
|
||||
t.Run(name, result, expected, note)
|
||||
|
||||
End
|
||||
|
||||
|
||||
'-----------------------------------------------------------------
|
||||
'Test All GSL Class Methods
|
||||
'-----------------------------------------------------------------
|
||||
Public Sub testGslMethods()
|
||||
Dim result As Variant
|
||||
|
||||
AddTest("GSL.Acosh(45)", GSL.Acosh(45), ACosh(45))
|
||||
AddTest("GSL.Asinh(45)", GSL.Asinh(45), ASinh(45))
|
||||
AddTest("GSL.Atanh(0.45)", GSL.Atanh(0.45), ATanh(0.45))
|
||||
AddTest("GSL.Expm1(45)", GSL.Expm1(45), Expm(45))
|
||||
AddTest("GSL.Fcmpb(-0.3, 0.2, 0.1)", GSL.Fcmpb(-0.3, 0.2, 0.1), GSL.Fcmpb(-0.3, 0.2, 0.1))
|
||||
AddTest("GSL.Fcmpi(-0.3, 0.2, 0.1)", GSL.Fcmpi(1.3, 2.2, -1.1), 1)
|
||||
result = GSL.Frexp(0.45)
|
||||
AddTest("GSL.Frexp(0.45)", result), result)
|
||||
AddTest("GSL.Hypot(10.27, 7.45)", GSL.Hypot(10.27, 7.45), GSL.Hypot(10.27, 7.45))
|
||||
AddTest("GSL.Hypot3(10.27, 7.45, 6.78125)", GSL.Hypot3(10.27, 7.45, 6.78125), GSL.Hypot3(10.27, 7.45, 6.78125))
|
||||
AddTest("GSL.IntPow(2.0, 8)", GSL.IntPow(2.0, 8), 256.00)
|
||||
AddTest("GSL.IntPow2(8)", GSL.IntPow2(8), GSL.IntPow2(8))
|
||||
AddTest("GSL.IntPow3(8)", GSL.IntPow3(8), GSL.IntPow3(8))
|
||||
AddTest("GSL.IntPow4(8)", GSL.IntPow4(8), GSL.IntPow4(8))
|
||||
AddTest("GSL.IntPow5(8)", GSL.IntPow5(8), GSL.IntPow5(8))
|
||||
AddTest("GSL.IntPow6(8)", GSL.IntPow6(8), GSL.IntPow6(8))
|
||||
AddTest("GSL.IntPow7(8)", GSL.IntPow7(8), GSL.IntPow7(8))
|
||||
AddTest("GSL.IntPow8(8)", GSL.IntPow8(8), GSL.IntPow8(8))
|
||||
AddTest("GSL.IntPow9(8)", GSL.IntPow9(8), GSL.IntPow9(8))
|
||||
AddTest("GSL.IsEven(2)", GSL.IsEven(2), True)
|
||||
AddTest("GSL.IsFinite(25)", GSL.IsFinite(25), True)
|
||||
AddTest("GSL.IsInf(0)", GSL.IsInf(0), False)
|
||||
AddTest("GSL.IsNan(0)", GSL.IsNan(0), False)
|
||||
AddTest("GSL.IsOdd(3)", GSL.IsOdd(3), True)
|
||||
AddTest("GSL.IsPos(0)", GSL.IsPos(0), True)
|
||||
AddTest("GSL.Ldexp(17.63, 3)", GSL.Ldexp(17.63, 3), 141.04)
|
||||
AddTest("GSL.Log1p(12.36)", GSL.Log1p(12.36), GSL.Log1p(12.36))
|
||||
AddTest("GSL.MaxFloat(2.0123, 2.01234)", GSL.MaxFloat(2.0123, 2.01234), 2.01234)
|
||||
AddTest("GSL.MaxInt(1,3)", GSL.MaxInt(1, 3), 3)
|
||||
AddTest("GSL.MinFLoat(0.001, 0.0011)", GSL.MinFLoat(0.001, 0.0011), 0.001)
|
||||
AddTest("GSL.MinInt(1,3)", GSL.MinInt(1, 3), 1)
|
||||
|
||||
End
|
||||
|
||||
|
||||
'----------------------------------------------------------------
|
||||
'Test GSL Class constance
|
||||
'----------------------------------------------------------------
|
||||
Public Sub testGslConstance()
|
||||
' Constance
|
||||
AddTest("GSL.M_1_PI", GSL.M_1_PI, 0.31830988618379067153776752675)
|
||||
AddTest("GSL.M_2_PI", GSL.M_2_PI, 0.63661977236758134307553505349)
|
||||
AddTest("GSL.M_2_SQRTPI", GSL.M_2_SQRTPI, 1.12837916709551257389615890312)
|
||||
AddTest("GSL.M_E", GSL.M_E, 2.71828182845904523536028747135)
|
||||
AddTest("GSL.M_EULER", GSL.M_EULER, 0.57721566490153286060651209008)
|
||||
AddTest("GSL.M_LN2", GSL.M_LN2, 0.69314718055994530941723212146)
|
||||
AddTest("GSL.M_LN10", GSL.M_LN10, 2.30258509299404568401799145468)
|
||||
AddTest("GSL.M_LNPI", GSL.M_LNPI, 1.14472988584940017414342735135)
|
||||
AddTest("GSL.M_LOG10E", GSL.M_LOG10E, 0.43429448190325182765112891892)
|
||||
AddTest("GSL.M_LOGE", GSL.M_LOGE, 1.44269504088896340735992468100)
|
||||
AddTest("GSL.M_PI", GSL.M_PI, 3.14159265358979323846264338328)
|
||||
AddTest("GSL.M_PI_2", GSL.M_PI_2, 1.57079632679489661923132169164)
|
||||
AddTest("GSL.M_PI_4", GSL.M_PI_4, 0.78539816339744830961566084582)
|
||||
AddTest("GSL.M_SQRT1_2", GSL.M_SQRT1_2, 0.70710678118654752440084436210)
|
||||
AddTest("GSL.M_SQRT2", GSL.M_SQRT2, 1.41421356237309504880168872421)
|
||||
AddTest("GSL.M_SQRT3", GSL.M_SQRT3, 1.73205080756887729352744634151)
|
||||
AddTest("GSL.M_SQRTPI", GSL.M_SQRTPI, 1.77245385090551602729816748334)
|
||||
|
||||
End
|
||||
|
||||
|
||||
|
||||
'------------------------------------------------------------------
|
||||
'Test Complex Class Methods
|
||||
'------------------------------------------------------------------
|
||||
Public Sub AddComplexTest(name As String, result As Variant, expected As Variant, Optional note As String)
|
||||
|
||||
Dim t As New TestComplex
|
||||
|
||||
ts.AddTest(t)
|
||||
t.Run(name, result, expected, note)
|
||||
|
||||
End
|
||||
|
||||
|
||||
'-------------------------------------------------------------------
|
||||
'Test Complex Class Methods
|
||||
'-------------------------------------------------------------------
|
||||
Public Sub testComplexMethods()
|
||||
Dim c As New Complex
|
||||
Dim z1 As New Complex
|
||||
Dim z2 As New Complex
|
||||
Dim z3 As Complex
|
||||
|
||||
z1.Set(1, 1)
|
||||
z2.Set(2, 2)
|
||||
|
||||
AddComplexTest("z1.Abs()", z1.Abs(), z1.Abs(), ("z1 = " & z1.ToString()))
|
||||
AddComplexTest("z1.Abs2()", z1.Abs2(), z1.Abs2(), "z1 = " & z1.ToString())
|
||||
AddComplexTest("z1.Add(z2)", z1.Add(z2), z1.Add(z2), "z1 = " & z1.ToString())
|
||||
AddComplexTest("z1.AddImag(1)", z1.AddImag(1), z1.AddImag(1), "z1 = " & z1.ToString())
|
||||
AddComplexTest("z1.AddReal(1)", z1.AddReal(1), z1.AddReal(1), "z1 = " & z1.ToString())
|
||||
AddComplexTest("z1.Arccos()", z1.Arccos(), z1.Arccos(), "z1 = " & z1.ToString())
|
||||
AddComplexTest("z1.Arccosh()", z1.Arccosh(), z1.Arccosh(), "z1 = " & z1.ToString())
|
||||
AddComplexTest("z1.ArccoshReal(5.45)", z1.ArccoshReal(5.45), z1.ArccoshReal(5.45), "z1 = " & z1.ToString())
|
||||
AddComplexTest("z1.ArccosReal(3.25)", z1.ArccosReal(3.25), z1.ArccosReal(3.25), "z1 = " & z1.ToString())
|
||||
AddComplexTest("z1.Arccot()", z1.Arccot(), z1.Arccot(), "z1 = " & z1.ToString())
|
||||
AddComplexTest("z1.Arccoth()", z1.Arccoth(), z1.Arccoth(), "z1 = " & z1.ToString())
|
||||
AddComplexTest("z1.Arccsc()", z1.Arccsc(), z1.Arccsc(), "z1 = " & z1.ToString())
|
||||
AddComplexTest("z1.Arccsch()", z1.Arccsch(), z1.Arccsch(), "z1 = " & z1.ToString())
|
||||
AddComplexTest("z1.ArccscReal(3.45)", z1.ArccscReal(3.45), z1.ArccscReal(3.45), "z1 = " & z1.ToString())
|
||||
AddComplexTest("z1.Arcsec()", z1.Arcsec(), z1.Arcsec(), "z1 = " & z1.ToString())
|
||||
AddComplexTest("z1.Arcsech()", z1.Arcsech(), z1.Arcsech(), "z1 = " & z1.ToString())
|
||||
AddComplexTest("z1.ArcsecReal(3.45)", z1.ArcsecReal(3.45), z1.ArcsecReal(3.45), "z1 = " & z1.ToString())
|
||||
AddComplexTest("z1.Arcsin()", z1.Arcsin(), z1.Arcsin(), "z1 = " & z1.ToString())
|
||||
AddComplexTest("z1.Arcsinh()", z1.Arcsinh(), z1.Arcsinh(), "z1 = " & z1.ToString())
|
||||
AddComplexTest("z1.ArcsinReal(3.45)", z1.ArcsinReal(3.45), z1.ArcsinReal(3.45), "z1 = " & z1.ToString())
|
||||
AddComplexTest("z1.Arctan()", z1.Arctan(), z1.Arctan(), "z1 = " & z1.ToString())
|
||||
AddComplexTest("z1.Arctanh()", z1.Arctanh(), z1.Arctanh(), "z1 = " & z1.ToString())
|
||||
AddComplexTest("z1.ArctanhReal(3.45)", z1.ArctanhReal(3.45), z1.ArctanhReal(3.45), "z1 = " & z1.ToString())
|
||||
AddComplexTest("z1.Arg()", z1.Arg(), z1.Arg(), "z1 = " & z1.ToString())
|
||||
AddComplexTest("z1.Copy()", z1.Copy(), z1.Copy(), "z1 = " & z1.ToString())
|
||||
AddComplexTest("z1.Cos()", z1.Cos(), z1.Cos(), "z1 = " & z1.ToString())
|
||||
AddComplexTest("z1.Cosh()", z1.Cosh(), z1.Cosh(), "z1 = " & z1.ToString())
|
||||
AddComplexTest("z1.Cot()", z1.Cot(), z1.Cot(), "z1 = " & z1.ToString())
|
||||
AddComplexTest("z1.Coth()", z1.Coth(), z1.Coth(), "z1 = " & z1.ToString())
|
||||
AddComplexTest("z1.Csc()", z1.Csc(), z1.Csc(), "z1 = " & z1.ToString())
|
||||
AddComplexTest("z1.Csch()", z1.Csch(), z1.Csch(), "z1 = " & z1.ToString())
|
||||
AddComplexTest("z1.Csch()", z1.Csch(), z1.Csch(), "z1 = [" & z1.ToString() & "] z2 = [" & z2.ToString() & "]")
|
||||
AddComplexTest("z1.DivImag(3.45)", z1.DivImag(3.45), z1.DivImag(3.45), "z1 = " & z1.ToString())
|
||||
AddComplexTest("z1.DivReal(3.45)", z1.DivReal(3.45), z1.DivReal(3.45), "z1 = " & z1.ToString())
|
||||
AddComplexTest("z1.Exp()", z1.Exp(), z1.Exp(), "z1 = " & z1.ToString())
|
||||
AddComplexTest("z1.Log()", z1.Log(), z1.Log(), "z1 = " & z1.ToString())
|
||||
AddComplexTest("z1.Log10()", z1.Log10(), z1.Log10(), "z1 = " & z1.ToString())
|
||||
AddComplexTest("z1.LogAbs()", z1.LogAbs(), z1.LogAbs(), "z1 = " & z1.ToString())
|
||||
AddComplexTest("z1.Logb(z2)", z1.Logb(z2), z1.Logb(z2), "z1 = [" & z1.ToString() & "] z2 = [" & z2.ToString() & "]")
|
||||
AddComplexTest("z1.Mul(z2)", z1.Mul(z2), z1.Mul(z2), "z1 = [" & z1.ToString() & "] z2 = [" & z2.ToString() & "]")
|
||||
AddComplexTest("z1.MulImag(3.45)", z1.MulImag(3.45), z1.MulImag(3.45), "z1 = " & z1.ToString())
|
||||
AddComplexTest("z1.MulReal(3.45)", z1.MulReal(3.45), z1.MulReal(3.45), "z1 = " & z1.ToString())
|
||||
z1.Polar(5, 2)
|
||||
AddComplexTest("z1.Polar(5,2)", z1.Copy(), z1.Copy(), "z1 = " & z1.ToString())
|
||||
AddComplexTest("z1.Pow(z2)", z1.Pow(z2), z1.Pow(z2), "z1 = [" & z1.ToString() & "] z2 = [" & z2.ToString() & "]")
|
||||
AddComplexTest("z1.PowReal(2) ", z1.PowReal(2), z1.PowReal(2), "z1 = [" & z1.ToString() & "] z2 = [" & z2.ToString() & "]")
|
||||
z1.Rect(1, 1)
|
||||
AddComplexTest("z1.Rect(1,1)", z1.Copy(), z1.Copy(), "z1 = " & z1.ToString())
|
||||
AddComplexTest("z1.Sec()", z1.Sec(), z1.Sec(), "z1 = " & z1.ToString())
|
||||
AddComplexTest("z1.Sech()", z1.Sech(), z1.Sech(), "z1 = " & z1.ToString())
|
||||
z1.Set(2, 2)
|
||||
AddComplexTest("z1.Set(2,2)", z1.Copy(), z1.Copy(), "z1 = " & z1.ToString())
|
||||
AddComplexTest("z1.Sin()", z1.Sin(), z1.Sin(), "z1 = " & z1.ToString())
|
||||
AddComplexTest("z1.Sinh()", z1.Sinh(), z1.Sinh(), "z1 = " & z1.ToString())
|
||||
AddComplexTest("z1.Sqrt()", z1.Sqrt(), z1.Sqrt(), "z1 = " & z1.ToString())
|
||||
AddComplexTest("z1.SqrtReal(3.45)", z1.SqrtReal(3.45), z1.SqrtReal(3.45), "z1 = " & z1.ToString())
|
||||
AddComplexTest("z1.Sub(z2)", z1.Sub(z2), z1.Sub(z2), "z1 = [" & z1.ToString() & "] z2 = [" & z2.ToString() & "]")
|
||||
AddComplexTest("z1.SubImag(1.321)", z1.SubImag(1.321), z1.SubImag(1.321), "z1 = " & z1.ToString())
|
||||
AddComplexTest("z1.SubReal(2.125)", z1.SubReal(2.125), z1.SubReal(2.125), "z1 = " & z1.ToString())
|
||||
AddComplexTest("z1.Tan()", z1.Tan(), z1.Tan(), "z1 = " & z1.ToString())
|
||||
AddComplexTest("z1.Tanh()", z1.Tanh(), z1.Tanh(), "z1 = " & z1.ToString())
|
||||
|
||||
End
|
||||
|
||||
|
||||
'-------------------------------------------------------------------
|
||||
' Add Polynomial Tests
|
||||
'-------------------------------------------------------------------
|
||||
Public Sub AddPolynomialTest(name As String, result As Variant, expected As Variant, Optional note As String)
|
||||
|
||||
Dim t As New TestPolynomial
|
||||
|
||||
ts.AddTest(t)
|
||||
t.Run(name, result, expected, note)
|
||||
|
||||
End
|
||||
|
||||
|
||||
'-------------------------------------------------------------------
|
||||
' Polynomial Tests
|
||||
'-------------------------------------------------------------------
|
||||
Public Sub testPolynomialMethods()
|
||||
Dim c As New Complex
|
||||
Dim p1 As New Polynomial
|
||||
Dim p2 As New Polynomial
|
||||
Dim p3 As Polynomial
|
||||
Dim f1 As Float
|
||||
Dim f2 As Float
|
||||
|
||||
p1.AddCoef(0.565)
|
||||
p1.AddCoef(1.738)
|
||||
p1.AddCoef(3.1465)
|
||||
|
||||
AddPolynomialTest("p1.AddCoef(0.565)", p1.AddCoef(0.565), 1, p1.ToString())
|
||||
AddPolynomialTest("p1.AddCoef(1.738)", p1.AddCoef(1.738), 2, p1.ToString())
|
||||
AddPolynomialTest("p1.AddCoef(3.1465)", p1.AddCoef(3.1465), 3, p1.ToString())
|
||||
|
||||
|
||||
End Sub
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
'-------------------------------------------------------------------
|
||||
'Run all tests
|
||||
'-------------------------------------------------------------------
|
||||
Public Sub Main()
|
||||
|
||||
' Setup test suite
|
||||
ts.Name = "GSL Component"
|
||||
ts.HeaderChar = "="
|
||||
ts.HeaderWidth = 40
|
||||
ts.TestHeaderChar = "-"
|
||||
ts.TestHeaderWidth = 40
|
||||
ts.Note = "This test suite was developed for use\n"
|
||||
"with GSL Component development. However,\n"
|
||||
"it may be useful in other projects."
|
||||
ts.ShowTestNotes = True
|
||||
|
||||
'Run our GSL Class Tests
|
||||
testGslMethods()
|
||||
testGslConstance
|
||||
|
||||
'Run Complex Class Test
|
||||
testComplexMethods()
|
||||
|
||||
'Run Polynomial Class Test
|
||||
testPolynomialMethods()
|
||||
|
||||
|
||||
' Finnish by showing test results
|
||||
ts.ShowTests()
|
||||
End
|
||||
|
||||
|
@ -1,199 +0,0 @@
|
||||
' Gambas class file
|
||||
|
||||
' ==================================================================
|
||||
' @Class: TestSuite
|
||||
' @Author: R Morgan <rmorgan62@gmail.com>
|
||||
' @Date: 03/01/2012
|
||||
' @Ver: 0.01
|
||||
' @Desc: A framework for running unit and regression tests.
|
||||
' ==================================================================
|
||||
Public Name As String ' Name of test, usually the function or method name.
|
||||
Public msgError As String ' Error Message if any
|
||||
Public hasError As Boolean = False ' True is we find an error
|
||||
Public Expected As Variant ' Expected Value
|
||||
Public Result As Variant ' Result value
|
||||
Public ExpType As String ' Expected Datatype
|
||||
Public ResType As String ' Result Datatype
|
||||
Public Note As String ' Note on test
|
||||
|
||||
'-------------------------------------------------------------------
|
||||
'@Sub: AddError
|
||||
'@Desc: This method simply adds the passed error string to the
|
||||
'error message array.
|
||||
'@Ver:0.01
|
||||
'@First: 03/01/2012
|
||||
'@Returns: Void
|
||||
'@Param msg - A string containing the error message
|
||||
'-------------------------------------------------------------------
|
||||
Public Sub AddError(msg As String)
|
||||
|
||||
Me.msgError = msg
|
||||
Me.hasError = True
|
||||
|
||||
End
|
||||
|
||||
|
||||
'-------------------------------------------------------------------
|
||||
'@Func; TypeError
|
||||
'@Desc: This method creates an error message for a type error
|
||||
'@Ver:0.01
|
||||
'@First: 03/01/2012
|
||||
'@Returns: A string containing the type error message.
|
||||
'@Param msg - A string containing the type as a string.
|
||||
'-------------------------------------------------------------------
|
||||
Public Function TypeError(gotType As String, expectedType As String) As String
|
||||
|
||||
Dim msg As String
|
||||
|
||||
msg = "Type error :<<< Expected type: " & expectedType & " Got type: " & gotType & " >>>"
|
||||
|
||||
Return msg
|
||||
|
||||
End
|
||||
|
||||
|
||||
'-------------------------------------------------------------------
|
||||
'@Desc: This method simply adds the passed error string to the
|
||||
'error message array.
|
||||
'@Ver:0.01
|
||||
'@First: 03/01/2012
|
||||
'@Returns: Void
|
||||
'@Param: msg - A string containing the error message
|
||||
'-------------------------------------------------------------------
|
||||
Public Function ValueError(gotValue As Variant, expectedValue As Variant) As String
|
||||
|
||||
Dim msg As String
|
||||
|
||||
msg = "Value error: <<< Expected: " & Str(expectedValue) & " Got: " & Str(gotValue) & " >>>"
|
||||
Return msg
|
||||
|
||||
End
|
||||
|
||||
|
||||
'-------------------------------------------------------------------
|
||||
'@Desc: This method simply adds the passed error string to the
|
||||
'error message array.
|
||||
'@Ver:0.01
|
||||
'@First: 03/17/2012
|
||||
'@Returns: Void
|
||||
'@Params: msg - A string contianing the error message.
|
||||
'-------------------------------------------------------------------
|
||||
Public Function LengthError(result As Integer, expected As Integer) As String
|
||||
Dim msg As String
|
||||
|
||||
msg = "Length error: <<< Expected a length of " & Str(expected) & " Got: " & Str(expected) & " >>>"
|
||||
Return msg
|
||||
|
||||
End
|
||||
|
||||
|
||||
'-------------------------------------------------------------------
|
||||
'@Desc: This method simply adds the passed error string to the
|
||||
'error message array.
|
||||
'@Ver:0.01
|
||||
'@First: 03/01/2012
|
||||
'@Returns: Void
|
||||
'@Param msg - A string containing the error message
|
||||
'-------------------------------------------------------------------
|
||||
Public Function getTypeString(p As Variant) As String
|
||||
|
||||
Select Case TypeOf(p)
|
||||
Case gb.NULL
|
||||
Return "NULL"
|
||||
Case gb.Boolean
|
||||
Return "Boolean"
|
||||
Case gb.Byte
|
||||
Return "Byte"
|
||||
Case gb.Class
|
||||
Return "Class"
|
||||
Case gb.Date
|
||||
Return "Date"
|
||||
Case gb.Float
|
||||
Return "Float"
|
||||
Case gb.Integer
|
||||
Return "Integer"
|
||||
Case gb.Long
|
||||
Return "Long"
|
||||
Case gb.Object
|
||||
Return "Object"
|
||||
Case gb.Pointer
|
||||
Return "Pointer"
|
||||
Case gb.Short
|
||||
Return "Short"
|
||||
Case gb.Single
|
||||
Return "Single"
|
||||
Case gb.String
|
||||
Return "String"
|
||||
Case gb.Variant
|
||||
Return "Variant"
|
||||
Default
|
||||
Return "Unknown"
|
||||
End Select
|
||||
|
||||
End
|
||||
|
||||
|
||||
'-------------------------------------------------------------------
|
||||
'Compare two value for equality
|
||||
'-------------------------------------------------------------------
|
||||
Public Function IsEqual(result As Variant, expected As Variant) As Boolean
|
||||
Dim err As Boolean = False
|
||||
Dim i As Integer = 0
|
||||
|
||||
If TypeOf(result) <> TypeOf(expected) Then
|
||||
AddError(TypeError(Me.ResType, Me.ExpType))
|
||||
Me.hasError = True
|
||||
Else
|
||||
If result Is Object And result Is Array And expected Is Array Then
|
||||
If result.len <> expected.len Then
|
||||
Me.hasError(LengthError(result.len, expected.len))
|
||||
Else
|
||||
For i = 0 To result.len - 1
|
||||
If result[i] <> expected[i] Then
|
||||
Me.hasError = True
|
||||
Endif
|
||||
Next
|
||||
Endif
|
||||
|
||||
Else
|
||||
If result <> expected Then
|
||||
AddError(ValueError(Me.Result, Me.Expected))
|
||||
Me.hasError = True
|
||||
Endif
|
||||
Endif
|
||||
Endif
|
||||
|
||||
Return Me.hasError
|
||||
|
||||
End
|
||||
|
||||
|
||||
|
||||
'-------------------------------------------------------------------
|
||||
'@Desc: This method tests the given values for equality in both
|
||||
' type and value.
|
||||
'@Ver:0.01
|
||||
'@First: 03/01/2012
|
||||
'@Returns:
|
||||
'@Param: func - A string containing the function that was tested.
|
||||
'@Param: result - A variant value containing the actual result of
|
||||
' the test.
|
||||
'@Param: expected - A variant value containing the expected result
|
||||
'value for the test.
|
||||
'-------------------------------------------------------------------
|
||||
Public Sub Run(func As String, result As Variant, expected As Variant, Optional note As String) As Boolean
|
||||
|
||||
Dim err As Boolean = False
|
||||
|
||||
Me.Name = func
|
||||
Me.Note = note
|
||||
|
||||
Me.Expected = expected
|
||||
Me.ExpType = getTypeString(expected)
|
||||
|
||||
Me.Result = result
|
||||
Me.ResType = Me.getTypeString(result)
|
||||
|
||||
Return IsEqual(result, expected)
|
||||
|
||||
End
|
@ -1,94 +0,0 @@
|
||||
' Gambas class file
|
||||
|
||||
Inherits Test
|
||||
|
||||
Public Function getComplexTypeString(p As Variant) As String
|
||||
Dim result As String
|
||||
|
||||
result = getTypeString(p)
|
||||
|
||||
If result = "Unknown" Then
|
||||
If result Is Complex Then
|
||||
result = "Complex"
|
||||
Endif
|
||||
Endif
|
||||
|
||||
Return result
|
||||
|
||||
End
|
||||
|
||||
|
||||
Public Sub IsComplexEqual(result As Variant, expected As Variant) As Boolean
|
||||
|
||||
If result Is Complex Or expected Is Complex Then
|
||||
'We have objects that need special processing
|
||||
If Me.IsEqual(result, expected) Then
|
||||
Me.Result = result.ToString()
|
||||
Me.ResType = "Complext"
|
||||
Me.Expected = expected.ToString()
|
||||
Me.ExpType = "Complex"
|
||||
Else
|
||||
Me.AddError(Me.ValueError(result.ToString, expected.ToString))
|
||||
Me.hasError = True
|
||||
Endif
|
||||
Else
|
||||
Me.hasError = Me.IsEqual(result, expected)
|
||||
Endif
|
||||
|
||||
Return Me.hasError
|
||||
|
||||
End
|
||||
|
||||
|
||||
Public Sub Run(func As String, result As Variant, expected As Variant, Optional note As String) As Boolean
|
||||
Dim err As Boolean = False
|
||||
|
||||
Me.Name = func
|
||||
Me.Note = note
|
||||
|
||||
Me.Expected = expected
|
||||
Me.ExpType = Me.getTypeString(expected)
|
||||
|
||||
|
||||
Me.Result = result
|
||||
Me.ResType = Me.getTypeString(result)
|
||||
|
||||
If TypeOf(result) <> gb.Object And TypeOf(expected) <> gb.Object Then
|
||||
' Not an object so run parent code
|
||||
If TypeOf(result) <> TypeOf(expected) Then
|
||||
Me.AddError(Me.TypeError(Me.ResType, Me.ExpType))
|
||||
err = True
|
||||
Else
|
||||
If result <> expected Then
|
||||
Me.AddError(Me.ValueError(Me.Result, Me.Expected))
|
||||
err = True
|
||||
Endif
|
||||
Endif
|
||||
Else
|
||||
'We have objects that need special processing
|
||||
If TypeOf(result) <> TypeOf(expected) Then
|
||||
Me.AddError(Me.TypeError(Me.ResType, Me.ExpType))
|
||||
err = True
|
||||
Else
|
||||
If result Is Complex And expected Is Complex Then
|
||||
If Me.IsEqual(result, expected) Then
|
||||
Me.Result = result.ToString()
|
||||
Me.ResType = "Complex Object"
|
||||
Me.Expected = expected.ToString()
|
||||
Me.ExpType = "Complex Object"
|
||||
Else
|
||||
Me.AddError(Me.ValueError(result.ToString, expected.ToString))
|
||||
err = True
|
||||
Endif
|
||||
Endif
|
||||
Endif
|
||||
|
||||
Endif
|
||||
|
||||
Return Me.hasError
|
||||
|
||||
|
||||
|
||||
End
|
||||
|
||||
|
@ -1,141 +0,0 @@
|
||||
' Gambas class file
|
||||
|
||||
' ==================================================================
|
||||
' @Class: TestSuite
|
||||
' @Author: R Morgan <rmorgan62@gmail.com>
|
||||
' @Date: 03/01/2012
|
||||
' @Ver: 0.01
|
||||
' @Desc: A framework for running unit and regression tests.
|
||||
' ==================================================================
|
||||
|
||||
Public numErrors As Integer
|
||||
Public msgErrors As New String[]
|
||||
Private numTests As Integer
|
||||
Public Tests As New Test[]
|
||||
Public hasErrors As Boolean
|
||||
Public HeaderChar As String = "="
|
||||
Public HeaderWidth As Integer = 40
|
||||
Public TestHeaderChar As String = "-"
|
||||
Public TestHeaderWidth As Integer = 40
|
||||
Public Name As String
|
||||
|
||||
Public Note As String
|
||||
Public NoteHeaderChar As String = "*"
|
||||
Public NoteHeaderWidth As Integer = 40
|
||||
Public ShowTestNotes As Boolean = False
|
||||
|
||||
|
||||
Public Sub AddTest(t As Test)
|
||||
|
||||
Tests.Add(t)
|
||||
numTests += 1
|
||||
|
||||
End
|
||||
|
||||
|
||||
|
||||
Public Procedure ErrorCount() As Integer
|
||||
Dim i As Integer
|
||||
Dim t As Test
|
||||
|
||||
For i = 0 To Tests.Length - 1
|
||||
t = Tests[i]
|
||||
If t.hasError Then
|
||||
Me.numErrors += 1
|
||||
Me.hasErrors = True
|
||||
Endif
|
||||
Next
|
||||
|
||||
Return Me.numErrors
|
||||
End
|
||||
|
||||
|
||||
|
||||
|
||||
Public Sub ShowHeader()
|
||||
Dim Header As String
|
||||
|
||||
Me.ErrorCount()
|
||||
|
||||
Header = String$(Me.HeaderWidth, Me.HeaderChar)
|
||||
Header &= "\n " & Name & " test\n"
|
||||
Header &= " Date: " & Date() & "\n"
|
||||
Header &= " Time: " & Time() & "\n"
|
||||
|
||||
If Me.hasErrors Then
|
||||
Header &= " Failure:" & Me.numErrors & " errors occurred.\n"
|
||||
Else
|
||||
Header &= " Success: All tests passed.\n"
|
||||
Endif
|
||||
|
||||
Header &= " There are " & numTests & " test in this run.\n"
|
||||
Header &= String$(Me.HeaderWidth, Me.HeaderChar)
|
||||
Header &= "\n\n"
|
||||
|
||||
Print Header
|
||||
|
||||
End
|
||||
|
||||
Public Sub ShowNotes()
|
||||
Dim Header As String
|
||||
|
||||
If Len(Me.Note) > 0 Then
|
||||
Header = String$(Me.NoteHeaderWidth, Me.NoteHeaderChar)
|
||||
Header &= "\n"
|
||||
Header &= Me.Note & "\n"
|
||||
Header &= String$(Me.NoteHeaderWidth, Me.NoteHeaderChar)
|
||||
Header &= "\n\n"
|
||||
|
||||
Print Header
|
||||
|
||||
Endif
|
||||
|
||||
End
|
||||
|
||||
|
||||
|
||||
Public Sub ShowTest(idx As Integer)
|
||||
Dim t As New Test
|
||||
Dim header As String
|
||||
Dim cnt As Integer = idx + 1
|
||||
t = Tests[idx]
|
||||
|
||||
header = String$(Me.TestHeaderWidth, Me.TestHeaderChar)
|
||||
header &= "\n #" & cnt & " " & t.Name & "\n"
|
||||
|
||||
If t.hasError Then
|
||||
header &= " Status: <<<<< Failure >>>>> \n"
|
||||
header &= " Error: " & t.msgError & "\n"
|
||||
Else
|
||||
header &= " Status: Passed \n"
|
||||
Endif
|
||||
|
||||
header &= " Expected result: " & Str(t.Expected) & "\n of type: " & t.ExpType & "\n"
|
||||
header &= " Recieved result: " & Str(t.Result) & "\n of type: " & t.ResType & "\n"
|
||||
|
||||
If ShowTestNotes Then
|
||||
header &= " Notes: " & t.Note & "\n"
|
||||
Endif
|
||||
header &= String$(Me.TestHeaderWidth, Me.TestHeaderChar)
|
||||
|
||||
Print header
|
||||
|
||||
End
|
||||
|
||||
|
||||
Public Sub ShowTests()
|
||||
Dim t As Test
|
||||
Dim i As Integer
|
||||
|
||||
Me.ShowHeader()
|
||||
Me.ShowNotes()
|
||||
|
||||
i = 0
|
||||
For i = 0 To Tests.Length - 1
|
||||
ShowTest(i)
|
||||
Next
|
||||
|
||||
End
|
||||
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user