Skip to content

Commit 77780b2

Browse files
committed
Move wrapped types to test helper file
1 parent bd7074a commit 77780b2

File tree

3 files changed

+312
-216
lines changed

3 files changed

+312
-216
lines changed

tests/FSharpPlus.Tests/Applicatives.fs

Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,3 +33,87 @@ 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+
[<Test>]
38+
let unzip () =
39+
let testVal = unzip {Head = (1, 'a'); Tail = [(2, 'b');(3, 'b')]}
40+
Assert.IsInstanceOf<Option<NonEmptyList<int> * NonEmptyList<char>>> (Some testVal)
41+
42+
let testVal2 = unzip (NonEmptyMap.Create((1,(true, 'a')), (2, (false, 'b'))))
43+
Assert.IsInstanceOf<Option<NonEmptyMap<int, bool> * NonEmptyMap<int, char>>> (Some testVal2)
44+
45+
[<Test>]
46+
let zipTest () =
47+
48+
SideEffects.reset ()
49+
let _a = zip (seq [1;2;3]) (seq [1. .. 3. ])
50+
Assert.AreEqual (list<string>.Empty, SideEffects.get ())
51+
52+
let _b = zip (WrappedListD [1;2;3]) (WrappedListD [1. .. 3. ])
53+
Assert.AreEqual (["Using WrappedListD's zip"], SideEffects.get ())
54+
55+
let _c = zip (dict [1,'1' ; 2,'2' ; 4,'4']) (dict [1,'1' ; 2,'2' ; 3,'3'])
56+
let _d = zip [ 1;2;3 ] [ 1. .. 3. ]
57+
let _e = zip [|1;2;3|] [|1. .. 3.|]
58+
let _g = zip ((seq [1;2;3]).GetEnumerator ()) ((seq [1. .. 3. ]).GetEnumerator ())
59+
let _h = zip (Map.ofSeq [1,'1' ; 2,'2' ; 4,'4']) (Map.ofSeq [1,'1' ; 2,'2' ; 3,'3'])
60+
let _i = zip (ofSeq [1,'1' ; 2,'2' ; 4,'4'] : Dictionary<_,_>) (ofSeq [1,'1' ; 2,'2' ; 3,'3'] : Dictionary<_,_>)
61+
let _j = zip (async {return 1}) (async {return '2'})
62+
let _h = zip (Task.FromResult 1) (Task.FromResult '2')
63+
let _i = zip List.singleton<int> Array.singleton<int>
64+
let _k = zip (TestNonEmptyCollection.Create 1) (result 2)
65+
66+
let _fa a = zip a (seq [1. .. 3. ])
67+
let _fb a = zip a (WrappedListD [1. .. 3. ])
68+
let _fc a = zip a (dict [1,'1' ; 2,'2' ; 3,'3'])
69+
let _fd a = zip a [ 1. .. 3. ]
70+
let _fe a = zip a [|1. .. 3.|]
71+
let _fg a = zip a ((seq [1. .. 3. ]).GetEnumerator ())
72+
let _fh a = zip a (Map.ofSeq [1,'1' ; 2,'2' ; 3,'3'])
73+
let _fi a = zip a (ofSeq [1,'1' ; 2,'2' ; 3,'3'] : Dictionary<_,_>)
74+
let _fj a = zip a (async {return '2'})
75+
let _fh a = zip a (Task.FromResult '2')
76+
let _fi a = zip a Array.singleton<int>
77+
let _fj a = zip a (TestNonEmptyCollection.Create 2)
78+
79+
let _ga b = zip (seq [1;2;3]) b
80+
let _gb b = zip (WrappedListD [1;2;3]) b
81+
let _gc b = zip (dict [1,'1' ; 2,'2' ; 4,'4']) b
82+
let _gd b = zip [ 1;2;3 ] b
83+
let _ge b = zip [|1;2;3|] b
84+
let _gg b = zip ((seq [1;2;3]).GetEnumerator ()) b
85+
let _gh b = zip (Map.ofSeq [1,'1' ; 2,'2' ; 4,'4']) b
86+
let _gi b = zip (ofSeq [1,'1' ; 2,'2' ; 4,'4'] : Dictionary<_,_>) b
87+
let _gj b = zip (async {return 1}) b
88+
let _gh b = zip (Task.FromResult 1) b
89+
let _gh b = zip List.singleton<int> b
90+
let _gj b = zip (TestNonEmptyCollection.Create 1) b
91+
92+
let _ha : _ -> _ -> _ seq = zip
93+
let _hb : _ -> _ -> _ WrappedListD = zip
94+
let _hc : _ -> _ -> IDictionary<_,_> = zip
95+
let _hd : _ -> _ -> _ list = zip
96+
let _he : _ -> _ -> _ [] = zip
97+
let _hg : _ -> _ -> _ IEnumerator = zip
98+
let _hh : _ -> _ -> Map<_,_> = zip
99+
let _hi : _ -> _ -> Dictionary<_,_> = zip
100+
let _hj : _ -> _ -> Async<_> = zip
101+
let _hh : _ -> _ -> Task<_> = zip
102+
let _hi : _ -> _ -> (int -> _ ) = zip
103+
let _hj : _ -> _ -> NonEmptySeq<_> = zip
104+
105+
()
106+
107+
[<Test>]
108+
let genericZipShortest () =
109+
let a = zip [|1; 2; 3|] [|"a"; "b"|]
110+
CollectionAssert.AreEqual ([|1,"a"; 2,"b"|], a)
111+
112+
let l = zip [1; 2] ["a"; "b"; "c"]
113+
CollectionAssert.AreEqual ([1,"a"; 2,"b"], l)
114+
115+
let e = zip (ResizeArray [1; 2]) (ResizeArray ["a"; "b"; "c"])
116+
CollectionAssert.AreEqual (ResizeArray [1,"a"; 2,"b"], e)
117+
118+
let nel = zip (NonEmptyList.ofList [1; 2]) (NonEmptyList.ofList ["a"; "b"; "c"])
119+
CollectionAssert.AreEqual (NonEmptyList.ofList [1,"a"; 2,"b"], nel)

