[GB.GSL]
* NEW: Added Test Suite Gambas Project to GSL Component. git-svn-id: svn://localhost/gambas/trunk@4527 867c0c6c-44f3-4631-809d-bfa615b0a4ec
This commit is contained in:
parent
a786448db0
commit
7dcd32d1b6
28 changed files with 1503 additions and 35 deletions
2
gb.gsl/Test/test/.directory
Normal file
2
gb.gsl/Test/test/.directory
Normal file
|
@ -0,0 +1,2 @@
|
|||
[Desktop Entry]
|
||||
Icon=./.icon.png
|
BIN
gb.gsl/Test/test/.gambas/MMAIN
Normal file
BIN
gb.gsl/Test/test/.gambas/MMAIN
Normal file
Binary file not shown.
BIN
gb.gsl/Test/test/.gambas/TEST
Normal file
BIN
gb.gsl/Test/test/.gambas/TEST
Normal file
Binary file not shown.
BIN
gb.gsl/Test/test/.gambas/TESTCOMPLEX
Normal file
BIN
gb.gsl/Test/test/.gambas/TESTCOMPLEX
Normal file
Binary file not shown.
BIN
gb.gsl/Test/test/.gambas/TESTSUITE
Normal file
BIN
gb.gsl/Test/test/.gambas/TESTSUITE
Normal file
Binary file not shown.
BIN
gb.gsl/Test/test/.icon.png
Normal file
BIN
gb.gsl/Test/test/.icon.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 3.7 KiB |
9
gb.gsl/Test/test/.project
Normal file
9
gb.gsl/Test/test/.project
Normal file
|
@ -0,0 +1,9 @@
|
|||
# Gambas Project File 3.0
|
||||
# Compiled with Gambas 3.0.90
|
||||
Title=test
|
||||
Startup=MMain
|
||||
Version=0.0.1
|
||||
Component=gb.gsl
|
||||
Component=gb.option
|
||||
Component=gb.xml
|
||||
TabSize=2
|
23
gb.gsl/Test/test/.settings
Normal file
23
gb.gsl/Test/test/.settings
Normal file
|
@ -0,0 +1,23 @@
|
|||
[Breakpoints]
|
||||
Count=0
|
||||
|
||||
[DebugWindow]
|
||||
Count=0
|
||||
|
||||
[DebugWindow/Tests]
|
||||
Geometry=[0,0,210,210]
|
||||
|
||||
[DebugWindow/v]
|
||||
Geometry=[0,0,210,210]
|
||||
|
||||
[OpenFile]
|
||||
Active=1
|
||||
File[1]=".src/MMain.module:168.2"
|
||||
File[2]=".src/TestSuite.class:115.39"
|
||||
File[3]=".src/Test.class:128.80"
|
||||
File[4]=".src/TestComplex.class:19.16"
|
||||
Count=4
|
||||
|
||||
[Watches]
|
||||
Count=0
|
||||
|
203
gb.gsl/Test/test/.src/MMain.module
Normal file
203
gb.gsl/Test/test/.src/MMain.module
Normal file
|
@ -0,0 +1,203 @@
|
|||
' 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()
|
||||
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)
|
||||
'AddTest("GSL.Frexp(0.45)", GSL.Frexp(0.45), GSL.Frexp(0.45)
|
||||
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
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
'-------------------------------------------------------------------
|
||||
'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()
|
||||
|
||||
' Finnish by showing test results
|
||||
ts.ShowTests()
|
||||
End
|
||||
|
||||
|
210
gb.gsl/Test/test/.src/MMain.module~
Normal file
210
gb.gsl/Test/test/.src/MMain.module~
Normal file
|
@ -0,0 +1,210 @@
|
|||
' 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()
|
||||
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)
|
||||
'AddTest("GSL.Frexp(0.45)", GSL.Frexp(0.45), GSL.Frexp(0.45)
|
||||
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
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
'-------------------------------------------------------------------
|
||||
'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()
|
||||
|
||||
' Finnish by showing test results
|
||||
ts.ShowTests()
|
||||
End
|
||||
|
||||
|
154
gb.gsl/Test/test/.src/Test.class
Normal file
154
gb.gsl/Test/test/.src/Test.class
Normal file
|
@ -0,0 +1,154 @@
|
|||
' 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/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
|
||||
|
||||
'-------------------------------------------------------------------
|
||||
'@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 = getTypeString(result)
|
||||
|
||||
If TypeOf(result) <> TypeOf(expected) Then
|
||||
AddError(TypeError(Me.ResType, Me.ExpType))
|
||||
err = True
|
||||
Else
|
||||
If result <> expected Then
|
||||
AddError(ValueError(Me.Result, Me.Expected))
|
||||
err = True
|
||||
Endif
|
||||
Endif
|
||||
|
||||
Return Me.hasError
|
||||
End
|
154
gb.gsl/Test/test/.src/Test.class~
Normal file
154
gb.gsl/Test/test/.src/Test.class~
Normal file
|
@ -0,0 +1,154 @@
|
|||
' 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/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
|
||||
|
||||
'-------------------------------------------------------------------
|
||||
'@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 = getTypeString(result)
|
||||
|
||||
If TypeOf(result) <> TypeOf(expected) Then
|
||||
AddError(TypeError(Me.ResType, Me.ExpType))
|
||||
err = True
|
||||
Else
|
||||
If result <> expected Then
|
||||
AddError(ValueError(Me.Result, Me.Expected))
|
||||
err = True
|
||||
Endif
|
||||
Endif
|
||||
|
||||
Return Me.hasError
|
||||
End
|
67
gb.gsl/Test/test/.src/TestComplex.class
Normal file
67
gb.gsl/Test/test/.src/TestComplex.class
Normal file
|
@ -0,0 +1,67 @@
|
|||
' Gambas class file
|
||||
|
||||
Inherits Test
|
||||
|
||||
Public Sub IsEqual(z1 As Complex, z2 As Complex) As Boolean
|
||||
|
||||
If (z1.Real = z2.Real) And z1.Imag = z2.Imag Then
|
||||
Return True
|
||||
Else
|
||||
Return False
|
||||
Endif
|
||||
|
||||
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 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
|
||||
|
||||
|
66
gb.gsl/Test/test/.src/TestComplex.class~
Normal file
66
gb.gsl/Test/test/.src/TestComplex.class~
Normal file
|
@ -0,0 +1,66 @@
|
|||
' Gambas class file
|
||||
|
||||
Inherits Test
|
||||
|
||||
Public Sub IsEqual(z1 As Complex, z2 As Complex) As Boolean
|
||||
|
||||
If (z1.Real = z2.Real) And z1.Imag = z2.Imag Then
|
||||
Return True
|
||||
Else
|
||||
Return False
|
||||
Endif
|
||||
|
||||
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.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 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
|
||||
|
||||
|
141
gb.gsl/Test/test/.src/TestSuite.class
Normal file
141
gb.gsl/Test/test/.src/TestSuite.class
Normal file
|
@ -0,0 +1,141 @@
|
|||
' 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 And Len(t.Note) <> 0 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
|
||||
|
||||
|
||||
|
141
gb.gsl/Test/test/.src/TestSuite.class~
Normal file
141
gb.gsl/Test/test/.src/TestSuite.class~
Normal file
|
@ -0,0 +1,141 @@
|
|||
' 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
|
||||
|
||||
|
||||
|
10
gb.gsl/Test/test/.startup
Normal file
10
gb.gsl/Test/test/.startup
Normal file
|
@ -0,0 +1,10 @@
|
|||
MMain
|
||||
test
|
||||
0
|
||||
0
|
||||
0.0.1
|
||||
|
||||
gb.gsl
|
||||
gb.option
|
||||
gb.xml
|
||||
|
|
@ -10,5 +10,14 @@ GB_COMPONENT_PKG_CONFIG(
|
|||
[GNU Scientific Library component],
|
||||
[src],
|
||||
gsl)
|
||||
GB_COMPONENT_SEARCH(
|
||||
gslcblas,
|
||||
GSLCBLAS,
|
||||
[GSL BLAS],
|
||||
[src],
|
||||
libgsl libgslcblas,
|
||||
[GB_FIND(gsl/gsl_cblas.h gsl/gsl_math.h, /usr /usr/local `gsl-config --prefix`, include include/gsl)],
|
||||
[GB_FIND(libgslcblas.$SHLIBEXT libgsl.$SHLIBEXT, /usr/lib /usr/local /usr/local/lib `gsl-config --prefix`, lib)],
|
||||
[$X_LIBS -llibgsl -llibgslcblas])
|
||||
AC_OUTPUT( Makefile src/Makefile )
|
||||
GB_PRINT_MESSAGES
|
||||
|
|
|
@ -8,4 +8,4 @@ gblib_LTLIBRARIES = gb.gsl.la
|
|||
gb_gsl_la_LIBADD = @GSL_LIB@
|
||||
gb_gsl_la_LDFLAGS = -module @LD_FLAGS@ @GSL_LDFLAGS@
|
||||
|
||||
gb_gsl_la_SOURCES = main.c main.h c_gsl.c c_gsl.h c_complex.c c_complex.h c_polynomial.c c_polynomial.h
|
||||
gb_gsl_la_SOURCES = main.c main.h c_gsl.c c_gsl.h c_complex.c c_complex.h c_polynomial.c c_polynomial.h c_complexpolynomial.c c_complexpolynomial.h
|
||||
|
|
|
@ -43,7 +43,12 @@
|
|||
***********************************/
|
||||
GSLCOMPLEX *GSLComplex_create()
|
||||
{
|
||||
return (GSLCOMPLEX *)GB.New(GB.FindClass("Complex"), NULL, NULL);
|
||||
GSLCOMPLEX *c;
|
||||
c = (GSLCOMPLEX *)GB.New(GB.FindClass("Complex"), NULL, NULL);
|
||||
c->number.dat[0] = 0.0;
|
||||
c->number.dat[1] = 0.0;
|
||||
|
||||
return c;
|
||||
}
|
||||
|
||||
BEGIN_METHOD(GslComplex_new, GB_FLOAT real; GB_FLOAT imag)
|
||||
|
@ -104,11 +109,15 @@ BEGIN_METHOD_VOID(GslComplex_ToString)
|
|||
{
|
||||
if (imag < 0.0)
|
||||
{
|
||||
*p++ = ' ';
|
||||
*p++ = '-';
|
||||
*p++ = ' ';
|
||||
imag = (-imag);
|
||||
}
|
||||
else if (p != buffer)
|
||||
*p++ = ' ';
|
||||
*p++ = '+';
|
||||
*p++ = ' ';
|
||||
|
||||
if (imag != 1.0)
|
||||
{
|
||||
|
|
|
@ -32,7 +32,6 @@
|
|||
#include <gsl/gsl_complex.h>
|
||||
#include <gsl/gsl_complex_math.h>
|
||||
|
||||
//GSLCOMPLEX GslComplex_Add_Real(GB_FLOAT x);
|
||||
|
||||
GB_INTERFACE GB EXPORT;
|
||||
|
||||
|
@ -43,8 +42,6 @@ typedef
|
|||
{
|
||||
GB_BASE ob;
|
||||
gsl_complex number;
|
||||
//double real;
|
||||
//double imagined;
|
||||
}
|
||||
GSLCOMPLEX;
|
||||
|
||||
|
|
|
@ -22,10 +22,6 @@
|
|||
MA 02110-1301, USA.
|
||||
|
||||
***************************************************************************/
|
||||
/*=========================================================================
|
||||
=== NOTE THIS IS SIMPLE LEARNING CODE ===
|
||||
AND NOTHING USEFUL EXISTS HERE YET
|
||||
==========================================================================*/
|
||||
|
||||
#define __C_GSL_COMPLEXPOLYNOMIAL_C
|
||||
|
||||
|
@ -34,17 +30,263 @@
|
|||
|
||||
#define THIS ((CCOMPLEXPOLYNOMIAL *)_object)
|
||||
|
||||
static CCOMPLEXPOLYNOMIAL *create_plynomial()
|
||||
|
||||
/**************************************************
|
||||
Utility Methods
|
||||
**************************************************/
|
||||
|
||||
CCOMPLEXPOLYNOMIAL *create_complexplynomial()
|
||||
{
|
||||
return (CCOMPLEXPOLYNOMIAL *)GB.New(GB.FindClass("ComplexPolynomial"), NULL, NULL);
|
||||
}
|
||||
|
||||
|
||||
BEGIN_METHOD_VOID(CComplexPolynomial_new)
|
||||
|
||||
// May change to take init array of floats
|
||||
THIS->alloc_size = 32;
|
||||
THIS->max = 32;
|
||||
GB.NewArray((void *)&THIS->c, sizeof(gsl_complex), THIS->alloc_size);
|
||||
THIS->len = 0;
|
||||
|
||||
END_METHOD
|
||||
|
||||
|
||||
BEGIN_METHOD_VOID(CComplexPolynomial_call)
|
||||
// May be changed to take init array of floats
|
||||
CCOMPLEXPOLYNOMIAL *c = create_complexpolynomial();
|
||||
|
||||
GB.ReturnObject(c);
|
||||
|
||||
END_METHOD
|
||||
|
||||
|
||||
BEGIN_METHOD_VOID(CComplexPolynomial_free)
|
||||
|
||||
if(THIS->c != NULL && THIS->c != 0)
|
||||
GB.FreeArray((void *)&THIS->c);
|
||||
|
||||
END_METHOD
|
||||
|
||||
|
||||
BEGIN_METHOD_VOID(CComplexPolynomial_exit)
|
||||
|
||||
if(THIS->c != NULL)
|
||||
GB.FreeArray((GB_FLOAT *)&THIS->c);
|
||||
|
||||
END_METHOD
|
||||
|
||||
|
||||
|
||||
/**************************************************
|
||||
Property Methods
|
||||
**************************************************/
|
||||
|
||||
BEGIN_PROPERTY(CComplexPolynomial_Length)
|
||||
|
||||
if (READ_PROPERTY)
|
||||
GB.ReturnInteger((THIS->len));
|
||||
|
||||
END_PROPERTY
|
||||
|
||||
|
||||
BEGIN_PROPERTY(CComplexPolynomial_MaxCoef)
|
||||
|
||||
if (READ_PROPERTY)
|
||||
GB.ReturnInteger((THIS->max));
|
||||
|
||||
END_PROPERTY
|
||||
|
||||
|
||||
BEGIN_PROPERTY(CComplexPolynomial_AllocSize)
|
||||
|
||||
if (READ_PROPERTY)
|
||||
GB.ReturnInteger((THIS->alloc_size));
|
||||
else
|
||||
THIS->alloc_size = (VPROP(GB_INTEGER));
|
||||
|
||||
END_PROPERTY
|
||||
|
||||
|
||||
BEGIN_METHOD_VOID(CComplexPolynomial_ToString)
|
||||
|
||||
char buffer[256];
|
||||
char *p = buffer;
|
||||
char *str;
|
||||
int len;
|
||||
double real, imag;
|
||||
int i = 0;
|
||||
|
||||
for(i=0; i < THIS->len; i++)
|
||||
{
|
||||
real = THIS->c[i].dat[0];
|
||||
imag = THIS->c[i].dat[1];
|
||||
|
||||
if (real == 0.0 && imag == 0.0)
|
||||
{
|
||||
GB.ReturnConstZeroString("0");
|
||||
return;
|
||||
}
|
||||
|
||||
if (real != 0.0)
|
||||
{
|
||||
GB.NumberToString(FALSE, real, NULL, &str, &len);
|
||||
strncpy(p, str, len);
|
||||
p += len;
|
||||
}
|
||||
|
||||
if (imag != 0.0)
|
||||
{
|
||||
if (imag < 0.0)
|
||||
{
|
||||
*p++ = ' ';
|
||||
*p++ = '-';
|
||||
*p++ = ' ';
|
||||
imag = (-imag);
|
||||
}
|
||||
else if (p != buffer)
|
||||
*p++ = ' ';
|
||||
*p++ = '+';
|
||||
*p++ = ' ';
|
||||
|
||||
|
||||
if (imag != 1.0)
|
||||
{
|
||||
GB.NumberToString(FALSE, imag, NULL, &str, &len);
|
||||
strncpy(p, str, len);
|
||||
p += len;
|
||||
}
|
||||
*p++ = 'i';
|
||||
|
||||
}
|
||||
|
||||
*p++ = '\n';
|
||||
}
|
||||
|
||||
GB.ReturnNewString(buffer, p - buffer);
|
||||
|
||||
END_METHOD
|
||||
|
||||
|
||||
|
||||
/**************************************************
|
||||
Data Methods
|
||||
**************************************************/
|
||||
|
||||
BEGIN_METHOD(CComplexPolynomial_AddFloats, GB_FLOAT real; GB_FLOAT imag)
|
||||
|
||||
double *elm;
|
||||
|
||||
// Add a value to coeficent array
|
||||
if(THIS->max > THIS->len)
|
||||
{
|
||||
THIS->c[THIS->len].dat[0] = (double)VARG(real);
|
||||
THIS->c[THIS->len].dat[1] = (double)VARG(imag);
|
||||
THIS->len++;
|
||||
return GB.ReturnInteger(THIS->len);
|
||||
}
|
||||
else
|
||||
{
|
||||
if(THIS->c != NULL && THIS->c != 0)
|
||||
{
|
||||
GB.Add((void *)&THIS->c);
|
||||
THIS->max++;
|
||||
// *elm = VARG(x);
|
||||
THIS->c[THIS->len].dat[0] = (double)VARG(real);
|
||||
THIS->c[THIS->len].dat[1] = (double)VARG(imag);
|
||||
THIS->len++;
|
||||
}
|
||||
return GB.ReturnInteger(THIS->len);
|
||||
}
|
||||
|
||||
END_METHOD
|
||||
|
||||
|
||||
|
||||
/**************************************************
|
||||
Implementation Methods
|
||||
**************************************************/
|
||||
|
||||
BEGIN_METHOD_VOID(CComplexPolynomial_ComplexSolve)
|
||||
int i;
|
||||
gsl_complex z[THIS->len];
|
||||
GB_ARRAY cArray;
|
||||
GSLCOMPLEX *cx, *elt;
|
||||
|
||||
|
||||
gsl_poly_complex_workspace * w = gsl_poly_complex_workspace_alloc(THIS->len);
|
||||
|
||||
gsl_poly_complex_solve((double *)THIS->c, THIS->len, w, z);
|
||||
|
||||
gsl_poly_complex_workspace_free(w);
|
||||
|
||||
GB.Array.New(&cArray, GB.FindClass("Complex"), (long)(THIS->len-1));
|
||||
|
||||
for(i = 0; i < THIS->len-1; i++)
|
||||
{
|
||||
printf ("z%d = %+.18f %+.18f\n", i, GSL_REAL(z[i]), GSL_IMAG(z[i]));
|
||||
cx = GSLComplex_create();
|
||||
if(cx)
|
||||
{
|
||||
cx->number.dat[0] = GSL_REAL(z[i]);
|
||||
cx->number.dat[1] = GSL_IMAG(z[i]);
|
||||
printf ("cx[%d] = %+.18f %+.18f\n", i, cx->number.dat[0], cx->number.dat[1]);
|
||||
elt = (GSLCOMPLEX *)GB.Array.Get(&cArray, i);
|
||||
elt = cx;
|
||||
GB.Ref(cx);
|
||||
}
|
||||
else
|
||||
{
|
||||
GB.Error("Could not create result array", NULL, NULL);
|
||||
return;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
return GB.ReturnObject(cArray);
|
||||
|
||||
END_METHOD
|
||||
|
||||
/*
|
||||
GB_ARRAY array;
|
||||
|
||||
GB.Array.New(&array, GB.FindClass("Complex"), size);
|
||||
|
||||
// Create a new Complex
|
||||
|
||||
*GB.Array.Get(TheArray, index) = TheComplexPointer;
|
||||
|
||||
GB.Ref(TheComplexPointer);
|
||||
*/
|
||||
|
||||
|
||||
// Function: gsl_complex gsl_complex_poly_complex_eval (const gsl_complex c[], const int len, const gsl_complex z)
|
||||
// This function evaluates a polynomial with complex coefficients for the complex variable z.
|
||||
|
||||
|
||||
|
||||
GB_DESC CComplexPolynomialDesc[] =
|
||||
{
|
||||
GB_DECLARE("ComplexPoly", sizeof(CCOMPLEXPOLYNOMIAL)),
|
||||
GB_DECLARE("ComplexPolynomial", sizeof(CCOMPLEXPOLYNOMIAL)),
|
||||
|
||||
// Utility Methods
|
||||
GB_METHOD("_new", NULL, CComplexPolynomial_new, NULL),
|
||||
GB_METHOD("_call", "Polynomial", CComplexPolynomial_call, NULL),
|
||||
GB_METHOD("_free", NULL, CComplexPolynomial_free, NULL),
|
||||
GB_METHOD("_exit", NULL, CComplexPolynomial_exit, NULL),
|
||||
|
||||
// Property Methods
|
||||
GB_PROPERTY_READ("Len", "i", CComplexPolynomial_Length),
|
||||
GB_PROPERTY_READ("MaxCoef", "i", CComplexPolynomial_MaxCoef),
|
||||
GB_PROPERTY("AllocSize", "i", CComplexPolynomial_AllocSize),
|
||||
|
||||
// Data Methods
|
||||
//GB_METHOD("Add", "Complex", CComplexPolynomial_Add, "(Z)Complex"),
|
||||
GB_METHOD("AddFloat", "i", CComplexPolynomial_AddFloats, "[(X)f(Y)f]"),
|
||||
GB_METHOD("ToString", "s", CComplexPolynomial_ToString, NULL),
|
||||
|
||||
GB_METHOD("ComplexSolve", "Complex[];", CComplexPolynomial_ComplexSolve, NULL),
|
||||
|
||||
GB_END_DECLARE
|
||||
};
|
||||
|
||||
|
|
|
@ -26,9 +26,13 @@
|
|||
#ifndef __C_GSL_COMPLEXPOLYNOMIAL_H
|
||||
#define __C_GSL_COMPLEXPOLYNOMIAL_H
|
||||
|
||||
#include "gambas.h"
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
#include "../gambas.h"
|
||||
#include "gb_common.h"
|
||||
#include <gsl/gsl_poly.h>
|
||||
#include "c_complex.h"
|
||||
|
||||
|
||||
GB_INTERFACE GB EXPORT;
|
||||
|
||||
|
@ -39,8 +43,10 @@ extern GB_DESC CComplexPolynomialDesc[];
|
|||
typedef
|
||||
struct {
|
||||
GB_BASE ob;
|
||||
gsl_complex *c; // coefficients
|
||||
gsl_complex *c; // complex coefficients
|
||||
int len;
|
||||
int max;
|
||||
int alloc_size;
|
||||
}
|
||||
CCOMPLEXPOLYNOMIAL;
|
||||
|
||||
|
|
|
@ -127,14 +127,14 @@ BEGIN_METHOD(GSL_MINFLOAT, GB_FLOAT x; GB_FLOAT y;)
|
|||
END_METHOD
|
||||
|
||||
|
||||
BEGIN_METHOD(GSL_MAXINT, GB_FLOAT x; GB_FLOAT y;)
|
||||
BEGIN_METHOD(GSL_MAXINT, GB_INTEGER x; GB_INTEGER y;)
|
||||
|
||||
GB.ReturnInteger((VARG(x) > VARG(y) ? VARG(x) : VARG(y)));
|
||||
|
||||
END_METHOD
|
||||
|
||||
|
||||
BEGIN_METHOD(GSL_MININT, GB_FLOAT x; GB_FLOAT y;)
|
||||
BEGIN_METHOD(GSL_MININT, GB_INTEGER x; GB_INTEGER y;)
|
||||
|
||||
GB.ReturnInteger((VARG(x) < VARG(y) ? VARG(x) : VARG(y)));
|
||||
|
||||
|
@ -267,20 +267,33 @@ BEGIN_METHOD(GSL_FREXP, GB_FLOAT x;)
|
|||
b = 0.0;
|
||||
|
||||
r = gsl_frexp(VARG(x), &b);
|
||||
printf("r: %d \te: %i", r, b);
|
||||
printf("r: %d \te: %i\n", r, b);
|
||||
|
||||
GB.Array.New(&arr , GB_T_VARIANT , r);
|
||||
if(arr != NULL && arr != 0)
|
||||
GB_ARRAY result;
|
||||
GB.Array.New(POINTER(&result), GB_T_VARIANT, 0);
|
||||
|
||||
GB.Array.New(&arr , GB_T_VARIANT , 2);
|
||||
if(arr != NULL)
|
||||
{
|
||||
|
||||
//GB_FLOAT f;
|
||||
//GB_INTEGER i;
|
||||
|
||||
//f.value = r;
|
||||
//i.value = b;
|
||||
|
||||
v.value.value._float = r;
|
||||
*((GB_VARIANT *)GB.Array.Get(arr, 0)) = v;
|
||||
|
||||
q.value.value._integer = b;
|
||||
*((GB_VARIANT *)GB.Array.Get(arr, 1)) = q;
|
||||
}
|
||||
GB.ReturnObject(arr);
|
||||
v.type = GB_T_FLOAT;
|
||||
//*((GB_VARIANT *)GB.Array.Get(arr, 0)) = v;
|
||||
GB.StoreVariant(&v, GB.Array.Add(result));
|
||||
|
||||
q.value.value._integer = b;
|
||||
q.type = GB_T_INTEGER;
|
||||
//*((GB_VARIANT *)GB.Array.Get(arr, 1)) = q;
|
||||
GB.StoreVariant(&q, GB.Array.Add(result));
|
||||
}
|
||||
|
||||
GB.ReturnObject(arr);
|
||||
|
||||
END_METHOD
|
||||
/*
|
||||
GB.Array.New(&iArray , GB_T_INTEGER , 1);
|
||||
|
@ -372,10 +385,10 @@ GB_DESC CGslDesc[] =
|
|||
GB_STATIC_METHOD("Sign", "i", GSL_SIGNF, "(X)i"),
|
||||
GB_STATIC_METHOD("IsOdd", "b", GSL_ISODD, "(X)i"),
|
||||
GB_STATIC_METHOD("IsEven", "b", GSL_ISEVEN, "(X)i"),
|
||||
GB_STATIC_METHOD("MaxFloat", "f", GSL_MAXFLOAT, "[(X)f(Y)f"),
|
||||
GB_STATIC_METHOD("MaxFloat", "f", GSL_MAXFLOAT, "[(X)f(Y)f]"),
|
||||
GB_STATIC_METHOD("MinFLoat", "f", GSL_MINFLOAT, "[(X)f(Y)f]"),
|
||||
GB_STATIC_METHOD("MaxInt", "i", GSL_MAXINT, "[(X)i(Y)i]"),
|
||||
GB_STATIC_METHOD("MinInt", "i", GSL_MININT, "[(X)i(Y)i"),
|
||||
GB_STATIC_METHOD("MinInt", "i", GSL_MININT, "[(X)i(Y)i]"),
|
||||
GB_STATIC_METHOD("Fcmpb", "b", GSL_FCMPB, "[(X)f(Y)f(E)f]"),
|
||||
GB_STATIC_METHOD("Fcmpi", "i", GSL_FCMPI, "[(X)f(Y)f(E)f]"),
|
||||
|
||||
|
@ -388,7 +401,7 @@ GB_DESC CGslDesc[] =
|
|||
GB_STATIC_METHOD("Asinh", "f", GSL_ASINH, "(X)f"),
|
||||
GB_STATIC_METHOD("Atanh", "f", GSL_ATANH, "(X)f"),
|
||||
GB_STATIC_METHOD("Ldexp", "f", GSL_LDEXP, "[(X)f(E)i]"),
|
||||
//GB_STATIC_METHOD("Frexp", "a", GSL_FREXP, "(X)f"),
|
||||
GB_STATIC_METHOD("Frexp", "v[];", GSL_FREXP, "(X)f"),
|
||||
|
||||
// Return x^y using a small int safe method
|
||||
GB_STATIC_METHOD("IntPow", "f", GSL_INTPOW, "[(X)f(I)i]"),
|
||||
|
|
|
@ -194,8 +194,8 @@ BEGIN_METHOD(CPolynomial_Eval, GB_FLOAT x;)
|
|||
|
||||
if(3 > THIS->len)
|
||||
{
|
||||
GB.Error(GB_ERR_BOUND);
|
||||
//GB.Error("Method takes a minimum of 3 coefficients &1 given.", THIS->len);
|
||||
GB.Error(GB_ERR_BOUND);
|
||||
return GB.ReturnFloat(0);
|
||||
}
|
||||
|
||||
|
@ -215,11 +215,16 @@ BEGIN_METHOD(CPolynomial_ComplexEval, GB_OBJECT z)
|
|||
|
||||
obj = GSLComplex_create();
|
||||
|
||||
|
||||
// TODO Figure out error when compiling gsl_poly_complex_eval()
|
||||
// It seems this function is not in the library or linker is linking
|
||||
// to an older version of the library that does not have this method.
|
||||
//obj = gsl_poly_complex_eval(THIS->c, THIS->len, z->number);
|
||||
if(1 <= THIS->len)
|
||||
{
|
||||
obj->number = gsl_poly_complex_eval(THIS->c, THIS->len, z->number);
|
||||
}
|
||||
else
|
||||
{
|
||||
//GB.Error("Method takes a minimum of 1 coefficients &1 given.", THIS->len);
|
||||
GB.Error(GB_ERR_BOUND);
|
||||
return GB.ReturnObject(obj);
|
||||
}
|
||||
|
||||
GB.ReturnObject(obj);
|
||||
|
||||
|
@ -261,6 +266,7 @@ BEGIN_METHOD_VOID(CPolynomial_SolveQuadratic)
|
|||
}
|
||||
else
|
||||
{
|
||||
//GB.Error("Method takes a minimum of 3 coefficients &1 given.", THIS->len);
|
||||
GB.Error(GB_ERR_BOUND);
|
||||
return GB.ReturnObject(arr);
|
||||
}
|
||||
|
@ -304,6 +310,7 @@ BEGIN_METHOD_VOID(CPolynomial_SolveCubic)
|
|||
}
|
||||
else
|
||||
{
|
||||
//GB.Error("Method takes a minimum of 3 coefficients &1 given.", THIS->len);
|
||||
GB.Error(GB_ERR_BOUND);
|
||||
return GB.ReturnObject(arr);
|
||||
}
|
||||
|
@ -311,6 +318,7 @@ BEGIN_METHOD_VOID(CPolynomial_SolveCubic)
|
|||
END_METHOD
|
||||
|
||||
|
||||
// Maybe should be in complexpolynomial....
|
||||
|
||||
/**************************************************
|
||||
Describe Class properties and methods to Gambas
|
||||
|
@ -337,9 +345,10 @@ GB_DESC CPolynomialDesc[] =
|
|||
|
||||
// Implementation Methods
|
||||
GB_METHOD("Eval", "f", CPolynomial_Eval, "(X)f"),
|
||||
//GB_METHOD("ComplexEval", "Complex", CPolynomial_ComplexEval, "(Z)Complex"),
|
||||
GB_METHOD("ComplexEval", "Complex", CPolynomial_ComplexEval, "(Z)Complex"),
|
||||
GB_METHOD("SolveQuadratic", "f[];", CPolynomial_SolveQuadratic, NULL),
|
||||
GB_METHOD("SolveCubic", "f[];", CPolynomial_SolveCubic, NULL),
|
||||
// GB_METHOD("ComplexSolve", "Complex[];", CPolynomial_ComplexSolve, NULL),
|
||||
|
||||
GB_END_DECLARE
|
||||
};
|
||||
|
|
|
@ -27,6 +27,7 @@
|
|||
#define __C_GSL_POLYNOMIAL_H
|
||||
|
||||
#include "gambas.h"
|
||||
#include "gb_common.h"
|
||||
#include <gsl/gsl_poly.h>
|
||||
#include <gsl/gsl_sf_result.h>
|
||||
#include "c_complex.h"
|
||||
|
|
|
@ -41,6 +41,7 @@ GB_DESC *GB_CLASSES[] EXPORT =
|
|||
CGslDesc, /* The Elementary math functions */
|
||||
CComplexDesc,
|
||||
CPolynomialDesc,
|
||||
CComplexPolynomialDesc,
|
||||
/* Other classes go here as completed */
|
||||
NULL // Must have a null entry for the end of the structure
|
||||
};
|
||||
|
|
|
@ -31,6 +31,7 @@
|
|||
#include "c_gsl.h"
|
||||
#include "c_complex.h"
|
||||
#include "c_polynomial.h"
|
||||
#include "c_complexpolynomial.h"
|
||||
|
||||
#ifndef __MAIN_C
|
||||
extern GB_INTERFACE GB;
|
||||
|
|
Loading…
Reference in a new issue