SHARE
TWEET

Untitled

a guest Aug 14th, 2019 74 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. type UnitQuantity = private UnitQuantity of int
  2. // ^ private constructor
  3.  
  4. // define a module with the same name as the type
  5. module UnitQuantity =
  6.     /// Define a "smart constructor" for UnitQuantity
  7.     /// int -> Result<UnitQuantity,string>
  8.     let create qty =
  9.         if qty < 1 then
  10.             // failure
  11.             Error "UnitQuantity can not be negative"
  12.         else if qty > 1000 then
  13.             // failure
  14.             Error "UnitQuantity can not be more than 1000"
  15.         else
  16.             // success -- construct the return value
  17.             Ok (UnitQuantity qty)
  18.      
  19. let ``Check UnitQuantity.create is one`` () =
  20.  
  21.     // ARRANGE
  22.     let expected = 1
  23.  
  24.     // ACT
  25.     //let unitQtyResult = UnitQuantity.create 1
  26.     match UnitQuantity.create 1 with
  27.     | Error msg -> 0
  28.         //printfn "Failure, Message is %s" msg
  29.     | Ok x -> 0
  30.        // let innerValue = UnitQuantity.value actual
  31.  
  32.     // ASSERT
  33.     //Assert.Equal(expected,actual)
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top