1

こんにちは、次のように、指定された文字列が回文であるかどうかを確認するサンプル スクリプトを作成しました。

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
}
}

そして、これは私の.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
    }
}

以下は呼び出しスクリプトです

$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

期待した結果が得られない

4

1 に答える 1

1

この文:

[string] $ReversString

空の文字列になる値式です。その空の文字列はPalindrome1、実行するたびに関数によって出力されます。次のように変更します。

[string] $ReversString = ''
于 2016-08-15T12:33:53.510 に答える