Book Image

Testing with F#

By : Mikael Lundin
Book Image

Testing with F#

By: Mikael Lundin

Overview of this book

Table of Contents (17 chapters)
Testing with F#
Credits
About the Author
About the Reviewers
www.PacktPub.com
Preface
Index

F# Interactive


One of the coolest things about F# is that its development environment comes with an interactive test environment: F# Interactive. You can access this feature in Visual Studio's top menu by navigating to View | Other Windows | F# Interactive or pressing the default shortcut Ctrl + Alt + F, as shown in the following screenshot:

This is valuable when we need to do the following:

  • Quickly validate computations

  • Spike new concepts

  • Validate the implemented solution

When working with F#, you can use the interactive window to quickly validate part of a solution before implementing it. It provides a kind of a workbench when developing a test environment.

Let's say you need to implement a function that checks whether the current year is a leap year. You can enter the following code into F# Interactive in order to understand how the .NET framework manages to create a date that is not valid:

> new System.DateTime(System.DateTime.Today.Year, 2, 29);;
System.ArgumentOutOfRangeException: Year...