Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions Graphical.psm1
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Get-ChildItem "$PSScriptRoot\src\" -Filter *.ps1 | ForEach-Object {
Get-ChildItem -Path "$PSScriptRoot\src\" -Filter *.ps1 | ForEach-Object -Process {
. $_.FullName
}

# Exporting the members and their aliases
Export-ModuleMember Show-Graph -Alias Graph
Export-ModuleMember -Function Show-Graph -Alias Graph
2 changes: 1 addition & 1 deletion src/Get-BarPlot.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ Function Get-BarPlot {

# Create a 2D Array to save datapoints in a 2D format
$NumOfRows = $difference/($Step) + 1
$Array = New-Object 'object[,]' $NumOfRows,$NumOfDatapoints
$Array = New-Object -TypeName 'object[,]' -ArgumentList $NumOfRows,$NumOfDatapoints

For($i = 0;$i -lt $Datapoints.count;$i++){
# Fit datapoint in a row, where, a row's data range = Total Datapoints / Step
Expand Down
2 changes: 1 addition & 1 deletion src/Get-LinePlot.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ Function Get-LinePlot {

# Create a 2D Array to save datapoints in a 2D format
$NumOfRows = $difference/($Step) + 1
$Array = New-Object 'object[,]' $NumOfRows,$NumOfDatapoints
$Array = New-Object -TypeName 'object[,]' -ArgumentList $NumOfRows,$NumOfDatapoints

$Marker = [char] 9608
$Line = [char] 9616
Expand Down
2 changes: 1 addition & 1 deletion src/Get-ScatterPlot.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ Function Get-ScatterPlot {
$Difference = $EndofRange - $StartOfRange
$NumOfRows = $difference/($Step) + 1
$NumOfDatapoints = $Datapoints.Count
$Array = New-Object 'object[,]' ($NumOfRows),$NumOfDatapoints
$Array = New-Object -TypeName 'object[,]' -ArgumentList ($NumOfRows),$NumOfDatapoints


For($i = 0;$i -lt $Datapoints.count;$i++){
Expand Down
10 changes: 5 additions & 5 deletions src/Show-Graph.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -109,8 +109,8 @@ Function Show-Graph {
$YAxisTitleStartIdx, $YAxisTitleEndIdx = CenterAlignStringReturnIndices -String $YAxisTitle -Length $NumOfRows

If($YAxisTitle.Length -gt $NumOfLabelsOnYAxis){
Write-Warning "No. Alphabets in YAxisTitle [$($YAxisTitle.Length)] can't be greator than no. of Labels on Y-Axis [$NumOfLabelsOnYAxis]"
Write-Warning "YAxisTitle will be cropped"
Write-Warning -Message "No. Alphabets in YAxisTitle [$($YAxisTitle.Length)] can't be greator than no. of Labels on Y-Axis [$NumOfLabelsOnYAxis]"
Write-Warning -Message "YAxisTitle will be cropped"
}

# Create a 2D Array to save datapoints in a 2D format
Expand Down Expand Up @@ -238,9 +238,9 @@ Function Show-Graph {
if(![String]::IsNullOrWhiteSpace($XAxisTitle)){
# Position the x-axis label at the center of the axis
$XAxisTitle = " "*$LengthOfMaxYAxisLabel + (CenterAlignString $XAxisTitle $XAxis.Length)
Write-Host $VerticalEdge -NoNewline
Write-Host $XAxisTitle -ForegroundColor DarkYellow -NoNewline # Prints XAxisTitle
Write-Host $(" "*$(($LengthOfMaxYAxisLabel + $XAxis.length) - $XAxisTitle.Length - 2)) $VerticalEdge
Write-Host -Object $VerticalEdge -NoNewline
Write-Host -Object $XAxisTitle -ForegroundColor DarkYellow -NoNewline # Prints XAxisTitle
Write-Host -Object $(" "*$(($LengthOfMaxYAxisLabel + $XAxis.length) - $XAxisTitle.Length - 2)) $VerticalEdge
}

# bottom boundary
Expand Down
10 changes: 5 additions & 5 deletions src/UtilityFunctions.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,10 @@ Function CenterAlignStringReturnIndices ($String, $Length) {

Function Write-Graph($YAxisLabelAlphabet, $YAxisLabel, $Row, $RowColor, $LabelColor)
{
Write-Host $([char]9474) -NoNewline
Write-Host $YAxisLabelAlphabet -ForegroundColor $LabelColor -NoNewline
Write-Host "$($YAxisLabel.tostring().PadLeft($LengthOfMaxYAxisLabel+2) + [Char]9508)" -NoNewline
Write-Host -Object $([char]9474) -NoNewline
Write-Host -Object $YAxisLabelAlphabet -ForegroundColor $LabelColor -NoNewline
Write-Host -Object "$($YAxisLabel.tostring().PadLeft($LengthOfMaxYAxisLabel+2) + [Char]9508)" -NoNewline
##Write-Host "$YAxisLabel|" -NoNewline
Write-Host $Row -ForegroundColor $RowColor -NoNewline
Write-Host " " $([char]9474)
Write-Host -Object $Row -ForegroundColor $RowColor -NoNewline
Write-Host -Object " " $([char]9474)
}
116 changes: 116 additions & 0 deletions tests/module.unit.tests.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,116 @@
<#
.Synopsis
Pester test to verify the content of the manifest and the documentation of each functions.
.Description
Pester test to verify the content of the manifest and the documentation of each functions.
#>
[CmdletBinding()]
PARAM(
[System.String]$modulePath=(split-path -parent -Path $PSScriptRoot),
[System.String]$moduleName='Graphical',
[System.String]$srcPath=(Join-Path -Path (split-path -parent -Path $PSScriptRoot) -ChildPath 'src')
)
begin{
# Find the Manifest file
$ManifestFile = "$modulePath\$ModuleName.psd1"

# Unload any module with same name
Get-Module -Name $ModuleName -All | Remove-Module -Force -ErrorAction Ignore

# Import Module
$ModuleInformation = Import-Module -Name $ManifestFile -Force -ErrorAction Stop -PassThru

# Get the functions present in the Manifest
$ExportedFunctions = $ModuleInformation.ExportedFunctions.Values.name

# Public functions
$publicFiles = @(Get-ChildItem -Path $srcPath\public\*.ps1 -ErrorAction SilentlyContinue)
}
end{
Remove-Module -Name $moduleName -ErrorAction SilentlyContinue}
process{
Describe "$ModuleName Module - Testing Manifest File (.psd1)"{

Context 'Module Version'{'Loaded Version vs Get-Command return for the module'}
Context 'Manifest'{
It 'Should contains RootModule'{$ModuleInformation.RootModule|Should not BeNullOrEmpty}
It 'Should contains Author'{$ModuleInformation.Author|Should not BeNullOrEmpty}
It 'Should contains Company Name'{$ModuleInformation.CompanyName|Should not BeNullOrEmpty}
It 'Should contains Description'{$ModuleInformation.Description|Should not BeNullOrEmpty}
It 'Should contains Copyright'{$ModuleInformation.Copyright|Should not BeNullOrEmpty}
It 'Should contains License'{$ModuleInformation.LicenseURI|Should not BeNullOrEmpty}
It 'Should contains a Project Link'{$ModuleInformation.ProjectURI|Should not BeNullOrEmpty}
It 'Should contains a Tags (For the PSGallery)'{$ModuleInformation.Tags.count|Should not BeNullOrEmpty}

It "Should have equal number of Function Exported and the Public PS1 files found ($($ExportedFunctions.count) and $($publicFiles.count))"{
$ExportedFunctions.count -eq $publicFiles.count |Should -Be $true}
It "Compare the missing function"{
if (-not($ExportedFunctions.count -eq $publicFiles.count)){
$Compare = Compare-Object -ReferenceObject $ExportedFunctions -DifferenceObject $publicFiles.basename
$Compare.inputobject -join ',' |
Should BeNullOrEmpty
}
}
}
}


# Testing the Module
Describe "$ModuleName Module - HELP" -Tags "Module" {
#$Commands = (get-command -Module ADSIPS).Name

FOREACH ($c in $ExportedFunctions)
{
$Help = Get-Help -Name $c -Full
$Notes = ($Help.alertSet.alert.text -split '\n')
$FunctionContent = Get-Content function:$c
$AST = [System.Management.Automation.Language.Parser]::ParseInput($FunctionContent, [ref]$null, [ref]$null)

Context "$c - Help"{

It "Synopsis"{$help.Synopsis| Should not BeNullOrEmpty}
It "Description"{$help.Description| Should not BeNullOrEmpty}
It "Notes - Github Project" {$Notes -match "$GithubRepository$ModuleName" | Should Be $true}

# Get the parameters declared in the Comment Based Help
# minus the RiskMitigationParameters
$RiskMitigationParameters = 'Whatif', 'Confirm'
$HelpParameters = $help.parameters.parameter | Where-Object name -NotIn $RiskMitigationParameters

# Parameter Count VS AST Parameter
$ASTParameters = $ast.ParamBlock.Parameters.Name.variablepath.userpath
It "Parameter - Compare Count Help/AST" {
$HelpParameters.name.count -eq $ASTParameters.count | Should Be $true}

# Parameters Description
$HelpParameters| Foreach-Object -Process {
It "Parameter $($_.Name) - Should contains description"{
$_.description | Should not BeNullOrEmpty
}
}

# Parameters separated by a space
$ParamText=$ast.ParamBlock.extent.text -split '\r\n' # split on return
$ParamText=$ParamText.trim()
$ParamTextSeparator=$ParamText |select-string ',$' #line that finish by a ','

if($ParamTextSeparator)
{
Foreach ($ParamLine in $ParamTextSeparator.linenumber)
{
it "Parameter - Separated by space (Line $ParamLine)"{
#$ParamText[$ParamLine] -match '\s+' | Should Be $true
$ParamText[$ParamLine] -match '^$|\s+' | Should Be $true
}
}
}

# Examples
it "Example - Count should be greater than 0"{
$Help.examples.example.code.count | Should BeGreaterthan 0
$Help.examples | Should not BeNullOrEmpty
}
}
}
}
}