Skip to content

Commit 2c9699f

Browse files
committed
+ tests
1 parent bd7074a commit 2c9699f

File tree

3 files changed

+118
-57
lines changed

3 files changed

+118
-57
lines changed

tests/FSharpPlus.Tests/Applicatives.fs

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,3 +33,59 @@ module Applicatives =
3333

3434
let arr3 = (+) <!> Compose (async { return [|1;2;3|] } ) <.> Compose (async { return [|10;20;30|] })
3535
CollectionAssert.AreEqual ([|11; 22; 33|], arr3 |> Compose.run |> Async.RunSynchronously)
36+
37+
38+
[<Test>]
39+
let zip3Test () =
40+
41+
SideEffects.reset ()
42+
let _a = zip3 (seq [1;2;3]) (seq [1. .. 3. ]) (seq ['a';'b';'c'])
43+
Assert.AreEqual (list<string>.Empty, SideEffects.get ())
44+
45+
let _b = zip3 (dict [1,'1' ; 2,'2' ; 4,'4']) (dict [1,'1' ; 2,'2' ; 3,'3']) (dict [1,'a' ; 2,'b' ; 3,'c'])
46+
let _c = zip3 [ 1;2;3 ] [ 1. .. 3. ] ['a';'b';'c']
47+
let _d = zip3 [|1;2;3|] [|1. .. 3.|] [|'a';'b';'c'|]
48+
let _e = zip3 (async {return 1}) (async {return '2'}) (async {return 3.})
49+
let _f = zip3 (Task.FromResult 1) (Task.FromResult '2') (Task.FromResult 3.)
50+
let _g = zip3 (Some 1) (Some '2') (Some 3.)
51+
let _h = zip3 (Ok 1) (Ok '2') (Ok 3.)
52+
53+
let _fa a = zip3 a (seq [1. .. 3. ]) (seq ['a';'b';'c'])
54+
let _fb a = zip3 a [ 1. .. 3. ] ['a';'b';'c']
55+
let _fc a = zip3 a [|1. .. 3.|] [|'a';'b';'c'|]
56+
let _fd a = zip3 a (async {return '2'}) (async {return 3.})
57+
let _fe a = zip3 a (Task.FromResult '2') (Task.FromResult 3.)
58+
59+
let _ga b = zip3 (seq [1;2;3]) b (seq ['a';'b';'c'])
60+
let _gb b = zip3 [ 1;2;3 ] b ['a';'b';'c']
61+
let _gc b = zip3 [|1;2;3|] b [|'a';'b';'c'|]
62+
let _gd b = zip3 (async {return 1}) b (async {return 3.})
63+
let _ge b = zip3 (Task.FromResult 1) b (Task.FromResult 3.)
64+
65+
let _ha c = zip3 (seq [1;2;3]) (seq [1. .. 3. ]) c
66+
let _hb c = zip3 [ 1;2;3 ] [ 1. .. 3. ] c
67+
let _hc c = zip3 [|1;2;3|] [|1. .. 3.|] c
68+
let _hd c = zip3 (async {return 1}) (async {return '2'}) c
69+
let _he c = zip3 (Task.FromResult 1) (Task.FromResult '2') c
70+
71+
let _ia : _ -> _ -> _ -> _ seq = zip3
72+
let _ib : _ -> _ -> _ -> _ list = zip3
73+
let _ic : _ -> _ -> _ -> _ [] = zip3
74+
let _id : _ -> _ -> _ -> Async<_> = zip3
75+
let _ie : _ -> _ -> _ -> Task<_> = zip3
76+
77+
()
78+
79+
[<Test>]
80+
let genericZip3Shortest () =
81+
let a = zip3 [|1; 2; 3|] [|"a"; "b"|] [|10.; 20.; 30.|]
82+
CollectionAssert.AreEqual ([|1,"a",10.; 2,"b",20.|], a)
83+
84+
let l = zip3 [1; 2] ["a"; "b"; "c"] [10.; 20.; 30.]
85+
CollectionAssert.AreEqual ([1,"a",10.; 2,"b",20.], l)
86+
87+
let e = zip3 (ResizeArray [1; 2]) (ResizeArray ["a"; "b"; "c"]) (ResizeArray [10.; 20.])
88+
CollectionAssert.AreEqual (ResizeArray [1,"a",10.; 2,"b",20.], e)
89+
90+
let nel = zip3 (NonEmptyList.ofList [1; 2]) (NonEmptyList.ofList ["a"; "b"; "c"]) (NonEmptyList.ofList [10.; 20.; 30.])
91+
CollectionAssert.AreEqual (NonEmptyList.ofList [1,"a",10.; 2,"b",20.], nel)

