Test a function: Difference between revisions

Test a function en FreeBASIC
(Test a function en FreeBASIC)
Line 611:
=={{header|Fortran}}==
There is no standard or popular facility. Compilers usually do not even check that a function or subroutine is invoked with the correct number of parameters let alone the correct types. Testing that a function returns expected values is entirely a matter for the programmer and whatever tools that may be devised, either directly for the function in question or adapted from some other project where this had been done.
 
 
=={{header|FreeBASIC}}==
{{trans|VBA}}
<lang freebasic>
Sub StrReverse(Byref text As String)
Dim As Integer x, lt = Len(text)
For x = 0 To lt Shr 1 - 1
Swap text[x], text[lt - x - 1]
Next x
End Sub
 
Sub Replace(Byref T As String, Byref I As String, Byref S As String, Byval A As Integer = 1)
Var p = Instr(A, T, I), li = Len(I), ls = Len(S) : If li = ls Then li = 0
Do While p
If li Then T = Left(T, p - 1) & S & Mid(T, p + li) Else Mid(T, p) = S
p = Instr(p + ls, T, I)
Loop
End Sub
 
Function IsPalindrome(Byval txt As String) As Boolean
Dim As String tempTxt = Lcase(txt), copyTxt = Lcase(txt)
Replace(tempTxt, " ", "")
Replace(copyTxt, " ", "")
StrReverse(tempTxt)
If tempTxt = copyTxt Then
Color 10
Return true
Else
Color 12
Return false
End If
End Function
 
'--- Programa Principal ---
Dim As String a(10) => {"abba", "mom", "dennis sinned", "Un roc lamina l animal cornu", _
"palindrome", "ba _ ab", "racecars", "racecar", "wombat", "in girum imus nocte et consumimur igni"}
 
Print !"¨Pal¡ndromos?\n"
For i As Byte = 0 To Ubound(a)-1
Print a(i) & " -> ";
Print IsPalindrome((a(i)))
Color 7
Next i
Sleep
</lang>
{{out}}
<pre>
¿Palíndromos?
 
abba -> true
mom -> true
dennis sinned -> true
Un roc lamina l animal cornu -> true
palindrome -> false
ba _ ab -> true
racecars -> false
racecar -> true
wombat -> false
in girum imus nocte et consumimur igni -> true
</pre>
 
 
=={{header|Go}}==
2,127

edits