Skip to content

Commit

Permalink
♻️ Update Introduction koans
Browse files Browse the repository at this point in the history
  • Loading branch information
vexx32 committed Jun 19, 2020
1 parent a6e2574 commit f3243e6
Show file tree
Hide file tree
Showing 7 changed files with 301 additions and 193 deletions.
Expand Up @@ -15,6 +15,7 @@ param()
'splatted' into the command by specifying the variable name with an @ symbol: @Variable
#>
Describe 'Splatting' {

BeforeAll {
$PSKoansFolder = Get-PSKoanLocation
}
Expand Down Expand Up @@ -74,8 +75,8 @@ Describe 'Splatting' {
}

Get-ChildItem @Parameters |
Select-Object -First 1 |
Should -BeOfType 'System.IO.FileInfo'
Select-Object -First 1 |
Should -BeOfType 'System.IO.FileInfo'
}

It 'can be built from automatic hashtables' {
Expand Down
Expand Up @@ -96,6 +96,7 @@ Describe 'System.Text.StringBuilder' {
}

Context 'Constructing the Final String Object' {

BeforeAll {
$SB = [System.Text.StringBuilder]::new("Hello!")
$SB.Append("BYE!")
Expand All @@ -115,9 +116,11 @@ Describe 'System.Text.StringBuilder' {
}

Context 'Other StringBuilder Methods' {

BeforeAll {
$StringBuilder = [System.Text.StringBuilder]::new("TEXT")
}

It 'can be cleared' {
$StringBuilder.Clear()
$StringBuilder.Length | Should -Be 0
Expand All @@ -143,6 +146,7 @@ Describe 'System.Text.StringBuilder' {
}

Context 'StringBuilder Properties' {

BeforeAll {
$StringBuilder = [System.Text.StringBuilder]::new()
$StringBuilder.AppendLine('When you look into the void,')
Expand All @@ -154,12 +158,12 @@ Describe 'System.Text.StringBuilder' {
$PropertyName = '____'

$Properties = $StringBuilder |
Get-Member |
Where-Object MemberType -eq 'Property'
Get-Member |
Where-Object MemberType -EQ 'Property'

$ExpectedPropertyCount = $Properties |
Measure-Object |
Select-Object -ExpandProperty Count
Measure-Object |
Select-Object -ExpandProperty Count

$PropertyCount | Should -Be $ExpectedPropertyCount
$PropertyName | Should -BeIn $Properties.Name
Expand Down
Expand Up @@ -98,6 +98,7 @@ Describe 'Arithmetic Operators' {
__ | Should -Be $Array
}
}

Context 'Subtraction' {

It 'works similarly to addition' {
Expand Down Expand Up @@ -148,9 +149,10 @@ Describe 'Arithmetic Operators' {
}

Context 'Modulus' {

# Modulus is a bit of an odd one, but common enough in programming. It performs a
# division, and then returns the integer value of the remainder.
<#
Modulus is a bit of an odd one, but common enough in programming. It performs a
division, and then returns the integer value of the remainder.
#>
It 'is usually used with integers' {
$Remainder = 15 % 7
__ | Should -Be $Remainder
Expand Down
233 changes: 140 additions & 93 deletions PSKoans/Koans/Introduction/AboutBinary.Koans.ps1
Expand Up @@ -43,108 +43,155 @@ param()
one, and 1 + 2 is equal to 3.
#>

Describe "Binary conversion" {
Describe 'Binary Conversions' {

It "Bit conversion" {
# What would 0 be if converted to be boolean?
# Replace __ with either $true or $false
$____ -as [int] | Should -Be 0
Context 'Boolean Conversions' {

# What would 1 be if converted to be boolean?
# Replace __ with either $true or $false
$____ -as [int] | Should -Be 1
}
It 'converts $false to an integer' {
$ExpectedResult = $false -as [int]

It "Binary to integer conversion" {
# Replace __ with the decimal value of 1111
# E.G. __ becomes 1234
$Binary = "1111"
$Value = __
$Value | Should -Be ([Convert]::ToInt32($Binary, 2))

# Replace __ with the decimal value of 1000
$Binary = "1000"
$Value = __
$Value | Should -Be ([Convert]::ToInt32($Binary, 2))

# Replace __ with the decimal value of 0010
$Binary = "0010"
$Value = __
$Value | Should -Be ([Convert]::ToInt32($Binary, 2))

# Replace __ with the decimal value of 1001
$Binary = "1001"
$Value = __
$Value | Should -Be ([Convert]::ToInt32($Binary, 2))

# Replace __ with the decimal value of 11111111
$Binary = "11111111"
$Value = __
$Value | Should -Be ([Convert]::ToInt32($Binary, 2))

# Replace __ with the decimal value of 10101010
$Binary = "10101010"
$Value = __
$Value | Should -Be ([Convert]::ToInt32($Binary, 2))

# Replace __ with the decimal value of 11001100
$Binary = "11001100"
$Value = __
$Value | Should -Be ([Convert]::ToInt32($Binary, 2))

# Replace __ with the decimal value of 11110001
$Binary = "11110001"
$Value = __
$Value | Should -Be ([Convert]::ToInt32($Binary, 2))
# What would $false be if converted to a number?
__ | Should -Be $ExpectedResult
}

It 'converts $true to an integer' {
$ExpectedResult = $true -as [int]

# What would $true be if converted to a number?
__ | Should -Be $ExpectedResult
}
}

It "Integer to Binary conversion" {
Context "Binary to Integer Conversion" {
<#
Convert the following integers into their binary representation
Replace the blanks below with the decimal value of the binary
numbers in each case. For example, the binary sequence "10" is
represented by the number 2 in the standard decimal system.
#>
It 'converts 1111 to an integer' {
$ExpectedValue = [Convert]::ToInt32($Binary, 2)

# Replace the __ with the decimal value of 1111
$Binary = "1111"
__ | Should -Be $ExpectedValue
}

It 'converts 1000 to an integer' {
$ExpectedValue = [Convert]::ToInt32($Binary, 2)

# Replace __ with the decimal value of 1000
$Binary = "1000"
__ | Should -Be $ExpectedValue
}

It 'converts 0010 to an integer' {
$ExpectedValue = [Convert]::ToInt32($Binary, 2)

# Replace __ with the decimal value of 0010
$Binary = "0010"
__ | Should -Be $ExpectedValue
}

It 'converts 1001 to an integer' {
$ExpectedValue = [Convert]::ToInt32($Binary, 2)

# Replace __ with the decimal value of 1001
$Binary = "1001"
__ | Should -Be $ExpectedValue
}

It 'converts 11111111 to an integer' {
$ExpectedValue = [Convert]::ToInt32($Binary, 2)

# Replace __ with the decimal value of 11111111
$Binary = "11111111"
__ | Should -Be $ExpectedValue
}

# Replace __ with the binary value of 7
# E.G. "__" becomes "0100"
$Binary = "____"
$Value = 7
$Value | Should -Be ([Convert]::ToInt32($Binary, 2))

# Replace __ with the binary value of 12
$Binary = "____"
$Value = 12
$Value | Should -Be ([Convert]::ToInt32($Binary, 2))

# Replace __ with the binary value of 2
$Binary = "____"
$Value = 2
$Value | Should -Be ([Convert]::ToInt32($Binary, 2))

# Replace __ with the binary value of 14
$Binary = "____"
$Value = 14
$Value | Should -Be ([Convert]::ToInt32($Binary, 2))

# Replace __ with the binary value of 103
# E.G. "__" becomes "01001110"
$Binary = "____"
$Value = 103
$Value | Should -Be ([Convert]::ToInt32($Binary, 2))

# Replace __ with the binary value of 250
$Binary = "____"
$Value = 250
$Value | Should -Be ([Convert]::ToInt32($Binary, 2))

# Replace __ with the binary value of 74
$Binary = "____"
$Value = 74
$Value | Should -Be ([Convert]::ToInt32($Binary, 2))

# Replace __ with the binary value of 32
$Binary = "____"
$Value = 32
$Value | Should -Be ([Convert]::ToInt32($Binary, 2))
It 'converts 10101010 to an integer' {
$ExpectedValue = [Convert]::ToInt32($Binary, 2)

# Replace __ with the decimal value of 10101010
$Binary = "10101010"
__ | Should -Be $ExpectedValue
}

It 'converts 11001100 to an integer' {
$ExpectedValue = [Convert]::ToInt32($Binary, 2)

# Replace __ with the decimal value of 11001100
$Binary = "11001100"
__ | Should -Be $ExpectedValue
}

It 'converts 11110001 to an integer' {
$ExpectedValue = [Convert]::ToInt32($Binary, 2)

# Replace __ with the decimal value of 11110001
$Binary = "11110001"
__ | Should -Be $ExpectedValue
}
}

It "Integer to Binary Conversion" {
<#
Convert the following integers into their binary representation.
For example, 2 is represented in binary with the digits "10".
#>
It 'converts the integer 7 to binary' {
# Replace ____ with the binary value of 7
$Value = 7
$Binary = [Convert]::ToString($Value, 2)
'____' | Should -Be $Binary
}

It 'converts the integer 12 to binary' {
# Replace __ with the binary value of 12
$Value = 12
$Binary = [Convert]::ToString($Value, 2)
'____' | Should -Be ([Convert]::ToInt32($Binary, 2))
}

It 'converts the integer 2 to binary' {
# Replace __ with the binary value of 2
$Value = 2
$Binary = [Convert]::ToString($Value, 2)
'____' | Should -Be ([Convert]::ToInt32($Binary, 2))
}

It 'converts the integer 14 to binary' {
# Replace __ with the binary value of 14
$Value = 14
$Binary = [Convert]::ToString($Value, 2)
'____' | Should -Be ([Convert]::ToInt32($Binary, 2))
}

It 'converts the integer 103 to binary' {
# Replace __ with the binary value of 103
$Value = 103
$Binary = [Convert]::ToString($Value, 2)
'____' | Should -Be ([Convert]::ToInt32($Binary, 2))
}

It 'converts the integer 250 to binary' {
# Replace __ with the binary value of 250
$Value = 250
$Binary = [Convert]::ToString($Value, 2)
'____' | Should -Be ([Convert]::ToInt32($Binary, 2))
}

It 'converts the integer 74 to binary' {
# Replace __ with the binary value of 74
$Value = 74
$Binary = [Convert]::ToString($Value, 2)
'____' | Should -Be ([Convert]::ToInt32($Binary, 2))
}

It 'converts the integer 32 to binary' {
# Replace __ with the binary value of 32
$Value = 32
$Binary = [Convert]::ToString($Value, 2)
'____' | Should -Be ([Convert]::ToInt32($Binary, 2))
}
}
}
28 changes: 20 additions & 8 deletions PSKoans/Koans/Introduction/AboutBooleans.Koans.ps1
Expand Up @@ -8,7 +8,7 @@ param()
allow us to represent a logical, binary, state. Effectively, they represent
the state of a single bit of data. For example:
| "Can I stop this service?"
"Can I stop this service?"
The answer is yes or no, True or False.
Expand All @@ -27,30 +27,42 @@ param()
#>

Describe "Booleans" {
<#
Fill in the blanks below with either $true or $false, indicating the
result you expect from the noted expressions.
# Using only booleans, either $true or $false, fill in the blanks below.
We'll cover comparison operators in more detail later on, but here's a
summary of the operators used here:
It '( 1 -gt 2 ) is either true or false' {
-gt => "is greater than"
-eq => "is equal to"
-lt => "is less than"
As an example, the expression 7 -gt 5 asserts "7 is greater than 5".
This is a true statement, so the final value of the expression is $true.
#>

It 'evaluates ( 1 -gt 2 ) as a boolean expression' {
$____ | Should -Be ( 1 -gt 2 ) -Because '1 is not greater than 2'
}

It '( 1 -lt 2 ) is either true or false' {
It 'evaluates ( 1 -lt 2 ) as a boolean expression' {
$____ | Should -Be ( 1 -lt 2 ) -Because '1 is less than 2'
}

It '( 10 -lt 20 ) is either true or false' {
It 'evaluates ( 10 -lt 20 ) as a boolean expression' {
$____ | Should -Be ( 10 -lt 20 ) -Because '10 is less than 20'
}

It '( 10 -gt 20 ) is either true or false' {
It 'evaluates ( 10 -gt 20 ) as a boolean expression' {
$____ | Should -Be ( 10 -gt 20 ) -Because 'The lesser is not greater'
}

It '( 3 -eq 3 ) is either true or false' {
It 'evaluates ( 3 -eq 3 ) as a boolean expression' {
$____ | Should -Be ( 3 -eq 3 ) -Because 'A mirror reflects true'
}

It '( 100 -lt 1 ) is either true or false' {
It 'evaluates ( 100 -lt 1 ) as a boolean expression' {
$____ | Should -Be ( 100 -lt 1 ) -Because '100 is not less than 1'
}
}

0 comments on commit f3243e6

Please sign in to comment.