tests/FSharpPlus.Tests/General.fs

Lines changed: 0 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -67,62 +67,6 @@ type WrappedListC<'s> = WrappedListC of 's list with
6767
static member Zero = WrappedListC List.empty
6868
static member Sum (lst: seq<WrappedListC<_>>) = Seq.head lst
6969

70-
type WrappedListD<'s> = WrappedListD of 's list with
71-
interface Collections.Generic.IEnumerable<'s> with member x.GetEnumerator () = (let (WrappedListD x) = x in x :> _ seq).GetEnumerator ()
72-
interface Collections.IEnumerable with member x.GetEnumerator () = (let (WrappedListD x) = x in x :> _ seq).GetEnumerator () :> Collections.IEnumerator
73-
static member Return (x) = SideEffects.add "Using WrappedListD's Return"; WrappedListD [x]
74-
static member (>>=) ((WrappedListD x):WrappedListD<'T>, f) = SideEffects.add "Using WrappedListD's Bind"; WrappedListD (List.collect (f >> (fun (WrappedListD x) -> x)) x)
75-
static member inline FoldMap (WrappedListD x, f) =
76-
SideEffects.add "Using optimized foldMap"
77-
Seq.fold (fun x y -> x ++ (f y)) zero x
78-
static member Zip (WrappedListD x, WrappedListD y) = SideEffects.add "Using WrappedListD's zip"; WrappedListD (List.zip x y)
79-
static member Exists (x, f) =
80-
SideEffects.add "Using WrappedListD's Exists"
81-
let (WrappedListD lst) = x
82-
List.exists f lst
83-
static member Pick (x, f) =
84-
SideEffects.add "Using WrappedListD's Pick"
85-
let (WrappedListD lst) = x
86-
List.pick f lst
87-
static member Min x =
88-
SideEffects.add "Using WrappedListD's Min"
89-
let (WrappedListD lst) = x
90-
List.min lst
91-
static member MaxBy (x, f) =
92-
SideEffects.add "Using WrappedListD's MaxBy"
93-
let (WrappedListD lst) = x
94-
List.maxBy f lst
95-
static member MapIndexed (WrappedListD x, f) =
96-
SideEffects.add "Using WrappedListD's MapIndexed"
97-
WrappedListD (List.mapi f x)
98-
static member ChooseIndexed (WrappedListD x, f) =
99-
SideEffects.add "Using WrappedListD's ChooseIndexed"
100-
WrappedListD (List.choosei f x)
101-
static member Lift3 (f, WrappedListD x, WrappedListD y, WrappedListD z) =
102-
SideEffects.add "Using WrappedListD's Lift3"
103-
WrappedListD (List.lift3 f x y z)
104-
static member IterateIndexed (WrappedListD x, f) =
105-
SideEffects.add "Using WrappedListD's IterateIndexed"
106-
List.iteri f x
107-
static member inline FoldIndexed (WrappedListD x, f, z) =
108-
SideEffects.add "Using WrappedListD's FoldIndexed"
109-
foldi f z x
110-
static member inline TraverseIndexed (WrappedListD x, f) =
111-
SideEffects.add "Using WrappedListD's TraverseIndexed"
112-
WrappedListD <!> (traversei f x : ^r)
113-
static member FindIndex (WrappedListD x, y) =
114-
SideEffects.add "Using WrappedListD's FindIndex"
115-
findIndex y x
116-
static member FindSliceIndex (WrappedListD x, WrappedListD y) =
117-
SideEffects.add "Using WrappedListD's FindSliceIndex"
118-
findSliceIndex y x
119-
static member FindLastSliceIndex (WrappedListD x, WrappedListD y) =
120-
SideEffects.add "Using WrappedListD's FindLastSliceIndex"
121-
findLastSliceIndex y x
122-
member this.Length =
123-
SideEffects.add "Using WrappedListD's Length"
124-
let (WrappedListD lst) = this
125-
List.length lst
12670
type WrappedListE<'s> = WrappedListE of 's list with
12771
static member Return x = WrappedListE [x]
12872
static member (>>=) (WrappedListE x: WrappedListE<'T>, f) = WrappedListE (List.collect (f >> (fun (WrappedListE x) -> x)) x)

tests/FSharpPlus.Tests/Helpers.fs

Lines changed: 62 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
11
module FSharpPlus.Tests.Helpers
22

3-
open NUnit.Framework
3+
open System
44
open System.Collections
5+
open NUnit.Framework
6+
open FSharpPlus
7+
open FSharpPlus.Control
58

69
let areEqual (x:'t) (y:'t) = Assert.AreEqual (x, y)
710
let areStEqual x y = Assert.IsTrue( (x = y), sprintf "Expected %A to be structurally equal to %A" x y)
@@ -14,3 +17,61 @@ module SideEffects =
1417
let add x = effects.Add (x)
1518
let get () = effects |> Seq.toList
1619
let are lst = areEquivalent lst (get ())
20+
21+
22+
type WrappedListD<'s> = WrappedListD of 's list with
23+
interface Collections.Generic.IEnumerable<'s> with member x.GetEnumerator () = (let (WrappedListD x) = x in x :> _ seq).GetEnumerator ()
24+
interface Collections.IEnumerable with member x.GetEnumerator () = (let (WrappedListD x) = x in x :> _ seq).GetEnumerator () :> Collections.IEnumerator
25+
static member Return (x) = SideEffects.add "Using WrappedListD's Return"; WrappedListD [x]
26+
static member (>>=) ((WrappedListD x):WrappedListD<'T>, f) = SideEffects.add "Using WrappedListD's Bind"; WrappedListD (List.collect (f >> (fun (WrappedListD x) -> x)) x)
27+
static member inline FoldMap (WrappedListD x, f) =
28+
SideEffects.add "Using optimized foldMap"
29+
Seq.fold (fun x y -> x ++ (f y)) zero x
30+
static member Zip (WrappedListD x, WrappedListD y) = SideEffects.add "Using WrappedListD's zip"; WrappedListD (List.zip x y)
31+
static member Exists (x, f) =
32+
SideEffects.add "Using WrappedListD's Exists"
33+
let (WrappedListD lst) = x
34+
List.exists f lst
35+
static member Pick (x, f) =
36+
SideEffects.add "Using WrappedListD's Pick"
37+
let (WrappedListD lst) = x
38+
List.pick f lst
39+
static member Min x =
40+
SideEffects.add "Using WrappedListD's Min"
41+
let (WrappedListD lst) = x
42+
List.min lst
43+
static member MaxBy (x, f) =
44+
SideEffects.add "Using WrappedListD's MaxBy"
45+
let (WrappedListD lst) = x
46+
List.maxBy f lst
47+
static member MapIndexed (WrappedListD x, f) =
48+
SideEffects.add "Using WrappedListD's MapIndexed"
49+
WrappedListD (List.mapi f x)
50+
static member ChooseIndexed (WrappedListD x, f) =
51+
SideEffects.add "Using WrappedListD's ChooseIndexed"
52+
WrappedListD (List.choosei f x)
53+
static member Lift3 (f, WrappedListD x, WrappedListD y, WrappedListD z) =
54+
SideEffects.add "Using WrappedListD's Lift3"
55+
WrappedListD (List.lift3 f x y z)
56+
static member IterateIndexed (WrappedListD x, f) =
57+
SideEffects.add "Using WrappedListD's IterateIndexed"
58+
List.iteri f x
59+
static member inline FoldIndexed (WrappedListD x, f, z) =
60+
SideEffects.add "Using WrappedListD's FoldIndexed"
61+
foldi f z x
62+
static member inline TraverseIndexed (WrappedListD x, f) =
63+
SideEffects.add "Using WrappedListD's TraverseIndexed"
64+
WrappedListD <!> (traversei f x : ^r)
65+
static member FindIndex (WrappedListD x, y) =
66+
SideEffects.add "Using WrappedListD's FindIndex"
67+
findIndex y x
68+
static member FindSliceIndex (WrappedListD x, WrappedListD y) =
69+
SideEffects.add "Using WrappedListD's FindSliceIndex"
70+
findSliceIndex y x
71+
static member FindLastSliceIndex (WrappedListD x, WrappedListD y) =
72+
SideEffects.add "Using WrappedListD's FindLastSliceIndex"
73+
findLastSliceIndex y x
74+
member this.Length =
75+
SideEffects.add "Using WrappedListD's Length"
76+
let (WrappedListD lst) = this
77+
List.length lst

0 commit comments

Comments
 (0)