We have a really fun puzzle for this week. I've been taking a Coursera class on mapping geospatial data. One of the Java libraries that we're using has a neat map() method that maps a value from one range to another.
For this week's puzzle, we'll write ConvertTo-Range, a map() function for PowerShell. But, instead of providing instructions, I've written a file of Pester tests, ConvertTo-Range.Tests.ps1, and a ConvertTo-Range.ps1 with comment-based help.
If you run the test file now, all the tests fail. Your mission is to write a ConvertTo-Range function that makes all of the tests pass. You get to dust off your math skills and try your hand at test-driven development with Pester.
Files:
- ConvertTo-Range.ps1 with comment-based help (hint*)
- ConvertTo-Ranges.Tests.ps1
Resources:
- Pester module in PowerShell Gallery
- Pester project on GitHub
- Getting Started with Pester (J. Jares)
- Using Pester for Test-Driven Development in PowerShell (M. Robbins)
- How to run a Pester test (J. Blender)- Invoke-Pester: Running selected tests (J. Blender)
- How to pass parameters to a Pester test script (J. Blender)
- Testing Pester Code Coverage (J. Blender)
- Test-Driven Development by Example (K. Beck)
- VIDEO: Real-World Test-Driven Development with Pester
Thanks to Andy Cahn at Chrysalis School for help with the math!
Like this PowerShell puzzle?
This repository includes all of the SAPIEN Technologies Friday PowerShell puzzles.
To read the solutions to our Friday PowerShell Puzzles, see Friday Puzzle Solutions.