1

Hi all I have a written a sample script to find whether the given string is Palindrome or not as follows

function Palindrome1([string] $param)
{
  [string] $ReversString
  $StringLength = @()

  $StringLength = $param.Length

  while ( $StringLength -ge 0 )
 {
    $ReversString = $ReversString + $param[$StringLength]
    $StringLength--
 }    

 if($ReversString -eq $param)
 {
    return $true
 }
else
{
    return $false
}
}

And this is my .tests.ps1

$here = Split-Path -Parent $MyInvocation.MyCommand.Path
$sut = (Split-Path -Leaf $MyInvocation.MyCommand.Path) -replace '\.Tests\.', '.'
. "$here\$sut"

Describe "Palindrome1" {
    It "does something useful" {
        Palindrome1 "radar" | Should Be $true
    }
}

Below is Invoke script

$modulePath = "D:\Pester-master\Pester.psm1"
$SourceDir = "E:\Pester"
Import-Module $modulePath -ErrorAction Inquire
$outputFile = Join-Path $SourceDir "TEST-pester.xml"

$result = Invoke-Pester -Path $SourceDir -CodeCoverage "$SourceDir\*.ps1" -PassThru -OutputFile $outputFile

$result

I am not getting the expected result can some one tell me where I am doing wrong

Developer
  • 8,390
  • 41
  • 129
  • 238

1 Answers1

1

This statement:

[string] $ReversString

is a value expression resulting in an empty string. That empty string is output by the Palindrome1 function every time your run it. Change it to:

[string] $ReversString = ''
Mathias R. Jessen
  • 157,619
  • 12
  • 148
  • 206
  • Hi one more help when I make the input parameter as Mandatory it is asking me multiple time to enter the string `function Palindrome1 { [CmdletBinding()] param ( [Parameter(Mandatory)] [string] $param )` – Developer Aug 15 '16 at 12:44
  • Not able to reproduce, it only prompts once if argument is not present. Please [ask a new question](http://stackoverflow.com/questions/ask) if you need help with parameters – Mathias R. Jessen Aug 15 '16 at 12:46
  • find here http://stackoverflow.com/questions/38955495/pester-powershell-testing-prompting-to-enter-the-input-multiple-times – Developer Aug 15 '16 at 12:54