Author Topic: Test function with Palindrome entry(Rosetta Code)  (Read 3389 times)

0 Members and 1 Guest are viewing this topic.

Offline TempodiBasic

  • Forum Resident
  • Posts: 1792
    • View Profile
Test function with Palindrome entry(Rosetta Code)
« on: April 26, 2021, 04:53:44 pm »
Hi
here my solution to this task http://rosettacode.org/wiki/Test_a_function
Quote
Using a well-known testing-specific library/module/suite for your language, write some tests for your language's entry in Palindrome.

Code: QB64: [Select]
  1. 'A palindrome is a phrase which reads the same backward and forward.
  2.  
  3. 'Task
  4. ' Using a well-known testing-specific library/module/suite for your
  5. ' language, write some tests for your language's entry in Palindrome.
  6. Dim palindr As String
  7.  
  8. palindr = "asdfghjkl78987lkjhgfdsa"
  9. If IsPalindrome(palindr) = -1 Then Print palindr; "  is palindrome" Else Print palindr; " NOT  is palindrome"
  10.  
  11. palindr = "roop123321poor5"
  12. If IsPalindrome(palindr) = -1 Then Print palindr; "  is palindrome" Else Print palindr; " NOT  is palindrome"
  13.  
  14. palindr = "98765abba56789"
  15. If IsPalindrome(palindr) = -1 Then Print palindr; "  is palindrome" Else Print palindr; " NOT  is palindrome"
  16.  
  17. Function IsPalindrome (Palindrome As String)
  18.     IsPalindrome = 0
  19.     Dim a As Integer
  20.     For a = 1 To Len(Palindrome) / 2
  21.         If Asc(Palindrome, a) <> Asc(Palindrome, Len(Palindrome) - a + 1) Then Exit Function
  22.     Next
  23.     IsPalindrome = -1
Thanks to test and for feedbacks
« Last Edit: April 26, 2021, 05:45:40 pm by TempodiBasic »
Programming isn't difficult, only it's  consuming time and coffee