tests/FSharpPlus.Tests/General.fs

Lines changed: 1 addition & 215 deletions
Original file line numberDiff line numberDiff line change
@@ -12,221 +12,7 @@ open Helpers
1212
open FSharpPlus.Math.Applicative
1313
open CSharpLib
1414

15-
type WrappedMapA<'K,'V when 'K : comparison> = WrappedMapA of Map<'K,'V> with
16-
static member ToMap (WrappedMapA m) = m
17-
static member inline TraverseIndexed (WrappedMapA m, f) =
18-
SideEffects.add "Using WrappedMapA's TraverseIndexed"
19-
WrappedMapA <!> (traversei f m : ^__)
20-
module WrappedMapA=
21-
let inline ofList l = Map.ofList l |> WrappedMapA
22-
23-
type WrappedListA<'s> = WrappedListA of 's list with
24-
static member ToSeq (WrappedListA lst) = SideEffects.add "Using WrappedListA's ToSeq"; List.toSeq lst
25-
static member OfSeq lst = WrappedListA (Seq.toList lst)
26-
static member TryItem (i, WrappedListA x) = List.tryItem i x
27-
static member TryParse x =
28-
if x = "[1;2;3]" then Some (WrappedListA [1;2;3])
29-
else None
30-
static member Exists (x, f) =
31-
SideEffects.add "Using WrappedListA's Exists"
32-
let (WrappedListA lst) = x
33-
List.exists f lst
34-
static member Pick (x, f) =
35-
SideEffects.add "Using WrappedListA's Pick"
36-
let (WrappedListA lst) = x
37-
List.pick f lst
38-
static member Min x =
39-
SideEffects.add "Using WrappedListA's Min"
40-
let (WrappedListA lst) = x
41-
List.min lst
42-
static member MaxBy (x, f) =
43-
SideEffects.add "Using WrappedListA's MaxBy"
44-
let (WrappedListA lst) = x
45-
List.maxBy f lst
46-
member this.Length =
47-
SideEffects.add "Using WrappedListA's Length"
48-
let (WrappedListA lst) = this
49-
List.length lst
50-
51-
type WrappedListB<'s> = WrappedListB of 's list with
52-
static member Return x = WrappedListB [x]
53-
static member (+) (WrappedListB l, WrappedListB x) = WrappedListB (l @ x)
54-
static member Zero = WrappedListB List.empty
55-
static member ToSeq (WrappedListB lst) = List.toSeq lst
56-
static member FoldBack (WrappedListB x, f, z) = List.foldBack f x z
57-
58-
type WrappedListB'<'s> = WrappedListB' of 's list with // Same as B but without clean signatures
59-
static member Return (_:WrappedListB'<'a>, _:Return ) = fun (x:'a) -> WrappedListB' [x]
60-
static member (+) (WrappedListB' l, WrappedListB' x) = WrappedListB' (l @ x)
61-
static member Zero (_:WrappedListB'<'a>, _:Zero) = WrappedListB' List.empty
62-
static member ToSeq (WrappedListB' lst) = List.toSeq lst
63-
static member FoldBack (WrappedListB' x, f, z) = List.foldBack f x z
64-
65-
type WrappedListC<'s> = WrappedListC of 's list with
66-
static member (+) (WrappedListC l, WrappedListC x) = WrappedListC (l @ x)
67-
static member Zero = WrappedListC List.empty
68-
static member Sum (lst: seq<WrappedListC<_>>) = Seq.head lst
69-
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
126-
type WrappedListE<'s> = WrappedListE of 's list with
127-
static member Return x = WrappedListE [x]
128-
static member (>>=) (WrappedListE x: WrappedListE<'T>, f) = WrappedListE (List.collect (f >> (fun (WrappedListE x) -> x)) x)
129-
static member get_Empty () = WrappedListE List.empty
130-
static member (<|>) (WrappedListE l, WrappedListE x) = WrappedListE (l @ x)
131-
132-
type WrappedListF<'s> = WrappedListF of 's list with
133-
static member Return x = WrappedListF [x]
134-
static member (>>=) (WrappedListF x: WrappedListF<'T>, f) = WrappedListF (List.collect (f >> (fun (WrappedListF x) -> x)) x)
135-
static member Join (WrappedListF wlst) = SideEffects.add "Join"; WrappedListF wlst >>= id
136-
static member get_Empty () = WrappedListF List.empty
137-
static member (<|>) (WrappedListF l, WrappedListF x) = WrappedListF (l @ x)
138-
139-
type WrappedListG<'s> = WrappedListG of 's list with
140-
interface Collections.Generic.IEnumerable<'s> with member x.GetEnumerator () = (let (WrappedListG x) = x in x :> _ seq).GetEnumerator ()
141-
interface Collections.IEnumerable with member x.GetEnumerator () = (let (WrappedListG x) = x in x :> _ seq).GetEnumerator () :> Collections.IEnumerator
142-
static member Return x = WrappedListG [x]
143-
static member (>>=) (WrappedListG x: WrappedListG<'T>, f) = WrappedListG (List.collect (f >> (fun (WrappedListG x) -> x)) x)
144-
static member Join (WrappedListG wlst) = (*SideEffects.add "Join";*) WrappedListG wlst >>= id
145-
static member get_Empty () = WrappedListG List.empty
146-
static member (<|>) (WrappedListG l, WrappedListG x) = WrappedListG (l @ x)
147-
static member Delay (f: unit -> WrappedListG<_>) = SideEffects.add "Using WrappedListG's Delay"; f ()
148-
static member Using (resource, body) = SideEffects.add "Using WrappedListG's Using"; using resource body
149-
150-
type WrappedListH<'s> = WrappedListH of 's list with
151-
static member Map (WrappedListH lst, f) = WrappedListH (List.map f lst)
152-
static member inline Sequence (x: WrappedListH<'``Functor<'T>``>) =
153-
let (WrappedListH lst) = x
154-
let s = sequence lst : '``Functor<List<'T>>``
155-
map WrappedListH s : '``Functor<WrappedListH<'T>>``
156-
157-
type WrappedListI<'s> = WrappedListI of 's list with
158-
interface Collections.Generic.IEnumerable<'s> with member x.GetEnumerator () = (let (WrappedListI x) = x in x :> _ seq).GetEnumerator ()
159-
interface Collections.IEnumerable with member x.GetEnumerator () = (let (WrappedListI x) = x in x :> _ seq).GetEnumerator () :> Collections.IEnumerator
160-
static member Return (x) = SideEffects.add "Using WrappedListI's Return"; WrappedListI [x]
161-
static member Sum (lst: seq<WrappedListI<_>>) = Seq.head lst
162-
163-
164-
type WrappedSeqA<'s> = WrappedSeqA of 's seq with
165-
interface Collections.Generic.IEnumerable<'s> with member x.GetEnumerator () = (let (WrappedSeqA x) = x in x).GetEnumerator ()
166-
interface Collections.IEnumerable with member x.GetEnumerator () = (let (WrappedSeqA x) = x in x).GetEnumerator () :> Collections.IEnumerator
167-
static member Return x = WrappedSeqA [x]
168-
static member (>>=) (WrappedSeqA x: WrappedSeqA<'T>, f) = WrappedSeqA (Seq.collect (f >> (fun (WrappedSeqA x) -> x)) x)
169-
static member Join (WrappedSeqA wlst) = WrappedSeqA wlst >>= id
170-
static member get_Empty () = WrappedSeqA List.empty
171-
static member (<|>) (WrappedSeqA l, WrappedSeqA x) = WrappedSeqA (Seq.append l x)
172-
static member Delay (f: unit -> WrappedSeqA<_>) =
173-
let run (WrappedSeqA s) = s
174-
WrappedSeqA (Seq.delay (f >> run))
175-
176-
type WrappedSeqB<'s> = WrappedSeqB of 's seq with
177-
interface Collections.Generic.IEnumerable<'s> with member x.GetEnumerator () = (let (WrappedSeqB x) = x in x).GetEnumerator ()
178-
interface Collections.IEnumerable with member x.GetEnumerator () = (let (WrappedSeqB x) = x in x).GetEnumerator () :> Collections.IEnumerator
179-
static member Return x = WrappedSeqB [x]
180-
static member (>>=) (WrappedSeqB x: WrappedSeqB<'T>, f) = WrappedSeqB (Seq.collect (f >> (fun (WrappedSeqB x) -> x)) x)
181-
static member Join (WrappedSeqB wlst) = WrappedSeqB wlst >>= id
182-
static member get_Empty () = WrappedSeqB List.empty
183-
static member (<|>) (WrappedSeqB l, WrappedSeqB x) = WrappedSeqB (Seq.append l x)
184-
static member Delay (f: unit -> WrappedSeqB<_>) =
185-
let run (WrappedSeqB s) = s
186-
WrappedSeqB (Seq.delay (f >> run))
187-
static member TryFinally (computation, compensation) =
188-
SideEffects.add "Using WrappedSeqA's TryFinally"
189-
try computation finally compensation ()
190-
static member Using (resource, body) =
191-
SideEffects.add "Using WrappedSeqB's Using"
192-
using resource body
193-
194-
type WrappedSeqC<'s> = WrappedSeqC of 's seq with
195-
interface Collections.Generic.IEnumerable<'s> with member x.GetEnumerator () = (let (WrappedSeqC x) = x in x).GetEnumerator ()
196-
interface Collections.IEnumerable with member x.GetEnumerator () = (let (WrappedSeqC x) = x in x).GetEnumerator () :> Collections.IEnumerator
197-
static member Return x = WrappedSeqC [x]
198-
static member (>>=) (WrappedSeqC x: WrappedSeqC<'T>, f) = WrappedSeqC (Seq.collect (f >> (fun (WrappedSeqC x) -> x)) x)
199-
static member Join (WrappedSeqC wlst) = WrappedSeqC wlst >>= id
200-
static member get_Empty () = WrappedSeqC List.empty
201-
static member (<|>) (WrappedSeqC l, WrappedSeqC x) = WrappedSeqC (Seq.append l x)
202-
static member Delay (f: unit -> WrappedSeqC<_>) =
203-
let run (WrappedSeqC s) = s
204-
WrappedSeqC (Seq.delay (f >> run))
205-
static member TryFinally (computation, compensation) =
206-
SideEffects.add "Using WrappedSeqC's TryFinally"
207-
try computation finally compensation ()
208-
209-
type WrappedSeqD<'s> = WrappedSeqD of 's seq with
210-
static member Return x = SideEffects.add "Using WrappedSeqD's Return"; WrappedSeqD (Seq.singleton x)
211-
static member (<*>) (WrappedSeqD f, WrappedSeqD x) = SideEffects.add "Using WrappedSeqD's Apply"; WrappedSeqD (f <*> x)
212-
static member ToList (WrappedSeqD x) = Seq.toList x
213-
static member ChooseIndexed (WrappedSeqD x, f) =
214-
SideEffects.add "Using WrappedSeqD's ChooseIndexed"
215-
WrappedSeqD (Seq.choosei f x)
216-
static member Lift3 (f, WrappedSeqD x, WrappedSeqD y, WrappedSeqD z) =
217-
SideEffects.add "Using WrappedSeqD's Lift3"
218-
WrappedSeqD (Seq.lift3 f x y z)
219-
220-
type WrappedSeqE<'s> = WrappedSeqE of 's seq with
221-
static member Reduce (WrappedSeqE x, reduction) = SideEffects.add "Using WrappedSeqE's Reduce"; Seq.reduce reduction x
222-
static member ToSeq (WrappedSeqE x) = SideEffects.add "Using WrappedSeqE's ToSeq"; x
223-
224-
type WrappedSeqF<'s> = WrappedSeqF of 's seq with
225-
interface Collections.Generic.IEnumerable<'s> with member x.GetEnumerator () = (let (WrappedSeqF x) = x in x).GetEnumerator ()
226-
interface Collections.IEnumerable with member x.GetEnumerator () = (let (WrappedSeqF x) = x in x).GetEnumerator () :> Collections.IEnumerator
227-
static member Return x = SideEffects.add "Using WrappedSeqF's Return"; WrappedSeqF (Seq.singleton x)
228-
static member (<*>) (WrappedSeqF f, WrappedSeqF x) = SideEffects.add "Using WrappedSeqF's Apply"; WrappedSeqF (f <*> x)
229-
static member ToList (WrappedSeqF x) = Seq.toList x
15+
23016

23117
type TestNonEmptyCollection<'a> = private { Singleton: 'a } with
23218
interface NonEmptySeq<'a> with

0 commit comments

Comments
 (0)