learning F#, it seems pretty cool, favourite functional language so far.
Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.

AccumulateTests.fs 1.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. // This file was created manually and its version is 2.0.0
  2. module AccumulateTest
  3. open System
  4. open Xunit
  5. open FsUnit.Xunit
  6. open Accumulate
  7. let reverse (str:string) = new string(str.ToCharArray() |> Array.rev)
  8. [<Fact>]
  9. let ``Empty accumulation produces empty accumulation`` () =
  10. accumulate (fun x -> x + 1) List.empty |> should be Empty
  11. [<Fact>]
  12. let ``Identity accumulation returns unmodified list`` () =
  13. accumulate id [1; 2; 3] |> should equal [1; 2; 3]
  14. [<Fact>]
  15. let ``Accumulate squares`` () =
  16. accumulate (fun x -> x * x) [1; 2; 3] |> should equal [1; 4; 9]
  17. [<Fact>]
  18. let ``Accumulate upcases`` () =
  19. accumulate (fun (x:string) -> x.ToUpper()) ["hello"; "world"]
  20. |> should equal ["HELLO"; "WORLD"]
  21. [<Fact>]
  22. let ``Accumulate reversed strings`` () =
  23. accumulate reverse (List.ofArray ("the quick brown fox etc".Split(' ')))
  24. |> should equal (List.ofArray("eht kciuq nworb xof cte".Split(' ')))
  25. [<Fact>]
  26. let ``Accumulate within accumulate`` () =
  27. accumulate (fun (x:string) -> String.concat " " (accumulate (fun y -> x + y) ["1"; "2"; "3"])) ["a"; "b"; "c"]
  28. |> should equal ["a1 a2 a3"; "b1 b2 b3"; "c1 c2 c3"]
  29. [<Fact>]
  30. let ``Accumulate large data set without stack overflow`` () =
  31. accumulate id [1..100000]
  32. |> should equal [1..100000]