File tree Expand file tree Collapse file tree 2 files changed +26
-0
lines changed
Expand file tree Collapse file tree 2 files changed +26
-0
lines changed Original file line number Diff line number Diff line change 1+ let fib_zarith n =
2+ let rec fib n a b =
3+ if n = 0 then a else fib (n - 1 ) b (Z. add a b) in
4+ Z. rem (fib n Z. zero Z. one) (Z. of_int 1000007 )
5+
6+ let fib_num n =
7+ let open Big_int in
8+ let rec fib n a b =
9+ if n = 0 then a else fib (n - 1 ) b (add_big_int a b) in
10+ mod_big_int (fib n zero_big_int unit_big_int) (big_int_of_int 1000007 )
Original file line number Diff line number Diff line change 1+ open OUnit
2+
3+ let suite = [
4+ " fib_zarith tests" > :::
5+ [
6+ " Testing 42" > :: (fun _ -> assert_equal (Z. of_int 912427 ) (Solution. fib_zarith 42 ) ~cmp: Z. equal ~printer: Z. to_string);
7+ " Testing 100000" > :: (fun _ -> assert_equal (Z. of_int 584523 ) (Solution. fib_zarith 100000 ) ~cmp: Z. equal ~printer: Z. to_string);
8+ " Testing 1000000" > :: (fun _ -> assert_equal (Z. of_int 930254 ) (Solution. fib_zarith 1000000 ) ~cmp: Z. equal ~printer: Z. to_string);
9+ ];
10+ " fib_num tests" > :::
11+ [
12+ " Testing 42" > :: (fun _ -> assert_equal (Big_int. big_int_of_int 912427 ) (Solution. fib_num 42 ) ~cmp: Big_int. eq_big_int ~printer: Big_int. string_of_big_int);
13+ " Testing 100000" > :: (fun _ -> assert_equal (Big_int. big_int_of_int 584523 ) (Solution. fib_num 100000 ) ~cmp: Big_int. eq_big_int ~printer: Big_int. string_of_big_int);
14+ " Testing 1000000" > :: (fun _ -> assert_equal (Big_int. big_int_of_int 930254 ) (Solution. fib_num 1000000 ) ~cmp: Big_int. eq_big_int ~printer: Big_int. string_of_big_int);
15+ ];
16+ ]
You can’t perform that action at this time.
0 commit comments