Skip to content

Instantly share code, notes, and snippets.

@dfinke
Last active October 8, 2015 14:10
Show Gist options
  • Select an option

  • Save dfinke/3ac04892bee85c8f0b57 to your computer and use it in GitHub Desktop.

Select an option

Save dfinke/3ac04892bee85c8f0b57 to your computer and use it in GitHub Desktop.
##
## Thanks to Jum Truher on the PowerShell team https://jtruher3.wordpress.com/
##
$scriptRoot = Split-Path $MyInvocation.MyCommand.Path
. "$scriptRoot\RubyArraylistConstructs.ps1"
Describe "Ruby array constructs are available on an ArrayList" {
BeforeEach {
[system.collections.arraylist]$al = 2,4,8
}
It "Can push a new value in the right place" {
$al.Push(16)
$al[-1] | Should be 16
}
It "Can push new values to the end of the list" {
$al.Push(32,64)
$al[-1] | should be 64
$al[-2] | Should be 32
$al[-3] | should be 8
}
It "Can push a new value to the beginning of the list" {
$al.Unshift(1)
$al[0] | should be 1
$al.Count | should be 4
}
It "Can push new values to the beginning of the list" {
$al.Unshift(0,1)
$al.Count | should be 5
$al[0] | should be 0
$al[1] | should be 1
$al[2] | should be 2
}
It "Shift returns the right value and adjusts the array" {
$v = $al.Shift()
$v | Should be 2
$al.count | should be 2
$al[0] | should be 4
}
It "Shift more than one item" {
$v = $al.Shift(2)
$v.count | Should be 2
$v[0] | Should be 2
$v[1] | Should be 4
$al.count | should be 1
$al[0] | should be 8
}
It "Pop returns the right value and adjusts the array" {
$v = $al.Pop()
$v | Should be 8
$al.count | should be 2
$al[0] | should be 2
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment