Created
September 26, 2023 07:08
-
-
Save ursenzler/def9bd67e7ee00fd6183af14d850369e to your computer and use it in GitHub Desktop.
A function in F# that can create dummy strings and integers (can be extended).
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
open FsToolkit.ErrorHandling | |
open Xunit | |
open Swensen.Unquote | |
let factoryFunction<'a> () : 'a = | |
let value = | |
if typeof<'a> = typeof<string> then "String" :> obj | |
elif typeof<'a> = typeof<int> then 1 :> obj | |
else failwith "Unsupported type" | |
downcast value | |
[<Fact>] | |
let ``factory can create dummy string value`` () = | |
let result = factoryFunction () | |
test <@ result = "String" @> | |
[<Fact>] | |
let ``factory can create dummy int value`` () = | |
let result = factoryFunction () | |
test <@ result = 1 @> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment