mirror of
https://github.com/c-cube/moonpool.git
synced 2025-12-06 03:05:30 -05:00
also add a basic test
This commit is contained in:
parent
2f0cf1970e
commit
db53458897
2 changed files with 53 additions and 0 deletions
3
test/dune
Normal file
3
test/dune
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
(test
|
||||
(name t_fib)
|
||||
(libraries moonpool))
|
||||
50
test/t_fib.ml
Normal file
50
test/t_fib.ml
Normal file
|
|
@ -0,0 +1,50 @@
|
|||
open Moonpool
|
||||
|
||||
let pool = Pool.create ~min:4 ()
|
||||
|
||||
let rec fib x =
|
||||
if x <= 1 then
|
||||
1
|
||||
else
|
||||
fib (x - 1) + fib (x - 2)
|
||||
|
||||
let () = assert (List.init 10 fib = [ 1; 1; 2; 3; 5; 8; 13; 21; 34; 55 ])
|
||||
let fibs = Array.init 30 (fun n -> Fut.spawn ~on:pool (fun () -> fib n))
|
||||
let res = Fut.join_array fibs |> Fut.wait_block
|
||||
|
||||
let () =
|
||||
assert (
|
||||
res
|
||||
= Ok
|
||||
[|
|
||||
1;
|
||||
1;
|
||||
2;
|
||||
3;
|
||||
5;
|
||||
8;
|
||||
13;
|
||||
21;
|
||||
34;
|
||||
55;
|
||||
89;
|
||||
144;
|
||||
233;
|
||||
377;
|
||||
610;
|
||||
987;
|
||||
1597;
|
||||
2584;
|
||||
4181;
|
||||
6765;
|
||||
10946;
|
||||
17711;
|
||||
28657;
|
||||
46368;
|
||||
75025;
|
||||
121393;
|
||||
196418;
|
||||
317811;
|
||||
514229;
|
||||
832040;
|
||||
|])
|
||||
Loading…
Add table
Reference in a new issue