diff options
Diffstat (limited to 'testsuite/tests')
| -rw-r--r-- | testsuite/tests/lib-num-2/Makefile | 23 | ||||
| -rw-r--r-- | testsuite/tests/lib-num-2/pi_big_int.ml | 78 | ||||
| -rw-r--r-- | testsuite/tests/lib-num-2/pi_big_int.reference | 100 | ||||
| -rw-r--r-- | testsuite/tests/lib-num-2/pi_num.ml | 72 | ||||
| -rw-r--r-- | testsuite/tests/lib-num-2/pi_num.reference | 100 | ||||
| -rw-r--r-- | testsuite/tests/lib-num/Makefile | 24 | ||||
| -rw-r--r-- | testsuite/tests/lib-num/end_test.ml | 1 | ||||
| -rw-r--r-- | testsuite/tests/lib-num/end_test.reference | 170 | ||||
| -rw-r--r-- | testsuite/tests/lib-num/test.ml | 103 | ||||
| -rw-r--r-- | testsuite/tests/lib-num/test_big_ints.ml | 1030 | ||||
| -rw-r--r-- | testsuite/tests/lib-num/test_io.ml | 64 | ||||
| -rw-r--r-- | testsuite/tests/lib-num/test_nats.ml | 148 | ||||
| -rw-r--r-- | testsuite/tests/lib-num/test_nums.ml | 234 | ||||
| -rw-r--r-- | testsuite/tests/lib-num/test_ratios.ml | 1195 |
14 files changed, 0 insertions, 3342 deletions
diff --git a/testsuite/tests/lib-num-2/Makefile b/testsuite/tests/lib-num-2/Makefile deleted file mode 100644 index 78930aeffe..0000000000 --- a/testsuite/tests/lib-num-2/Makefile +++ /dev/null @@ -1,23 +0,0 @@ -#************************************************************************** -#* * -#* OCaml * -#* * -#* Xavier Clerc, SED, INRIA Rocquencourt * -#* * -#* Copyright 2010 Institut National de Recherche en Informatique et * -#* en Automatique. * -#* * -#* All rights reserved. This file is distributed under the terms of * -#* the GNU Lesser General Public License version 2.1, with the * -#* special exception on linking described in the file LICENSE. * -#* * -#************************************************************************** - -BASEDIR=../.. -LIBRARIES=nums -ADD_COMPFLAGS=-I $(OTOPDIR)/otherlibs/num -LD_PATH=$(TOPDIR)/otherlibs/num -PROGRAM_ARGS=1000 - -include $(BASEDIR)/makefiles/Makefile.several -include $(BASEDIR)/makefiles/Makefile.common diff --git a/testsuite/tests/lib-num-2/pi_big_int.ml b/testsuite/tests/lib-num-2/pi_big_int.ml deleted file mode 100644 index 22872ba483..0000000000 --- a/testsuite/tests/lib-num-2/pi_big_int.ml +++ /dev/null @@ -1,78 +0,0 @@ -(* Pi digits computed with the sreaming algorithm given on pages 4, 6 - & 7 of "Unbounded Spigot Algorithms for the Digits of Pi", Jeremy - Gibbons, August 2004. *) - -open Printf;; -open Big_int;; - -let ( !$ ) = Big_int.big_int_of_int -and ( +$ ) = Big_int.add_big_int -and ( *$ ) = Big_int.mult_big_int -and ( =$ ) = Big_int.eq_big_int -;; - -let zero = Big_int.zero_big_int -and one = Big_int.unit_big_int -and three = !$ 3 -and four = !$ 4 -and ten = !$ 10 -and neg_ten = !$(-10) -;; - -(* Linear Fractional (aka M=F6bius) Transformations *) -module LFT = struct - - let floor_ev (q, r, s, t) x = div_big_int (q *$ x +$ r) (s *$ x +$ t);; - - let unit = (one, zero, zero, one);; - - let comp (q, r, s, t) (q', r', s', t') = - (q *$ q' +$ r *$ s', q *$ r' +$ r *$ t', - s *$ q' +$ t *$ s', s *$ r' +$ t *$ t') -;; - -end -;; - -let next z = LFT.floor_ev z three -and safe z n = (n =$ LFT.floor_ev z four) -and prod z n = LFT.comp (ten, neg_ten *$ n, zero, one) z -and cons z k = - let den = 2 * k + 1 in - LFT.comp z (!$ k, !$(2 * den), zero, !$ den) -;; - -let rec digit k z n row col = - if n > 0 then - let y = next z in - if safe z y then - if col = 10 then ( - let row = row + 10 in - printf "\t:%i\n%s" row (string_of_big_int y); - digit k (prod z y) (n - 1) row 1 - ) - else ( - print_string(string_of_big_int y); - digit k (prod z y) (n - 1) row (col + 1) - ) - else digit (k + 1) (cons z k) n row col - else - printf "%*s\t:%i\n" (10 - col) "" (row + col) -;; - -let digits n = digit 1 LFT.unit n 0 0 -;; - -let usage () = - prerr_endline "Usage: pi_big_int <number of digits to compute for pi>"; - exit 2 -;; - -let main () = - let args = Sys.argv in - if Array.length args <> 2 then usage () else - digits (int_of_string Sys.argv.(1)) -;; - -main () -;; diff --git a/testsuite/tests/lib-num-2/pi_big_int.reference b/testsuite/tests/lib-num-2/pi_big_int.reference deleted file mode 100644 index ad4dc9962b..0000000000 --- a/testsuite/tests/lib-num-2/pi_big_int.reference +++ /dev/null @@ -1,100 +0,0 @@ -3141592653 :10 -5897932384 :20 -6264338327 :30 -9502884197 :40 -1693993751 :50 -0582097494 :60 -4592307816 :70 -4062862089 :80 -9862803482 :90 -5342117067 :100 -9821480865 :110 -1328230664 :120 -7093844609 :130 -5505822317 :140 -2535940812 :150 -8481117450 :160 -2841027019 :170 -3852110555 :180 -9644622948 :190 -9549303819 :200 -6442881097 :210 -5665933446 :220 -1284756482 :230 -3378678316 :240 -5271201909 :250 -1456485669 :260 -2346034861 :270 -0454326648 :280 -2133936072 :290 -6024914127 :300 -3724587006 :310 -6063155881 :320 -7488152092 :330 -0962829254 :340 -0917153643 :350 -6789259036 :360 -0011330530 :370 -5488204665 :380 -2138414695 :390 -1941511609 :400 -4330572703 :410 -6575959195 :420 -3092186117 :430 -3819326117 :440 -9310511854 :450 -8074462379 :460 -9627495673 :470 -5188575272 :480 -4891227938 :490 -1830119491 :500 -2983367336 :510 -2440656643 :520 -0860213949 :530 -4639522473 :540 -7190702179 :550 -8609437027 :560 -7053921717 :570 -6293176752 :580 -3846748184 :590 -6766940513 :600 -2000568127 :610 -1452635608 :620 -2778577134 :630 -2757789609 :640 -1736371787 :650 -2146844090 :660 -1224953430 :670 -1465495853 :680 -7105079227 :690 -9689258923 :700 -5420199561 :710 -1212902196 :720 -0864034418 :730 -1598136297 :740 -7477130996 :750 -0518707211 :760 -3499999983 :770 -7297804995 :780 -1059731732 :790 -8160963185 :800 -9502445945 :810 -5346908302 :820 -6425223082 :830 -5334468503 :840 -5261931188 :850 -1710100031 :860 -3783875288 :870 -6587533208 :880 -3814206171 :890 -7766914730 :900 -3598253490 :910 -4287554687 :920 -3115956286 :930 -3882353787 :940 -5937519577 :950 -8185778053 :960 -2171226806 :970 -6130019278 :980 -7661119590 :990 -9216420198 :1000 diff --git a/testsuite/tests/lib-num-2/pi_num.ml b/testsuite/tests/lib-num-2/pi_num.ml deleted file mode 100644 index e2580c10bd..0000000000 --- a/testsuite/tests/lib-num-2/pi_num.ml +++ /dev/null @@ -1,72 +0,0 @@ -(* Pi digits computed with the sreaming algorithm given on pages 4, 6 - & 7 of "Unbounded Spigot Algorithms for the Digits of Pi", Jeremy - Gibbons, August 2004. *) - -open Printf;; -open Num;; - -let zero = num_of_int 0 -and one = num_of_int 1 -and three = num_of_int 3 -and four = num_of_int 4 -and ten = num_of_int 10 -and neg_ten = num_of_int(-10) -;; - -(* Linear Fractional Transformation *) -module LFT = struct - - let floor_ev (q, r, s, t) x = quo_num (q */ x +/ r) (s */ x +/ t);; - - let unit = (one, zero, zero, one);; - - let comp (q, r, s, t) (q', r', s', t') = - (q */ q' +/ r */ s', q */ r' +/ r */ t', - s */ q' +/ t */ s', s */ r' +/ t */ t') -;; - -end -;; - -let next z = LFT.floor_ev z three -and safe z n = (n =/ LFT.floor_ev z four) -and prod z n = LFT.comp (ten, neg_ten */ n, zero, one) z -and cons z k = - let den = 2 * k + 1 in - LFT.comp z (num_of_int k, num_of_int(2 * den), zero, num_of_int den) -;; - -let rec digit k z n row col = - if n > 0 then - let y = next z in - if safe z y then - if col = 10 then ( - let row = row + 10 in - printf "\t:%i\n%s" row (string_of_num y); - digit k (prod z y) (n-1) row 1 - ) - else ( - print_string(string_of_num y); - digit k (prod z y) (n-1) row (col + 1) - ) - else digit (k + 1) (cons z k) n row col - else - printf "%*s\t:%i\n" (10 - col) "" (row + col) -;; - -let digits n = digit 1 LFT.unit n 0 0 -;; - -let usage () = - prerr_endline "Usage: pi_num <number of digits to compute for pi>"; - exit 2 -;; - -let main () = - let args = Sys.argv in - if Array.length args <> 2 then usage () else - digits (int_of_string Sys.argv.(1)) -;; - -main () -;; diff --git a/testsuite/tests/lib-num-2/pi_num.reference b/testsuite/tests/lib-num-2/pi_num.reference deleted file mode 100644 index ad4dc9962b..0000000000 --- a/testsuite/tests/lib-num-2/pi_num.reference +++ /dev/null @@ -1,100 +0,0 @@ -3141592653 :10 -5897932384 :20 -6264338327 :30 -9502884197 :40 -1693993751 :50 -0582097494 :60 -4592307816 :70 -4062862089 :80 -9862803482 :90 -5342117067 :100 -9821480865 :110 -1328230664 :120 -7093844609 :130 -5505822317 :140 -2535940812 :150 -8481117450 :160 -2841027019 :170 -3852110555 :180 -9644622948 :190 -9549303819 :200 -6442881097 :210 -5665933446 :220 -1284756482 :230 -3378678316 :240 -5271201909 :250 -1456485669 :260 -2346034861 :270 -0454326648 :280 -2133936072 :290 -6024914127 :300 -3724587006 :310 -6063155881 :320 -7488152092 :330 -0962829254 :340 -0917153643 :350 -6789259036 :360 -0011330530 :370 -5488204665 :380 -2138414695 :390 -1941511609 :400 -4330572703 :410 -6575959195 :420 -3092186117 :430 -3819326117 :440 -9310511854 :450 -8074462379 :460 -9627495673 :470 -5188575272 :480 -4891227938 :490 -1830119491 :500 -2983367336 :510 -2440656643 :520 -0860213949 :530 -4639522473 :540 -7190702179 :550 -8609437027 :560 -7053921717 :570 -6293176752 :580 -3846748184 :590 -6766940513 :600 -2000568127 :610 -1452635608 :620 -2778577134 :630 -2757789609 :640 -1736371787 :650 -2146844090 :660 -1224953430 :670 -1465495853 :680 -7105079227 :690 -9689258923 :700 -5420199561 :710 -1212902196 :720 -0864034418 :730 -1598136297 :740 -7477130996 :750 -0518707211 :760 -3499999983 :770 -7297804995 :780 -1059731732 :790 -8160963185 :800 -9502445945 :810 -5346908302 :820 -6425223082 :830 -5334468503 :840 -5261931188 :850 -1710100031 :860 -3783875288 :870 -6587533208 :880 -3814206171 :890 -7766914730 :900 -3598253490 :910 -4287554687 :920 -3115956286 :930 -3882353787 :940 -5937519577 :950 -8185778053 :960 -2171226806 :970 -6130019278 :980 -7661119590 :990 -9216420198 :1000 diff --git a/testsuite/tests/lib-num/Makefile b/testsuite/tests/lib-num/Makefile deleted file mode 100644 index 14f0d2c1a8..0000000000 --- a/testsuite/tests/lib-num/Makefile +++ /dev/null @@ -1,24 +0,0 @@ -#************************************************************************** -#* * -#* OCaml * -#* * -#* Xavier Clerc, SED, INRIA Rocquencourt * -#* * -#* Copyright 2010 Institut National de Recherche en Informatique et * -#* en Automatique. * -#* * -#* All rights reserved. This file is distributed under the terms of * -#* the GNU Lesser General Public License version 2.1, with the * -#* special exception on linking described in the file LICENSE. * -#* * -#************************************************************************** - -BASEDIR=../.. -MODULES=test test_nats test_big_ints test_ratios test_nums test_io -MAIN_MODULE=end_test -LIBRARIES=nums -ADD_COMPFLAGS=-w a -I $(OTOPDIR)/otherlibs/num -LD_PATH=$(TOPDIR)/otherlibs/num - -include $(BASEDIR)/makefiles/Makefile.one -include $(BASEDIR)/makefiles/Makefile.common diff --git a/testsuite/tests/lib-num/end_test.ml b/testsuite/tests/lib-num/end_test.ml deleted file mode 100644 index 57e099eda5..0000000000 --- a/testsuite/tests/lib-num/end_test.ml +++ /dev/null @@ -1 +0,0 @@ -Test.end_tests ();; diff --git a/testsuite/tests/lib-num/end_test.reference b/testsuite/tests/lib-num/end_test.reference deleted file mode 100644 index ab99ae015d..0000000000 --- a/testsuite/tests/lib-num/end_test.reference +++ /dev/null @@ -1,170 +0,0 @@ - -num_digits_nat - -1... 0... 1... -length_nat - 1... -equal_nat - 1... 2... 3... 4... -incr_nat - 1... 2... 3... 4... -decr_nat - 1... 2... 3... 4... -is_zero_nat - 1... 2... 3... 4... -string_of_nat - 1... 2... -string_of_nat && nat_of_string - 1... 2... 3... 4... 5... 6... 7... 8... 9... 10... 11... 12... 13... 14... 15... 16... 17... 18... 19... 20... 21... 22... -gcd_nat - 1... 2... 3... 4... 5... 6... 7... 8... 9... 10... 11... 12... 13... 14... 15... 16... 17... 18... 19... 20... -sqrt_nat - 1... 2... 3... 4... 5... -compare_big_int - 1... 2... 3... 4... 5... 6... 7... 8... 9... 10... 11... 12... 13... -pred_big_int - 1... 2... 3... -succ_big_int - 1... 2... 3... -add_big_int - 1... 2... 3... 4... 5... 6... 7... 8... 9... 10... 11... 12... 13... 14... 15... 16... 17... -sub_big_int - 1... 2... 3... 4... 5... 6... 7... 8... 9... 10... 11... 12... 13... 14... 15... 16... 17... -mult_int_big_int - 1... 2... 3... 4... -mult_big_int - 1... 2... 3... 4... 5... -quomod_big_int - 1... 2... 3... 4... 5... 6... 7... 8... 9... 10... 11... 12... 13... 14... 15... 16... 17... 18... 19... 20... 21... 22... 23... 24... 25... -gcd_big_int - 1... 2... 3... 4... 5... 6... 7... 8... 9... 10... 11... 12... 13... 14... 15... 16... 17... 18... 19... 20... 21... 22... 23... 24... 25... 26... 27... 28... -int_of_big_int - 1... 2... 3... 4... 5... 6... 7... 8... -is_int_big_int - 1... 2... 3... 4... 5... 6... 7... 8... 9... 10... -sys_string_of_big_int - 1... -big_int_of_string - 1... 2... 4... 5... 6... 7... 9... 10... 18... 19... 20... 21... -power_base_int - 1... 2... 3... -base_power_big_int - 1... 2... 3... -power_int_positive_big_int - 1... 2... 3... 4... 5... 6... 7... -power_big_int_positive_int - 1... 2... 3... 4... 5... -power_big_int_positive_big_int - 1... 2... 3... 4... 5... 6... 7... 8... 9... -square_big_int - 1... 2... 3... 4... -big_int_of_nativeint - 1... 2... 3... -nativeint_of_big_int - 1... 2... 2... -big_int_of_int32 - 1... 2... 3... -int32_of_big_int - 1... 2... 3... 4... 5... 6... 7... 8... -big_int_of_int64 - 1... 2... 3... 4... 5... 6... 7... 8... -int64_of_big_int - 1... 2... 3... 4... 5... 6... 7... 8... -and_big_int - 1... 2... 3... 4... 5... 6... -or_big_int - 1... 2... 3... 4... 5... 6... -xor_big_int - 1... 2... 3... 4... 5... 6... -shift_left_big_int - 1... 2... 2... 3... 4... 5... 6... -shift_right_big_int - 1... 2... 3... 4... 5... 6... -shift_right_towards_zero_big_int - 1... 2... -extract_big_int - 1... 2... 3... 4... 5... 6... 7... 8... 9... 10... -hashing of big integers - 1... 2... 3... 4... 5... 6... -float_of_big_int - 1... 2... 3... 4... 5... 6... 7... 8... -create_ratio - 1... 2... 3... 4... 5... 6... 7... 8... -create_normalized_ratio - 1... 2... 3... 4... 5... 6... 7... 8... 9... 10... -null_denominator - 1... 2... -sign_ratio - 1... 2... 3... -normalize_ratio - 1... 2... 3... 4... -report_sign_ratio - 1... 2... -is_integer_ratio - 1... 2... -add_ratio - 1... 2... 3... 4... 5... 6... 7... 8... 9... 10... 11... 12... 1... 2... 3... 4... -sub_ratio - 1... 2... 3... 4... 5... 6... 7... 8... -mult_ratio - 1... 2... 3... 4... 5... 6... 7... 8... -div_ratio - 1... 2... 3... 4... 5... 6... 7... 8... -integer_ratio - 1... 2... 3... 4... 5... -floor_ratio - 1... 2... 3... 4... 5... -round_ratio - 1... 2... 3... 4... 5... -ceiling_ratio - 1... 2... 3... 4... 5... 6... -eq_ratio - 1... 2... 3... 4... 5... -compare_ratio - 1... 2... 3... 4... 5... 6... 7... 8... 9... 10... 11... 12... 13... 14... 15... 16... 17... 18... 19... 20... 21... 22... 23... 24... 25... 26... 27... 28... 29... 30... 31... 32... 33... 34... 35... 36... -eq_big_int_ratio - 1... 2... 3... 4... 5... -compare_big_int_ratio - 1... 2... 3... 4... 5... 6... 7... 8... 9... -int_of_ratio - 1... 2... 3... 4... 5... -ratio_of_int - 1... 2... -nat_of_ratio - 1... 2... 3... 4... -ratio_of_big_int - 1... -big_int_of_ratio - 1... 2... 3... -string_of_ratio - 1... 2... 3... 4... -ratio_of_string - 1... 6... 7... 8... -round_futur_last_digit - 1... 2... 3... 4... 5... 6... 7... 8... 9... 10... 11... 12... 13... 14... 15... 16... 17... 18... 19... 20... 21... 22... 23... 24... -approx_ratio_fix - 1... 2... 3... 4... 5... 6... 7... 8... 9... 10... 11... 12... 13... 14... -approx_ratio_exp - 1... 2... 3... 4... 5... 6... 7... 8... 9... -float_of_ratio - 1... -add_num - 1... 2... 3... 4... 5... 6... 7... 8... 9... -sub_num - 1... 2... 3... 4... 5... 7... 8... 9... 10... -mult_num - 1... 2... 3... 4... 5... 6... 7... 8... 9... -div_num - 1... 2... 3... 4... 5... 6... 7... 8... 9... -is_integer_num - 1... 2... 3... 4... -num_of_ratio - 1... 2... 3... -num_of_string - 1... 7... 8... 11... 12... 13... 14... 15... -output_value/input_value on nats - 1... 2... 3... 4... 5... 6... 7... -output_value/input_value on big ints - 1... 2... 3... 4... 5... -output_value/input_value on nums - 1... 2... 3... 4... 5... 6... 7... 8... -************* TESTS COMPLETED SUCCESSFULLY **************** diff --git a/testsuite/tests/lib-num/test.ml b/testsuite/tests/lib-num/test.ml deleted file mode 100644 index b45d05d1fa..0000000000 --- a/testsuite/tests/lib-num/test.ml +++ /dev/null @@ -1,103 +0,0 @@ -open Printf;; - -let flush_all () = flush stdout; flush stderr;; - -let message s = print_string s; print_newline ();; - -let error_occurred = ref false;; -let immediate_failure = ref true;; - -let error () = - if !immediate_failure then exit 2 else begin - error_occurred := true; - flush_all (); - false - end;; - -let success () = flush_all (); true;; - -let function_tested = ref "";; - -let testing_function s = - flush_all (); - function_tested := s; - print_newline(); - message s;; - -let test test_number eq_fun (answer, correct_answer) = - flush_all (); - if not (eq_fun answer correct_answer) then begin - fprintf stderr ">>> Bad result (%s, test %d)\n" !function_tested test_number; - error () - end else begin - printf " %d..." test_number; - success () - end;; - -let failure_test test_number fun_to_test arg = - flush_all (); - try - fun_to_test arg; - fprintf stderr ">>> Failure expected (%s, test %d)\n" - !function_tested test_number; - error () - with _ -> - printf " %d..." test_number; - success ();; - -let failwith_test test_number fun_to_test arg correct_failure = - flush_all (); - try - fun_to_test arg; - fprintf stderr ">>> Failure expected (%s, test %d)\n" - !function_tested test_number; - error () - with x -> - if x = correct_failure then begin - printf " %d..." test_number; - success () - end else begin - fprintf stderr ">>> Bad failure (%s, test %d)\n" - !function_tested test_number; - error () - end;; - -let end_tests () = - flush_all (); - print_newline (); - if !error_occurred then begin - print_endline "************* TESTS FAILED ****************"; exit 2 - end else begin - print_endline "************* TESTS COMPLETED SUCCESSFULLY ****************"; - exit 0 - end;; - -let eq = (==);; -let eq_int (i: int) (j: int) = (i = j);; -let eq_string (i: string) (j: string) = (i = j);; -let eq_bytes (i: bytes) (j: bytes) = (i = j);; -let eq_nativeint (i: nativeint) (j: nativeint) = (i = j);; -let eq_int32 (i: int32) (j: int32) = (i = j);; -let eq_int64 (i: int64) (j: int64) = (i = j);; -let eq_float (x: float) (y: float) = Pervasives.compare x y = 0;; - -let sixtyfour = (1 lsl 31) <> 0;; - -let rec gcd_int i1 i2 = - if i2 = 0 then abs i1 else gcd_int i2 (i1 mod i2);; - -let rec num_bits_int_aux n = - if n = 0 then 0 else succ(num_bits_int_aux (n lsr 1));; - -let num_bits_int n = num_bits_int_aux (abs n);; - -let sign_int i = if i = 0 then 0 else if i > 0 then 1 else -1;; - -let length_of_int = Sys.word_size - 2;; - -let monster_int = 1 lsl length_of_int;; -let biggest_int = monster_int - 1;; -let least_int = - biggest_int;; - -let compare_int n1 n2 = - if n1 == n2 then 0 else if n1 > n2 then 1 else -1;; diff --git a/testsuite/tests/lib-num/test_big_ints.ml b/testsuite/tests/lib-num/test_big_ints.ml deleted file mode 100644 index 61e4a9f2df..0000000000 --- a/testsuite/tests/lib-num/test_big_ints.ml +++ /dev/null @@ -1,1030 +0,0 @@ -open Test;; -open Nat;; -open Big_int;; -open List;; - -testing_function "compare_big_int";; - -test 1 -eq_int (compare_big_int zero_big_int zero_big_int, 0);; -test 2 -eq_int (compare_big_int zero_big_int (big_int_of_int 1), (-1));; -test 3 -eq_int (compare_big_int zero_big_int (big_int_of_int (-1)), 1);; -test 4 -eq_int (compare_big_int (big_int_of_int 1) zero_big_int, 1);; -test 5 -eq_int (compare_big_int (big_int_of_int (-1)) zero_big_int, (-1));; -test 6 -eq_int (compare_big_int (big_int_of_int 1) (big_int_of_int 1), 0);; -test 7 -eq_int (compare_big_int (big_int_of_int (-1)) (big_int_of_int (-1)), 0);; -test 8 -eq_int (compare_big_int (big_int_of_int 1) (big_int_of_int (-1)), 1);; -test 9 -eq_int (compare_big_int (big_int_of_int (-1)) (big_int_of_int 1), (-1));; -test 10 -eq_int (compare_big_int (big_int_of_int 1) (big_int_of_int 2), (-1));; -test 11 -eq_int (compare_big_int (big_int_of_int 2) (big_int_of_int 1), 1);; -test 12 -eq_int (compare_big_int (big_int_of_int (-1)) (big_int_of_int (-2)), 1);; -test 13 -eq_int (compare_big_int (big_int_of_int (-2)) (big_int_of_int (-1)), (-1));; - - -testing_function "pred_big_int";; - -test 1 -eq_big_int (pred_big_int zero_big_int, big_int_of_int (-1));; -test 2 -eq_big_int (pred_big_int unit_big_int, zero_big_int);; -test 3 -eq_big_int (pred_big_int (big_int_of_int (-1)), big_int_of_int (-2));; - -testing_function "succ_big_int";; - -test 1 -eq_big_int (succ_big_int zero_big_int, unit_big_int);; -test 2 -eq_big_int (succ_big_int unit_big_int, big_int_of_int 2);; -test 3 -eq_big_int (succ_big_int (big_int_of_int (-1)), zero_big_int);; - -testing_function "add_big_int";; - -test 1 -eq_big_int (add_big_int zero_big_int zero_big_int, zero_big_int);; -test 2 -eq_big_int (add_big_int zero_big_int (big_int_of_int 1), - big_int_of_int 1);; -test 3 -eq_big_int (add_big_int (big_int_of_int 1) zero_big_int, - big_int_of_int 1);; -test 4 -eq_big_int (add_big_int zero_big_int (big_int_of_int (-1)), - big_int_of_int (-1));; -test 5 -eq_big_int (add_big_int (big_int_of_int (-1)) zero_big_int, - big_int_of_int (-1));; -test 6 -eq_big_int (add_big_int (big_int_of_int 1) (big_int_of_int 1), - big_int_of_int 2);; -test 7 -eq_big_int (add_big_int (big_int_of_int 1) (big_int_of_int 2), - big_int_of_int 3);; -test 8 -eq_big_int (add_big_int (big_int_of_int 2) (big_int_of_int 1), - big_int_of_int 3);; -test 9 -eq_big_int (add_big_int (big_int_of_int (-1)) (big_int_of_int (-1)), - big_int_of_int (-2));; -test 10 -eq_big_int (add_big_int (big_int_of_int (-1)) (big_int_of_int (-2)), - big_int_of_int (-3));; -test 11 -eq_big_int (add_big_int (big_int_of_int (-2)) (big_int_of_int (-1)), - big_int_of_int (-3));; -test 12 -eq_big_int (add_big_int (big_int_of_int 1) (big_int_of_int (-1)), - zero_big_int);; -test 13 -eq_big_int (add_big_int (big_int_of_int (-1)) (big_int_of_int 1), - zero_big_int);; -test 14 -eq_big_int (add_big_int (big_int_of_int 1) (big_int_of_int (-2)), - big_int_of_int (-1));; -test 15 -eq_big_int (add_big_int (big_int_of_int (-2)) (big_int_of_int 1), - big_int_of_int (-1));; -test 16 -eq_big_int (add_big_int (big_int_of_int (-1)) (big_int_of_int 2), - big_int_of_int 1);; -test 17 -eq_big_int (add_big_int (big_int_of_int 2) (big_int_of_int (-1)), - big_int_of_int 1);; - - -testing_function "sub_big_int";; - -test 1 -eq_big_int (sub_big_int zero_big_int zero_big_int, zero_big_int);; -test 2 -eq_big_int (sub_big_int zero_big_int (big_int_of_int 1), - big_int_of_int (-1));; -test 3 -eq_big_int (sub_big_int (big_int_of_int 1) zero_big_int, - big_int_of_int 1);; -test 4 -eq_big_int (sub_big_int zero_big_int (big_int_of_int (-1)), - big_int_of_int 1);; -test 5 -eq_big_int (sub_big_int (big_int_of_int (-1)) zero_big_int, - big_int_of_int (-1));; -test 6 -eq_big_int (sub_big_int (big_int_of_int 1) (big_int_of_int 1), - zero_big_int);; -test 7 -eq_big_int (sub_big_int (big_int_of_int 1) (big_int_of_int 2), - big_int_of_int (-1));; -test 8 -eq_big_int (sub_big_int (big_int_of_int 2) (big_int_of_int 1), - big_int_of_int 1);; -test 9 -eq_big_int (sub_big_int (big_int_of_int (-1)) (big_int_of_int (-1)), - zero_big_int);; -test 10 -eq_big_int (sub_big_int (big_int_of_int (-1)) (big_int_of_int (-2)), - big_int_of_int 1);; -test 11 -eq_big_int (sub_big_int (big_int_of_int (-2)) (big_int_of_int (-1)), - big_int_of_int (-1));; -test 12 -eq_big_int (sub_big_int (big_int_of_int 1) (big_int_of_int (-1)), - big_int_of_int 2);; -test 13 -eq_big_int (sub_big_int (big_int_of_int (-1)) (big_int_of_int 1), - big_int_of_int (-2));; -test 14 -eq_big_int (sub_big_int (big_int_of_int 1) (big_int_of_int (-2)), - big_int_of_int 3);; -test 15 -eq_big_int (sub_big_int (big_int_of_int (-2)) (big_int_of_int 1), - big_int_of_int (-3));; -test 16 -eq_big_int (sub_big_int (big_int_of_int (-1)) (big_int_of_int 2), - big_int_of_int (-3));; -test 17 -eq_big_int (sub_big_int (big_int_of_int 2) (big_int_of_int (-1)), - big_int_of_int 3);; - -testing_function "mult_int_big_int";; - -test 1 -eq_big_int (mult_int_big_int 0 (big_int_of_int 3), zero_big_int);; -test 2 -eq_big_int (mult_int_big_int 1 (big_int_of_int 3), big_int_of_int 3);; -test 3 -eq_big_int (mult_int_big_int 1 zero_big_int, zero_big_int);; -test 4 -eq_big_int (mult_int_big_int 2 (big_int_of_int 3), big_int_of_int 6);; - -testing_function "mult_big_int";; - -test 1 -eq_big_int (mult_big_int zero_big_int zero_big_int, - zero_big_int);; -test 2 -eq_big_int (mult_big_int (big_int_of_int 2) (big_int_of_int 3), - big_int_of_int 6);; -test 3 -eq_big_int (mult_big_int (big_int_of_int 2) (big_int_of_int (-3)), - big_int_of_int (-6));; -test 4 -eq_big_int (mult_big_int (big_int_of_string "12724951") - (big_int_of_string "81749606400"), - big_int_of_string "1040259735709286400");; -test 5 -eq_big_int (mult_big_int (big_int_of_string "26542080") - (big_int_of_string "81749606400"), - big_int_of_string "2169804593037312000");; - -testing_function "quomod_big_int";; - -let (quotient, modulo) = - quomod_big_int (big_int_of_int 1) (big_int_of_int 1) in - test 1 eq_big_int (quotient, big_int_of_int 1) && - test 2 eq_big_int (modulo, zero_big_int);; - -let (quotient, modulo) = - quomod_big_int (big_int_of_int 1) (big_int_of_int (-1)) in - test 3 eq_big_int (quotient, big_int_of_int (-1)) && - test 4 eq_big_int (modulo, zero_big_int);; - -let (quotient, modulo) = - quomod_big_int (big_int_of_int (-1)) (big_int_of_int 1) in - test 5 eq_big_int (quotient, big_int_of_int (-1)) && - test 6 eq_big_int (modulo, zero_big_int);; - -let (quotient, modulo) = - quomod_big_int (big_int_of_int 3) (big_int_of_int 2) in - test 7 eq_big_int (quotient, big_int_of_int 1) && - test 8 eq_big_int (modulo, big_int_of_int 1);; - -let (quotient, modulo) = - quomod_big_int (big_int_of_int 5) (big_int_of_int 3) in - test 9 eq_big_int (quotient, big_int_of_int 1) && - test 10 eq_big_int (modulo, big_int_of_int 2);; - -let (quotient, modulo) = - quomod_big_int (big_int_of_int (-5)) (big_int_of_int 3) in - test 11 eq_big_int (quotient, big_int_of_int (-2)) && - test 12 eq_big_int (modulo, big_int_of_int 1);; - -let (quotient, modulo) = - quomod_big_int (big_int_of_int 1) (big_int_of_int 2) in - test 13 eq_big_int (quotient, zero_big_int) && - test 14 eq_big_int (modulo, big_int_of_int 1);; - -let (quotient, modulo) = - quomod_big_int (big_int_of_int (-1)) (big_int_of_int 3) in - test 15 eq_big_int (quotient, minus_big_int unit_big_int) && - test 16 eq_big_int (modulo, big_int_of_int 2);; - -failwith_test 17 -(quomod_big_int (big_int_of_int 1)) zero_big_int -Division_by_zero -;; - -let (quotient, modulo) = - quomod_big_int (big_int_of_int 10) (big_int_of_int 20) in - test 18 eq_big_int (quotient, big_int_of_int 0) && - test 19 eq_big_int (modulo, big_int_of_int 10);; - -let (quotient, modulo) = - quomod_big_int (big_int_of_int (-10)) (big_int_of_int 20) in - test 20 eq_big_int (quotient, big_int_of_int (-1)) && - test 21 eq_big_int (modulo, big_int_of_int 10);; - -let (quotient, modulo) = - quomod_big_int (big_int_of_int 10) (big_int_of_int (-20)) in - test 22 eq_big_int (quotient, big_int_of_int 0) && - test 23 eq_big_int (modulo, big_int_of_int 10);; - -let (quotient, modulo) = - quomod_big_int (big_int_of_int (-10)) (big_int_of_int (-20)) in - test 24 eq_big_int (quotient, big_int_of_int 1) && - test 25 eq_big_int (modulo, big_int_of_int 10);; - - -testing_function "gcd_big_int";; - -test 1 -eq_big_int (gcd_big_int zero_big_int zero_big_int, - zero_big_int);; -test 2 -eq_big_int (gcd_big_int zero_big_int (big_int_of_int 1), - big_int_of_int 1);; -test 3 -eq_big_int (gcd_big_int (big_int_of_int 1) zero_big_int, - big_int_of_int 1);; -test 4 -eq_big_int (gcd_big_int (big_int_of_int 1) (big_int_of_int 2), - big_int_of_int 1);; -test 5 -eq_big_int (gcd_big_int (big_int_of_int 2) (big_int_of_int 1), - big_int_of_int 1);; -test 6 -eq_big_int (gcd_big_int (big_int_of_int 1) (big_int_of_int 1), - big_int_of_int 1);; -test 7 -eq_big_int (gcd_big_int (big_int_of_int 9) (big_int_of_int 16), - big_int_of_int 1);; -test 8 -eq_big_int (gcd_big_int (big_int_of_int 12) (big_int_of_int 16), - big_int_of_int 4);; - -for i = 9 to 28 do - let n1 = Random.int 1000000000 - and n2 = Random.int 100000 in - let _ = - test i eq - (int_of_big_int (gcd_big_int (big_int_of_int n1) (big_int_of_int n2)), - gcd_int n1 n2) in - () -done;; - -testing_function "int_of_big_int";; - -test 1 -eq_int (int_of_big_int (big_int_of_int 1), 1);; -test 2 -eq_int (int_of_big_int (big_int_of_int(-1)), -1);; -test 3 -eq_int (int_of_big_int zero_big_int, 0);; -test 4 -eq_int (int_of_big_int (big_int_of_int max_int), max_int);; -test 5 -eq_int (int_of_big_int (big_int_of_int min_int), min_int);; -failwith_test 6 - (fun () -> int_of_big_int (succ_big_int (big_int_of_int max_int))) - () (Failure "int_of_big_int");; -failwith_test 7 - (fun () -> int_of_big_int (pred_big_int (big_int_of_int min_int))) - () (Failure "int_of_big_int");; -failwith_test 8 - (fun () -> int_of_big_int (mult_big_int (big_int_of_int min_int) - (big_int_of_int 2))) - () (Failure "int_of_big_int");; - - -testing_function "is_int_big_int";; - -test 1 -eq (is_int_big_int (big_int_of_int 1), true);; -test 2 -eq (is_int_big_int (big_int_of_int (-1)), true);; -test 3 -eq (is_int_big_int (succ_big_int (big_int_of_int biggest_int)), false);; -test 4 -eq (int_of_big_int (big_int_of_int monster_int), monster_int);; -(* Should be true *) -test 5 -eq (is_int_big_int (big_int_of_string (string_of_int biggest_int)), true);; -test 6 -eq (is_int_big_int (big_int_of_string (string_of_int least_int)), true);; -test 7 -eq (is_int_big_int (big_int_of_string (string_of_int monster_int)), true);; - -(* Should be false *) -(* Successor of biggest_int is not an int *) -test 8 -eq (is_int_big_int (succ_big_int (big_int_of_int (biggest_int))), false);; -test 9 -eq (is_int_big_int - (succ_big_int (succ_big_int (big_int_of_int (biggest_int)))), false);; -(* Negation of monster_int (as a big_int) is not an int *) -test 10 -eq (is_int_big_int - (minus_big_int (big_int_of_string (string_of_int monster_int))), false);; - - -testing_function "sys_string_of_big_int";; - -test 1 -eq_string (string_of_big_int (big_int_of_int 1), "1");; - - -testing_function "big_int_of_string";; - -test 1 -eq_big_int (big_int_of_string "1", big_int_of_int 1);; -test 2 -eq_big_int (big_int_of_string "-1", big_int_of_int (-1));; -test 4 -eq_big_int (big_int_of_string "0", zero_big_int);; - -failwith_test 5 big_int_of_string "sdjdkfighdgf" - (Failure "invalid digit");; - -test 6 -eq_big_int (big_int_of_string "123", big_int_of_int 123);; -test 7 -eq_big_int (big_int_of_string "+3456", big_int_of_int 3456);; - -test 9 -eq_big_int (big_int_of_string "-3456", big_int_of_int (-3456));; - - -let implode = List.fold_left (^) "";; (* To hell with efficiency *) - -let l = rev [ -"174679877494298468451661416292903906557638850173895426081611831060970135303"; -"044177587617233125776581034213405720474892937404345377707655788096850784519"; -"539374048533324740018513057210881137248587265169064879918339714405948322501"; -"445922724181830422326068913963858377101914542266807281471620827145038901025"; -"322784396182858865537924078131032036927586614781817695777639491934361211399"; -"888524140253852859555118862284235219972858420374290985423899099648066366558"; -"238523612660414395240146528009203942793935957539186742012316630755300111472"; -"852707974927265572257203394961525316215198438466177260614187266288417996647"; -"132974072337956513457924431633191471716899014677585762010115338540738783163"; -"739223806648361958204720897858193606022290696766988489073354139289154127309"; -"916985231051926209439373780384293513938376175026016587144157313996556653811"; -"793187841050456120649717382553450099049321059330947779485538381272648295449"; -"847188233356805715432460040567660999184007627415398722991790542115164516290"; -"619821378529926683447345857832940144982437162642295073360087284113248737998"; -"046564369129742074737760485635495880623324782103052289938185453627547195245"; -"688272436219215066430533447287305048225780425168823659431607654712261368560"; -"702129351210471250717394128044019490336608558608922841794819375031757643448"; -"32" -] in - -let bi1 = big_int_of_string (implode (rev l)) in - -let bi2 = big_int_of_string (implode (rev ("3" :: tl l))) in - -test 10 -eq_big_int (bi1, (add_big_int (mult_big_int bi2 (big_int_of_string "10")) - (big_int_of_string "2"))) -(* test 11 - && -eq_big_int (bi1, (add_big_int (mult_big_int bi2 (big_int_of_string "10e0")) - (big_int_of_string "20e-1"))) && -test 12 -eq_big_int (minus_big_int bi1, - (add_big_int (mult_big_int bi2 (big_int_of_string "-10e0")) - (big_int_of_string "-20e-1"))) && -test 13 -eq_big_int (bi1, (add_big_int (mult_big_int bi2 (big_int_of_string "+10e0")) - (big_int_of_string "+20e-1"))) && -test 14 -eq_big_int (minus_big_int bi1, - (add_big_int (mult_big_int bi2 (big_int_of_string "-10e+0")) - (big_int_of_string "-20e-1"))) && -test 15 -eq_big_int (minus_big_int bi1, - (add_big_int (mult_big_int bi2 (big_int_of_string "-1e+1")) - (big_int_of_string "-2e-0"))) && -test 16 -eq_big_int (minus_big_int bi1, - (add_big_int (mult_big_int bi2 (big_int_of_string "-0.1e+2")) - (big_int_of_string "-2.0e-0"))) && -test 17 -eq_big_int (minus_big_int bi1, - (add_big_int (mult_big_int bi2 (big_int_of_string "-1.000e+1")) - (big_int_of_string "-0.02e2")))*) -;; - -test 18 -eq_big_int (big_int_of_string "0xAbC", big_int_of_int 0xABC);; - -test 19 -eq_big_int (big_int_of_string "-0o452", big_int_of_int (-0o452));; - -test 20 -eq_big_int (big_int_of_string "0B110101", big_int_of_int 53);; - -test 21 -eq_big_int (big_int_of_string "0b11_01_01", big_int_of_int 53);; - -testing_function "power_base_int";; - -test 1 -eq_big_int (big_int_of_nat (power_base_int 10 0), unit_big_int) -;; -test 2 -eq_big_int (big_int_of_nat (power_base_int 10 8), big_int_of_int 100000000) -;; -test 3 -eq_big_int (big_int_of_nat (power_base_int 2 (length_of_int + 2)), - big_int_of_nat (let nat = make_nat 2 in - set_digit_nat nat 1 1; - nat)) -;; - -testing_function "base_power_big_int";; - -test 1 -eq_big_int (base_power_big_int 10 0 (big_int_of_int 2), big_int_of_int 2);; -test 2 -eq_big_int (base_power_big_int 10 2 (big_int_of_int 2), big_int_of_int 200);; -test 3 -eq_big_int (base_power_big_int 10 1 (big_int_of_int 123), big_int_of_int 1230) -;; - -testing_function "power_int_positive_big_int";; - -test 1 -eq_big_int (power_int_positive_big_int 2 (big_int_of_int 10), - big_int_of_int 1024);; -test 2 -eq_big_int - (power_int_positive_big_int 2 (big_int_of_int 65), - big_int_of_string "36893488147419103232");; - -test 3 -eq_big_int - (power_int_positive_big_int 3 (big_int_of_string "47"), - big_int_of_string "26588814358957503287787");; - -test 4 -eq_big_int - (power_int_positive_big_int 1 (big_int_of_string "1000000000000000000000"), - big_int_of_int 1);; - -test 5 -eq_big_int - (power_int_positive_big_int (-1) (big_int_of_string "1000000000000000000000"), - big_int_of_int 1);; - -test 6 -eq_big_int - (power_int_positive_big_int (-1) (big_int_of_string "1000000000000000000001"), - big_int_of_int (-1));; - -test 7 -eq_big_int - (power_int_positive_big_int 0 (big_int_of_string "1000000000000000000000"), - big_int_of_int 0);; - -testing_function "power_big_int_positive_int";; - -test 1 -eq_big_int (power_big_int_positive_int (big_int_of_int 2) 10, - big_int_of_int 1024);; -test 2 -eq_big_int - (power_big_int_positive_int (big_int_of_int 100) 20, - big_int_of_string "10000000000000000000000000000000000000000");; - -test 3 -eq_big_int - (power_big_int_positive_int (big_int_of_string "3") 47, - big_int_of_string "26588814358957503287787");; - -test 4 -eq_big_int - (power_big_int_positive_int (big_int_of_string "200000000000000") 34, - big_int_of_string -"17179869184000000000000000000000000000000000000000000000000000000000\ -00000000000000000000000000000000000000000000000000000000000000000000\ -00000000000000000000000000000000000000000000000000000000000000000000\ -00000000000000000000000000000000000000000000000000000000000000000000\ -00000000000000000000000000000000000000000000000000000000000000000000\ -00000000000000000000000000000000000000000000000000000000000000000000\ -00000000000000000000000000000000000000000000000000000000000000000000\ -00000000000");; - -test 5 -eq_big_int - (power_big_int_positive_int (big_int_of_string "2197609328765") 243, - big_int_of_string -"12415638672345366257764851943822299490113545698929764576040102857365\ -27920436565335427676982530274588056944387957287793378051852205028658\ -73008292720317554332284838709453634119919368441951233982592586680844\ -20765201140575612595182857026804842796931784944918059630667794516774\ -58498235838834599150657873894983300999081942159304585449505963892008\ -97855706440206825609657816209327492197604711437269361628626691080334\ -38432768885637928268354258860147333786379766583179851226375449161073\ -10396958979998161989562418169797611757651190037273397850239552735199\ -63719988832594486235837899145390948533078339399890545062510060406048\ -61331200657727576638170520036143007285549092686618686739320973444703\ -33342725604091818763255601206325426337211467746377586080108631634250\ -11232258578207762608797108802386708549785680783113606089879687396654\ -54004281165259352412815385041917713969718327109245777066079665194617\ -29230093411050053217775067781725651590160086483960457766025246936489\ -92234225900994076609973190516835778346886551506344097474301175288686\ -25662752919718480402972207084177612056491949911377568680526080633587\ -33230060757162252611388973328501680433819585006035301408574879645573\ -47126018243568976860515247053858204554293343161581801846081341003624\ -22906934772131205632200433218165757307182816260714026614324014553342\ -77303133877636489457498062819003614421295692889321460150481573909330\ -77301946991278225819671075907191359721824291923283322225480199446258\ -03302645587072103949599624444368321734975586414930425964782010567575\ -43333331963876294983400462908871215572514487548352925949663431718284\ -14589547315559936497408670231851521193150991888789948397029796279240\ -53117024758684807981605608837291399377902947471927467827290844733264\ -70881963357258978768427852958888430774360783419404195056122644913454\ -24537375432013012467418602205343636983874410969339344956536142566292\ -67710105053213729008973121773436382170956191942409859915563249876601\ -97309463059908818473774872128141896864070835259683384180928526600888\ -17480854811931632353621014638284918544379784608050029606475137979896\ -79160729736625134310450643341951675749112836007180865039256361941093\ -99844921135320096085772541537129637055451495234892640418746420370197\ -76655592198723057553855194566534999101921182723711243608938705766658\ -35660299983828999383637476407321955462859142012030390036241831962713\ -40429407146441598507165243069127531565881439971034178400174881243483\ -00001434950666035560134867554719667076133414445044258086968145695386\ -00575860256380332451841441394317283433596457253185221717167880159573\ -60478649571700878049257386910142909926740023800166057094445463624601\ -79490246367497489548435683835329410376623483996271147060314994344869\ -89606855219181727424853876740423210027967733989284801813769926906846\ -45570461348452758744643550541290031199432061998646306091218518879810\ -17848488755494879341886158379140088252013009193050706458824793551984\ -39285914868159111542391208521561221610797141925061986437418522494485\ -59871215531081904861310222368465288125816137210222223075106739997863\ -76953125");; - -testing_function "power_big_int_positive_big_int";; - -test 1 -eq_big_int - (power_big_int_positive_big_int (big_int_of_int 2) (big_int_of_int 10), - big_int_of_int 1024);; - -test 2 -eq_big_int - (power_big_int_positive_big_int (big_int_of_int 2) (big_int_of_int 65), - big_int_of_string "36893488147419103232");; - -test 3 -eq_big_int - (power_big_int_positive_big_int - (big_int_of_string "3") (big_int_of_string "47"), - big_int_of_string "26588814358957503287787");; - -test 4 -eq_big_int - (power_big_int_positive_big_int - (big_int_of_string "200000000000000") (big_int_of_int 34), - big_int_of_string -"17179869184000000000000000000000000000000000000000000000000000000000\ -00000000000000000000000000000000000000000000000000000000000000000000\ -00000000000000000000000000000000000000000000000000000000000000000000\ -00000000000000000000000000000000000000000000000000000000000000000000\ -00000000000000000000000000000000000000000000000000000000000000000000\ -00000000000000000000000000000000000000000000000000000000000000000000\ -00000000000000000000000000000000000000000000000000000000000000000000\ -00000000000");; - -test 5 -eq_big_int - (power_big_int_positive_big_int (big_int_of_string "2197609328765") - (big_int_of_string "243"), - big_int_of_string -"12415638672345366257764851943822299490113545698929764576040102857365\ -27920436565335427676982530274588056944387957287793378051852205028658\ -73008292720317554332284838709453634119919368441951233982592586680844\ -20765201140575612595182857026804842796931784944918059630667794516774\ -58498235838834599150657873894983300999081942159304585449505963892008\ -97855706440206825609657816209327492197604711437269361628626691080334\ -38432768885637928268354258860147333786379766583179851226375449161073\ -10396958979998161989562418169797611757651190037273397850239552735199\ -63719988832594486235837899145390948533078339399890545062510060406048\ -61331200657727576638170520036143007285549092686618686739320973444703\ -33342725604091818763255601206325426337211467746377586080108631634250\ -11232258578207762608797108802386708549785680783113606089879687396654\ -54004281165259352412815385041917713969718327109245777066079665194617\ -29230093411050053217775067781725651590160086483960457766025246936489\ -92234225900994076609973190516835778346886551506344097474301175288686\ -25662752919718480402972207084177612056491949911377568680526080633587\ -33230060757162252611388973328501680433819585006035301408574879645573\ -47126018243568976860515247053858204554293343161581801846081341003624\ -22906934772131205632200433218165757307182816260714026614324014553342\ -77303133877636489457498062819003614421295692889321460150481573909330\ -77301946991278225819671075907191359721824291923283322225480199446258\ -03302645587072103949599624444368321734975586414930425964782010567575\ -43333331963876294983400462908871215572514487548352925949663431718284\ -14589547315559936497408670231851521193150991888789948397029796279240\ -53117024758684807981605608837291399377902947471927467827290844733264\ -70881963357258978768427852958888430774360783419404195056122644913454\ -24537375432013012467418602205343636983874410969339344956536142566292\ -67710105053213729008973121773436382170956191942409859915563249876601\ -97309463059908818473774872128141896864070835259683384180928526600888\ -17480854811931632353621014638284918544379784608050029606475137979896\ -79160729736625134310450643341951675749112836007180865039256361941093\ -99844921135320096085772541537129637055451495234892640418746420370197\ -76655592198723057553855194566534999101921182723711243608938705766658\ -35660299983828999383637476407321955462859142012030390036241831962713\ -40429407146441598507165243069127531565881439971034178400174881243483\ -00001434950666035560134867554719667076133414445044258086968145695386\ -00575860256380332451841441394317283433596457253185221717167880159573\ -60478649571700878049257386910142909926740023800166057094445463624601\ -79490246367497489548435683835329410376623483996271147060314994344869\ -89606855219181727424853876740423210027967733989284801813769926906846\ -45570461348452758744643550541290031199432061998646306091218518879810\ -17848488755494879341886158379140088252013009193050706458824793551984\ -39285914868159111542391208521561221610797141925061986437418522494485\ -59871215531081904861310222368465288125816137210222223075106739997863\ -76953125");; - -test 6 -eq_big_int - (power_big_int_positive_big_int (big_int_of_int 1) - (big_int_of_string "1000000000000000000000"), - big_int_of_int 1);; - -test 7 -eq_big_int - (power_big_int_positive_big_int (big_int_of_int (-1)) - (big_int_of_string "1000000000000000000000"), - big_int_of_int 1);; - -test 8 -eq_big_int - (power_big_int_positive_big_int (big_int_of_int (-1)) - (big_int_of_string "1000000000000000000001"), - big_int_of_int (-1));; - -test 9 -eq_big_int - (power_big_int_positive_big_int (big_int_of_int 0) - (big_int_of_string "1000000000000000000000"), - big_int_of_int 0);; - -testing_function "square_big_int";; - -test 1 eq_big_int - (square_big_int (big_int_of_string "0"), big_int_of_string "0");; -test 2 eq_big_int - (square_big_int (big_int_of_string "1"), big_int_of_string "1");; -test 3 eq_big_int - (square_big_int (big_int_of_string "-1"), big_int_of_string "1");; -test 4 eq_big_int - (square_big_int (big_int_of_string "-7"), big_int_of_string "49");; - - -testing_function "big_int_of_nativeint";; - -test 1 eq_big_int - (big_int_of_nativeint 0n, zero_big_int);; -test 2 eq_big_int - (big_int_of_nativeint 1234n, big_int_of_string "1234");; -test 3 eq_big_int - (big_int_of_nativeint (-1234n), big_int_of_string "-1234");; - -testing_function "nativeint_of_big_int";; - -test 1 eq_nativeint - (nativeint_of_big_int zero_big_int, 0n);; -test 2 eq_nativeint - (nativeint_of_big_int (big_int_of_string "1234"), 1234n);; -test 2 eq_nativeint - (nativeint_of_big_int (big_int_of_string "-1234"), -1234n);; - -testing_function "big_int_of_int32";; - -test 1 eq_big_int - (big_int_of_int32 0l, zero_big_int);; -test 2 eq_big_int - (big_int_of_int32 2147483647l, big_int_of_string "2147483647");; -test 3 eq_big_int - (big_int_of_int32 (-2147483648l), big_int_of_string "-2147483648");; - -testing_function "int32_of_big_int";; - -test 1 eq_int32 - (int32_of_big_int zero_big_int, 0l);; -test 2 eq_int32 - (int32_of_big_int (big_int_of_string "2147483647"), 2147483647l);; -test 3 eq_int32 - (int32_of_big_int (big_int_of_string "-2147483648"), -2147483648l);; -test 4 eq_int32 - (int32_of_big_int (big_int_of_string "-2147"), -2147l);; -let should_fail s = - try ignore (int32_of_big_int (big_int_of_string s)); 0 - with Failure _ -> 1;; -test 5 eq_int - (should_fail "2147483648", 1);; -test 6 eq_int - (should_fail "-2147483649", 1);; -test 7 eq_int - (should_fail "4294967296", 1);; -test 8 eq_int - (should_fail "18446744073709551616", 1);; - -testing_function "big_int_of_int64";; - -test 1 eq_big_int - (big_int_of_int64 0L, zero_big_int);; -test 2 eq_big_int - (big_int_of_int64 9223372036854775807L, - big_int_of_string "9223372036854775807");; -test 3 eq_big_int - (big_int_of_int64 (-9223372036854775808L), - big_int_of_string "-9223372036854775808");; -test 4 eq_big_int (*PR#4792*) - (big_int_of_int64 (Int64.of_int32 Int32.min_int), - big_int_of_string "-2147483648");; -test 5 eq_big_int - (big_int_of_int64 1234L, big_int_of_string "1234");; -test 6 eq_big_int - (big_int_of_int64 0x1234567890ABCDEFL, - big_int_of_string "1311768467294899695");; -test 7 eq_big_int - (big_int_of_int64 (-1234L), big_int_of_string "-1234");; -test 8 eq_big_int - (big_int_of_int64 (-0x1234567890ABCDEFL), - big_int_of_string "-1311768467294899695");; - -testing_function "int64_of_big_int";; - -test 1 eq_int64 - (int64_of_big_int zero_big_int, 0L);; -test 2 eq_int64 - (int64_of_big_int (big_int_of_string "9223372036854775807"), - 9223372036854775807L);; -test 3 eq_int64 - (int64_of_big_int (big_int_of_string "-9223372036854775808"), - -9223372036854775808L);; -test 4 eq_int64 - (int64_of_big_int (big_int_of_string "-9223372036854775"), - -9223372036854775L);; -test 5 eq_int64 (* PR#4804 *) - (int64_of_big_int (big_int_of_string "2147483648"), 2147483648L);; -let should_fail s = - try ignore (int64_of_big_int (big_int_of_string s)); 0 - with Failure _ -> 1;; -test 6 eq_int - (should_fail "9223372036854775808", 1);; -test 7 eq_int - (should_fail "-9223372036854775809", 1);; -test 8 eq_int - (should_fail "18446744073709551616", 1);; - -(* build a 128-bit big int from two int64 *) - -let big_int_128 hi lo = - add_big_int (mult_big_int (big_int_of_int64 hi) - (big_int_of_string "18446744073709551616")) - (big_int_of_int64 lo);; -let h1 = 0x7fd05b7ee46a29f8L -and h2 = 0x64b28b8ee70b6e6dL -and h3 = 0x58546e563f5b44f0L -and h4 = 0x1db72f6377ff3ec6L -and h5 = 0x4f9bb0a19c543cb1L;; - -testing_function "and_big_int";; - -test 1 eq_big_int - (and_big_int unit_big_int zero_big_int, zero_big_int);; -test 2 eq_big_int - (and_big_int zero_big_int unit_big_int, zero_big_int);; -test 3 eq_big_int - (and_big_int unit_big_int unit_big_int, unit_big_int);; -test 4 eq_big_int - (and_big_int (big_int_128 h1 h2) (big_int_128 h3 h4), - big_int_128 (Int64.logand h1 h3) (Int64.logand h2 h4));; -test 5 eq_big_int - (and_big_int (big_int_128 h1 h2) (big_int_of_int64 h5), - big_int_of_int64 (Int64.logand h2 h5));; -test 6 eq_big_int - (and_big_int (big_int_of_int64 h5) (big_int_128 h3 h4) , - big_int_of_int64 (Int64.logand h5 h4));; - -testing_function "or_big_int";; - -test 1 eq_big_int - (or_big_int unit_big_int zero_big_int, unit_big_int);; -test 2 eq_big_int - (or_big_int zero_big_int unit_big_int, unit_big_int);; -test 3 eq_big_int - (or_big_int unit_big_int unit_big_int, unit_big_int);; -test 4 eq_big_int - (or_big_int (big_int_128 h1 h2) (big_int_128 h3 h4), - big_int_128 (Int64.logor h1 h3) (Int64.logor h2 h4));; -test 5 eq_big_int - (or_big_int (big_int_128 h1 h2) (big_int_of_int64 h5), - big_int_128 h1 (Int64.logor h2 h5));; -test 6 eq_big_int - (or_big_int (big_int_of_int64 h5) (big_int_128 h3 h4) , - big_int_128 h3 (Int64.logor h5 h4));; - -testing_function "xor_big_int";; - -test 1 eq_big_int - (xor_big_int unit_big_int zero_big_int, unit_big_int);; -test 2 eq_big_int - (xor_big_int zero_big_int unit_big_int, unit_big_int);; -test 3 eq_big_int - (xor_big_int unit_big_int unit_big_int, zero_big_int);; -test 4 eq_big_int - (xor_big_int (big_int_128 h1 h2) (big_int_128 h3 h4), - big_int_128 (Int64.logxor h1 h3) (Int64.logxor h2 h4));; -test 5 eq_big_int - (xor_big_int (big_int_128 h1 h2) (big_int_of_int64 h5), - big_int_128 h1 (Int64.logxor h2 h5));; -test 6 eq_big_int - (xor_big_int (big_int_of_int64 h5) (big_int_128 h3 h4) , - big_int_128 h3 (Int64.logxor h5 h4));; - -testing_function "shift_left_big_int";; - -test 1 eq_big_int - (shift_left_big_int unit_big_int 0, - unit_big_int);; -test 2 eq_big_int - (shift_left_big_int unit_big_int 1, - big_int_of_int 2);; -test 2 eq_big_int - (shift_left_big_int unit_big_int 31, - big_int_of_string "2147483648");; -test 3 eq_big_int - (shift_left_big_int unit_big_int 64, - big_int_of_string "18446744073709551616");; -test 4 eq_big_int - (shift_left_big_int unit_big_int 95, - big_int_of_string "39614081257132168796771975168");; -test 5 eq_big_int - (shift_left_big_int (big_int_of_string "39614081257132168796771975168") 67, - big_int_of_string "5846006549323611672814739330865132078623730171904");; -test 6 eq_big_int - (shift_left_big_int (big_int_of_string "-39614081257132168796771975168") 67, - big_int_of_string "-5846006549323611672814739330865132078623730171904");; - -testing_function "shift_right_big_int";; - -test 1 eq_big_int - (shift_right_big_int unit_big_int 0, - unit_big_int);; -test 2 eq_big_int - (shift_right_big_int (big_int_of_int 12345678) 3, - big_int_of_int 1543209);; -test 3 eq_big_int - (shift_right_big_int (big_int_of_string "5299989648942") 32, - big_int_of_int 1234);; -test 4 eq_big_int - (shift_right_big_int (big_int_of_string - "5846006549323611672814739330865132078623730171904") - 67, - big_int_of_string "39614081257132168796771975168");; -test 5 eq_big_int - (shift_right_big_int (big_int_of_string "-5299989648942") 32, - big_int_of_int (-1235));; -test 6 eq_big_int - (shift_right_big_int (big_int_of_string "-16570089876543209725755392") 27, - big_int_of_string "-123456790123456789");; - -testing_function "shift_right_towards_zero_big_int";; - -test 1 eq_big_int - (shift_right_towards_zero_big_int (big_int_of_string "-5299989648942") 32, - big_int_of_int (-1234));; -test 2 eq_big_int - (shift_right_towards_zero_big_int (big_int_of_string - "-16570089876543209725755392") - 27, - big_int_of_string "-123456790123456789");; - -testing_function "extract_big_int";; - -test 1 eq_big_int - (extract_big_int (big_int_of_int64 0x123456789ABCDEFL) 3 13, - big_int_of_int 6589);; -test 2 eq_big_int - (extract_big_int (big_int_128 h1 h2) 67 12, - big_int_of_int 1343);; -test 3 eq_big_int - (extract_big_int (big_int_of_string "-1844674407370955178") 37 9, - big_int_of_int 307);; -test 4 eq_big_int - (extract_big_int unit_big_int 2048 254, - zero_big_int);; -test 5 eq_big_int - (extract_big_int (big_int_of_int64 0x123456789ABCDEFL) 0 32, - big_int_of_int64 2309737967L);; -test 6 eq_big_int - (extract_big_int (big_int_of_int (-1)) 0 16, - big_int_of_int 0xFFFF);; -test 7 eq_big_int - (extract_big_int (big_int_of_int (-1)) 1027 12, - big_int_of_int 0xFFF);; -test 8 eq_big_int - (extract_big_int (big_int_of_int (-1234567)) 0 16, - big_int_of_int 10617);; -test 9 eq_big_int - (extract_big_int (minus_big_int (power_int_positive_int 2 64)) 64 20, - big_int_of_int 0xFFFFF);; -test 10 eq_big_int - (extract_big_int (pred_big_int (minus_big_int (power_int_positive_int 2 64))) - 64 20, - big_int_of_int 0xFFFFE);; - -testing_function "hashing of big integers";; - -test 1 eq_int (Hashtbl.hash zero_big_int, - 955772237);; -test 2 eq_int (Hashtbl.hash unit_big_int, - 992063522);; -test 3 eq_int (Hashtbl.hash (minus_big_int unit_big_int), - 161678167);; -test 4 eq_int (Hashtbl.hash (big_int_of_string "123456789123456789"), - 755417385);; -test 5 eq_int (Hashtbl.hash (sub_big_int - (big_int_of_string "123456789123456789") - (big_int_of_string "123456789123456789")), - 955772237);; -test 6 eq_int (Hashtbl.hash (sub_big_int - (big_int_of_string "123456789123456789") - (big_int_of_string "123456789123456788")), - 992063522);; - -testing_function "float_of_big_int";; - -test 1 eq_float (float_of_big_int zero_big_int, 0.0);; -test 2 eq_float (float_of_big_int unit_big_int, 1.0);; -test 3 eq_float (float_of_big_int (minus_big_int unit_big_int), -1.0);; -test 4 eq_float (float_of_big_int (shift_left_big_int unit_big_int 1024), - infinity);; -test 5 eq_float (float_of_big_int (shift_left_big_int unit_big_int 1023), - ldexp 1.0 1023);; -(* Some random int64 values *) -let ok = ref true in -for i = 1 to 100 do - let n = Random.int64 Int64.max_int in - if not (eq_float (float_of_big_int (big_int_of_int64 n)) (Int64.to_float n)) - then ok := false; - let n = Int64.neg n in - if not (eq_float (float_of_big_int (big_int_of_int64 n)) (Int64.to_float n)) - then ok := false -done; -test 6 eq (!ok, true);; -(* Some random int64 values scaled by some random power of 2 *) -let ok = ref true in -for i = 1 to 1000 do - let n = Random.int64 Int64.max_int in - let exp = Random.int 1200 in - if not (eq_float - (float_of_big_int - (shift_left_big_int (big_int_of_int64 n) exp)) - (ldexp (Int64.to_float n) exp)) - then ok := false; - let n = Int64.neg n in - if not (eq_float - (float_of_big_int - (shift_left_big_int (big_int_of_int64 n) exp)) - (ldexp (Int64.to_float n) exp)) - then ok := false -done; -test 7 eq (!ok, true);; -(* Round to nearest even *) -let ok = ref true in -for i = 0 to 15 do - let n = Int64.(add 0xfffffffffffff0L (of_int i)) in - if not (eq_float - (float_of_big_int - (shift_left_big_int (big_int_of_int64 n) 32)) - (ldexp (Int64.to_float n) 32)) - then ok := false -done; -test 8 eq (!ok, true);; diff --git a/testsuite/tests/lib-num/test_io.ml b/testsuite/tests/lib-num/test_io.ml deleted file mode 100644 index 1df11a5fe6..0000000000 --- a/testsuite/tests/lib-num/test_io.ml +++ /dev/null @@ -1,64 +0,0 @@ -open Test -open Nat -open Big_int -open Num - -let intern_extern obj = - let f = Filename.temp_file "testnum" ".data" in - let oc = open_out_bin f in - output_value oc obj; - close_out oc; - let ic = open_in_bin f in - let res = input_value ic in - close_in ic; - Sys.remove f; - res -;; - -testing_function "output_value/input_value on nats";; - -let equal_nat n1 n2 = - eq_nat n1 0 (length_nat n1) n2 0 (length_nat n2) -;; - -List.iter - (fun (i, s) -> - let n = nat_of_string s in - ignore(test i equal_nat (n, intern_extern n))) - [1, "0"; - 2, "1234"; - 3, "8589934592"; - 4, "340282366920938463463374607431768211455"; - 5, String.make 100 '3'; - 6, String.make 1000 '9'; - 7, String.make 20000 '8'] -;; - -testing_function "output_value/input_value on big ints";; - -List.iter - (fun (i, s) -> - let b = big_int_of_string s in - ignore(test i eq_big_int (b, intern_extern b))) - [1, "0"; - 2, "1234"; - 3, "-1234"; - 4, "1040259735709286400"; - 5, "-" ^ String.make 20000 '7'] -;; - -testing_function "output_value/input_value on nums";; - -List.iter - (fun (i, s) -> - let n = num_of_string s in - ignore(test i eq_num (n, intern_extern n))) - [1, "0"; - 2, "1234"; - 3, "-1234"; - 4, "159873568791325097646845892426782"; - 5, "1/4"; - 6, "-15/2"; - 7, "159873568791325097646845892426782/24098772507410987265987"; - 8, String.make 10000 '3' ^ "/" ^ String.make 5000 '7'] -;; diff --git a/testsuite/tests/lib-num/test_nats.ml b/testsuite/tests/lib-num/test_nats.ml deleted file mode 100644 index 74ce5ecd1c..0000000000 --- a/testsuite/tests/lib-num/test_nats.ml +++ /dev/null @@ -1,148 +0,0 @@ -open Test;; -open Nat;; - -(* Can compare nats less than 2**32 *) -let equal_nat n1 n2 = - eq_nat n1 0 (num_digits_nat n1 0 1) - n2 0 (num_digits_nat n2 0 1);; - -testing_function "num_digits_nat";; - -test (-1) eq (false,not true);; -test 0 eq (true,not false);; - -test 1 -eq_int -(let r = make_nat 2 in - set_digit_nat r 1 1; - num_digits_nat r 0 1,1);; - -testing_function "length_nat";; - -test 1 -eq_int -(let r = make_nat 2 in - set_digit_nat r 0 1; - length_nat r,2);; - -testing_function "equal_nat";; - -let zero_nat = make_nat 1 in - -test 1 -equal_nat (zero_nat,zero_nat);; -test 2 -equal_nat (nat_of_int 1,nat_of_int 1);; - -test 3 -equal_nat (nat_of_string "2",nat_of_string "2");; -test 4 -eq (equal_nat (nat_of_string "2")(nat_of_string "3"),false);; - -testing_function "incr_nat";; - -let zero = nat_of_int 0 in -let res = incr_nat zero 0 1 1 in - test 1 - equal_nat (zero, nat_of_int 1) && - test 2 - eq (res,0);; - -let n = nat_of_int 1 in -let res = incr_nat n 0 1 1 in - test 3 - equal_nat (n, nat_of_int 2) && - test 4 - eq (res,0);; - - -testing_function "decr_nat";; - -let n = nat_of_int 1 in -let res = decr_nat n 0 1 0 in - test 1 - equal_nat (n, nat_of_int 0) && - test 2 - eq (res,1);; - -let n = nat_of_int 2 in -let res = decr_nat n 0 1 0 in - test 3 - equal_nat (n, nat_of_int 1) && - test 4 - eq (res,1);; - -testing_function "is_zero_nat";; - -let n = nat_of_int 1 in -test 1 eq (is_zero_nat n 0 1,false) && -test 2 eq (is_zero_nat (make_nat 1) 0 1, true) && -test 3 eq (is_zero_nat (make_nat 2) 0 2, true) && -(let r = make_nat 2 in - set_digit_nat r 1 1; - test 4 eq (is_zero_nat r 0 1, true)) -;; - -testing_function "string_of_nat";; - -let n = make_nat 4;; - -test 1 eq_string (string_of_nat n, "0");; - -complement_nat n 0 (if sixtyfour then 2 else 4);; - -test 2 eq_string (string_of_nat n, "340282366920938463463374607431768211455");; - -testing_function "string_of_nat && nat_of_string";; - -for i = 1 to 20 do - let s = String.init i (function 0 -> '1' | _ -> '0') in - ignore (test i eq_string (string_of_nat (nat_of_string s), s)) -done;; - -let set_mult_digit_nat n1 d1 l1 n2 d2 l2 n3 d3 = - ignore (mult_digit_nat n1 d1 l1 n2 d2 l2 n3 d3) -;; - -let s = - "33333333333333333333333333333333333333333333333333333333333333333333\ - 33333333333333333333333333333333333333333333333333333333333333333333" -in -test 21 equal_nat ( -nat_of_string s, -(let nat = make_nat 15 in - set_digit_nat nat 0 3; - set_mult_digit_nat nat 0 15 - (nat_of_string (String.sub s 0 135)) 0 14 - (nat_of_int 10) 0; - nat)) -;; - -test 22 eq_string (string_of_nat(nat_of_string "1073741824"), "1073741824");; - -testing_function "gcd_nat";; - -for i = 1 to 20 do - let n1 = Random.int 1000000000 - and n2 = Random.int 100000 in - let nat1 = nat_of_int n1 - and nat2 = nat_of_int n2 in - ignore (gcd_nat nat1 0 1 nat2 0 1); - ignore (test i eq (int_of_nat nat1, gcd_int n1 n2)) -done -;; - -testing_function "sqrt_nat";; - -test 1 equal_nat (sqrt_nat (nat_of_int 1) 0 1, nat_of_int 1);; -test 2 equal_nat (let n = nat_of_string "8589934592" in - sqrt_nat n 0 (length_nat n), - nat_of_string "92681");; -test 3 equal_nat (let n = nat_of_string "4294967295" in - sqrt_nat n 0 (length_nat n), - nat_of_string "65535");; -test 4 equal_nat (let n = nat_of_string "18446744065119617025" in - sqrt_nat n 0 (length_nat n), - nat_of_string "4294967295");; -test 5 equal_nat (sqrt_nat (nat_of_int 15) 0 1, - nat_of_int 3);; diff --git a/testsuite/tests/lib-num/test_nums.ml b/testsuite/tests/lib-num/test_nums.ml deleted file mode 100644 index e6cd5c9c73..0000000000 --- a/testsuite/tests/lib-num/test_nums.ml +++ /dev/null @@ -1,234 +0,0 @@ -open Test;; -open Nat;; -open Big_int;; -open Ratio;; -open Num;; -open Arith_status;; - -testing_function "add_num";; - -test 1 -eq_num (add_num (Int 1) (Int 3), Int 4);; -test 2 -eq_num (add_num (Int 1) (Big_int (big_int_of_int 3)), Int 4);; -test 3 -eq_num (add_num (Int 1) (Ratio (ratio_of_string "3/4")), - Ratio (ratio_of_string "7/4"));; -test 4 -eq_num (add_num (Big_int (big_int_of_int 1)) (Ratio (ratio_of_string "3/4")), - Ratio (ratio_of_string "7/4"));; -test 5 -eq_num (add_num (Big_int (big_int_of_int 1)) (Big_int (big_int_of_int 3)), - Int 4);; -test 6 -eq_num (add_num (Big_int (big_int_of_int 1)) (Ratio (ratio_of_string "3/4")), - Ratio (ratio_of_string "7/4"));; -test 7 -eq_num (add_num (Ratio (ratio_of_string "2/3")) (Ratio (ratio_of_string "3/4")), - Ratio (ratio_of_string "17/12"));; -test 8 -eq_num (add_num (Int least_int) (Int 1), - Int (- (pred biggest_int)));; -test 9 -eq_num (add_num (Int biggest_int) (Int 1), - Big_int (minus_big_int (pred_big_int (big_int_of_int least_int))));; - -testing_function "sub_num";; - -test 1 -eq_num (sub_num (Int 1) (Int 3), Int (-2));; -test 2 -eq_num (sub_num (Int 1) (Big_int (big_int_of_int 3)), Int (-2));; -test 3 -eq_num (sub_num (Int 1) (Ratio (ratio_of_string "3/4")), - Ratio (ratio_of_string "1/4"));; -test 4 -eq_num (sub_num (Big_int (big_int_of_int 1)) (Ratio (ratio_of_string "3/4")), - Ratio (ratio_of_string "1/4"));; -test 5 -eq_num (sub_num (Big_int (big_int_of_int 1)) (Big_int (big_int_of_int 3)), - Int (-2));; -test 7 -eq_num (sub_num (Big_int (big_int_of_int 1)) (Ratio (ratio_of_string "3/4")), - Ratio (ratio_of_string "1/4"));; -test 8 -eq_num (sub_num (Ratio (ratio_of_string "2/3")) (Ratio (ratio_of_string "3/4")), - Ratio (ratio_of_string "-1/12"));; -test 9 -eq_num (sub_num (Int least_int) (Int (-1)), - Int (- (pred biggest_int)));; -test 10 -eq_num (sub_num (Int (-1)) (Int biggest_int), pred_num (Int least_int));; - -testing_function "mult_num";; - -test 1 -eq_num (mult_num (Int 2) (Int 3), Int 6);; -test 2 -eq_num (mult_num (Int 127) (Int (int_of_string "257")), - Int (int_of_string "32639"));; -test 3 -eq_num (mult_num (Int 257) (Int (int_of_string "260")), - Big_int (big_int_of_string "66820"));; -test 4 -eq_num (mult_num (Int 2) (Big_int (big_int_of_int 3)), Int 6);; -test 5 -eq_num (mult_num (Int 10) (Ratio (ratio_of_string "3/4")), - Ratio (ratio_of_string "15/2"));; -test 6 -eq_num (mult_num (Big_int (big_int_of_int 10)) (Ratio (ratio_of_string "3/4")), - Ratio (ratio_of_string "15/2"));; -test 7 -eq_num (mult_num (Big_int (big_int_of_int 2)) (Big_int (big_int_of_int 3)), - Int 6);; -test 8 -eq_num (mult_num (Big_int (big_int_of_int 10)) (Ratio (ratio_of_string "3/4")), - Ratio (ratio_of_string "15/2"));; -test 9 -eq_num (mult_num (Ratio (ratio_of_string "2/3")) (Ratio (ratio_of_string "3/4")) - , Ratio (ratio_of_string "1/2"));; - -testing_function "div_num";; - -test 1 -eq_num (div_num (Int 6) (Int 3), Int 2);; -test 2 -eq_num (div_num (Int (int_of_string "32639")) - (Int (int_of_string "257")), Int 127);; -test 3 -eq_num (div_num (Big_int (big_int_of_string "66820")) - (Int (int_of_string "257")), - Int 260);; -test 4 -eq_num (div_num (Int 6) (Big_int (big_int_of_int 3)), Int 2);; -test 5 -eq_num (div_num (Ratio (ratio_of_string "15/2")) - (Int 10), - Ratio (ratio_of_string "3/4"));; -test 6 -eq_num (div_num (Big_int (big_int_of_int 6)) (Big_int (big_int_of_int 3)), - Int 2);; -test 7 -eq_num (div_num (Ratio (ratio_of_string "15/2")) - (Big_int (big_int_of_int 10)), - Ratio (ratio_of_string "3/4"));; -test 8 -eq_num (div_num (Ratio (ratio_of_string "15/2")) - (Ratio (ratio_of_string "3/4")), - Big_int (big_int_of_int 10));; -test 9 -eq_num (div_num (Ratio (ratio_of_string "1/2")) - (Ratio (ratio_of_string "3/4")), - Ratio (ratio_of_string "2/3"));; - -testing_function "is_integer_num";; - -test 1 -eq (is_integer_num (Int 3),true);; -test 2 -eq (is_integer_num (Big_int (big_int_of_string "1234567890")),true);; -test 3 -eq (not (is_integer_num (Ratio (ratio_of_string "1/2"))),true);; -test 4 -eq (is_integer_num (Ratio (ratio_of_string "1073774590/32770")),true);; - -testing_function "num_of_ratio";; - -test 1 -eq_num (num_of_ratio (ratio_of_string "4/2"), Int 2);; -test 2 -eq_num (num_of_ratio (ratio_of_string "11811160075/11"), - Big_int (big_int_of_string "1073741825"));; -test 3 -eq_num (num_of_ratio (ratio_of_string "123456789012/1234"), - Ratio (ratio_of_string "61728394506/617"));; - -testing_function "num_of_string";; - -test 1 -eq_num (num_of_string "123/3456", Ratio (ratio_of_string "123/3456"));; -(********* -test 2 -eq_num (num_of_string "12.3/34.56", Ratio (ratio_of_string "1230/3456"));; -test 3 -eq_num (num_of_string "1.23/325.6", Ratio (ratio_of_string "123/32560"));; -test 4 -eq_num (num_of_string "12.3/345.6", Ratio (ratio_of_string "123/3456"));; -set_error_when_null_denominator false;; -test 5 -eq_num (num_of_string "12.3/0.0", Ratio (ratio_of_string "123/0"));; -test 6 -eq_num (num_of_string "0/0", Ratio (ratio_of_string "0/0"));; -set_error_when_null_denominator true;; -*********) -test 7 -eq_num (num_of_string "1234567890", - Big_int (big_int_of_string "1234567890"));; -test 8 -eq_num (num_of_string "12345", Int (int_of_string "12345"));; -(********* -test 9 -eq_num (num_of_string "0.23", Ratio (ratio_of_string "23/100"));; -test 10 -eq_num (num_of_string "0.23", Ratio (ratio_of_string "0.23/1"));; -********) - -failwith_test 11 -num_of_string ("frlshjkurty") (Failure "num_of_string");; - -test 12 -eq_num (num_of_string "0xAbCdEf", - Big_int (big_int_of_int 0xabcdef));; - -test 13 -eq_num (num_of_string "0b1101/0O1765", - Ratio (ratio_of_string "0b1101/0o1765"));; - -test 14 -eq_num (num_of_string "-12_34_56", - Big_int (big_int_of_int (-123456)));; - -test 15 -eq_num (num_of_string "0B101010", Big_int (big_int_of_int 42));; - -(******* - -testing_function "immediate numbers";; - -standard arith false;; - -let x = (1/2) in -test 0 eq_string (string_of_num x, "1/2");; - -let y = 12345678901 in -test 1 eq_string (string_of_num y, "12345678901");; -testing_function "immediate numbers";; - -let x = (1/2) in -test 0 eq_string (string_of_num x, "1/2");; - -let y = 12345678901 in -test 1 eq_string (string_of_num y, "12345678901");; - -testing_function "pattern_matching on nums";; - -let f1 = function 0 -> true | _ -> false;; - -test 1 eq (f1 0, true);; - -test 2 eq (f1 1, false);; - -test 3 eq (f1 (0/1), true);; - -test 4 eq (f1 (let n = num_of_string "2000000000000000000000000" in n-n) , - true);; - -test 5 eq (f1 (let n = num_of_string "2000000000000000000000000" in n/n-1) , - true);; - -test 6 eq (f1 (let n = num_of_string "2000000000000000000000000" in n+1) , - false);; - -test 7 eq (f1 (1/2), false);; - -**************) diff --git a/testsuite/tests/lib-num/test_ratios.ml b/testsuite/tests/lib-num/test_ratios.ml deleted file mode 100644 index a5d8fe5eea..0000000000 --- a/testsuite/tests/lib-num/test_ratios.ml +++ /dev/null @@ -1,1195 +0,0 @@ -open Test;; -open Nat;; -open Big_int;; -open Ratio;; -open Arith_status;; - -set_error_when_null_denominator false -;; - -let infinite_failure = "infinite or undefined rational number";; - -testing_function "create_ratio" -;; - -let r = create_ratio (big_int_of_int 1) (big_int_of_int (-2)) in -test 1 eq_big_int (numerator_ratio r, big_int_of_int (-1)) && -test 2 eq_big_int (denominator_ratio r, big_int_of_int 2) -;; - -let r = create_ratio (big_int_of_int 2) (big_int_of_int 3) in -test 3 eq_big_int (numerator_ratio r, big_int_of_int 2) && -test 4 eq_big_int (denominator_ratio r, big_int_of_int 3) -;; - -set_normalize_ratio true -;; - -let r = create_ratio (big_int_of_int 12) (big_int_of_int (-16)) in -test 5 eq_big_int (numerator_ratio r, big_int_of_int (-3)) && -test 6 eq_big_int (denominator_ratio r, big_int_of_int 4) -;; - -set_normalize_ratio false -;; - -let r = create_ratio (big_int_of_int 0) (big_int_of_int 0) in -test 7 eq_big_int (numerator_ratio r, big_int_of_int 0) && -test 8 eq_big_int (denominator_ratio r, big_int_of_int 0) -;; - -testing_function "create_normalized_ratio" -;; - -let r = create_normalized_ratio (big_int_of_int 1) (big_int_of_int (-2)) in -test 1 eq_big_int (numerator_ratio r, big_int_of_int (-1)) && -test 2 eq_big_int (denominator_ratio r, big_int_of_int 2) -;; - -let r = create_normalized_ratio (big_int_of_int 2) (big_int_of_int 3) in -test 3 eq_big_int (numerator_ratio r, big_int_of_int 2) && -test 4 eq_big_int (denominator_ratio r, big_int_of_int 3) -;; - -set_normalize_ratio true -;; - -let r = create_normalized_ratio (big_int_of_int 12) (big_int_of_int (-16)) in -test 5 eq_big_int (numerator_ratio r, big_int_of_int (-12)) && -test 6 eq_big_int (denominator_ratio r, big_int_of_int 16) -;; - -set_normalize_ratio false -;; - -let r = create_normalized_ratio (big_int_of_int 1) (big_int_of_int 0) in -test 7 eq_big_int (numerator_ratio r, big_int_of_int 1) && -test 8 eq_big_int (denominator_ratio r, big_int_of_int 0) -;; - -let r = create_normalized_ratio (big_int_of_int 0) (big_int_of_int 0) in -test 9 eq_big_int (numerator_ratio r, big_int_of_int 0) && -test 10 eq_big_int (denominator_ratio r, big_int_of_int 0) -;; - -testing_function "null_denominator" -;; - -test 1 - eq (null_denominator (create_ratio (big_int_of_int 1) (big_int_of_int (-2))), - false) -;; -test 2 eq - (null_denominator (create_ratio (big_int_of_int 1) zero_big_int),true) -;; - -(***** -testing_function "verify_null_denominator" -;; - -test 1 - eq (verify_null_denominator (ratio_of_string "0/1"), false) -;; -test 2 - eq (verify_null_denominator (ratio_of_string "0/0"), true) -;; -*****) - -testing_function "sign_ratio" -;; - -test 1 -eq_int (sign_ratio (create_ratio (big_int_of_int (-2)) (big_int_of_int (-3))), - 1) -;; -test 2 -eq_int (sign_ratio (create_ratio (big_int_of_int 2) (big_int_of_int (-3))), - (-1)) -;; -test 3 -eq_int (sign_ratio (create_ratio zero_big_int (big_int_of_int (-3))), 0) -;; - -testing_function "normalize_ratio" -;; - -let r = create_ratio (big_int_of_int 12) (big_int_of_int (-16)) in -ignore (normalize_ratio r); -test 1 eq_big_int (numerator_ratio r, big_int_of_int (-3)) && -test 2 eq_big_int (denominator_ratio r, big_int_of_int 4) -;; - -let r = create_ratio (big_int_of_int (-1)) zero_big_int in -ignore (normalize_ratio r); -test 3 eq_big_int (numerator_ratio r, big_int_of_int (-1)) && -test 4 eq_big_int (denominator_ratio r, zero_big_int) -;; - -testing_function "report_sign_ratio" -;; - -test 1 -eq_big_int (report_sign_ratio - (create_ratio (big_int_of_int 2) (big_int_of_int (-3))) - (big_int_of_int 1), - big_int_of_int (-1)) -;; -test 2 -eq_big_int (report_sign_ratio - (create_ratio (big_int_of_int 2) (big_int_of_int 3)) - (big_int_of_int 1), - big_int_of_int 1) -;; - -testing_function "is_integer_ratio" -;; - -test 1 eq - (is_integer_ratio (create_ratio (big_int_of_int 2) (big_int_of_int (-1))), - true) -;; -test 2 eq - (is_integer_ratio (create_ratio (big_int_of_int 2) (big_int_of_int 3)), - false) -;; - -testing_function "add_ratio" -;; - -let r = add_ratio (create_ratio (big_int_of_int 1) (big_int_of_int 2)) - (create_ratio (big_int_of_int 2) (big_int_of_int 3)) in -test 1 eq_big_int (numerator_ratio r, big_int_of_int 7) && -test 2 eq_big_int (denominator_ratio r, big_int_of_int 6) -;; - -let r = add_ratio (create_ratio (big_int_of_int 2) (big_int_of_int 3)) - (create_ratio (big_int_of_int 1) (big_int_of_int (-2))) in -test 3 eq_big_int (numerator_ratio r, big_int_of_int 1) && -test 4 eq_big_int (denominator_ratio r, big_int_of_int 6) -;; - -let r = add_ratio (create_ratio (big_int_of_int 2) zero_big_int) - (create_ratio (big_int_of_int 1) (big_int_of_int (-2))) in -test 5 eq_big_int (numerator_ratio r, big_int_of_int 4) && -test 6 eq_big_int (denominator_ratio r, zero_big_int) -;; - -let r = add_ratio (create_ratio (big_int_of_int 2) (big_int_of_int 3)) - (create_ratio (big_int_of_int 1) zero_big_int) in -test 7 eq_big_int (numerator_ratio r, big_int_of_int 3) && -test 8 eq_big_int (denominator_ratio r, zero_big_int) -;; - -let r = add_ratio (create_ratio (big_int_of_int 2) zero_big_int) - (create_ratio (big_int_of_int 1) zero_big_int) in -test 9 eq_big_int (numerator_ratio r, zero_big_int) && -test 10 eq_big_int (denominator_ratio r, zero_big_int) -;; - -let r = add_ratio (create_ratio (big_int_of_string "12724951") - (big_int_of_string "26542080")) - (create_ratio (big_int_of_string "-1") - (big_int_of_string "81749606400")) in -test 11 eq_big_int (numerator_ratio r, - big_int_of_string "1040259735682744320") && -test 12 eq_big_int (denominator_ratio r, - big_int_of_string "2169804593037312000") -;; - -let r1,r2 = - (create_ratio (big_int_of_string "12724951") - (big_int_of_string "26542080"), - create_ratio (big_int_of_string "-1") - (big_int_of_string "81749606400")) in - -let bi1 = mult_big_int (numerator_ratio r1) (denominator_ratio r2) -and bi2 = mult_big_int (numerator_ratio r2) (denominator_ratio r1) -in -test 1 -eq_big_int (bi1, - big_int_of_string "1040259735709286400") -&& -test 2 -eq_big_int (bi2, - big_int_of_string "-26542080") -&& test 3 -eq_big_int (mult_big_int (denominator_ratio r1) (denominator_ratio r2), - big_int_of_string "2169804593037312000") -&& test 4 -eq_big_int (add_big_int bi1 bi2, - big_int_of_string "1040259735682744320") -;; - -testing_function "sub_ratio" -;; - -let r = sub_ratio (create_ratio (big_int_of_int 2) (big_int_of_int 3)) - (create_ratio (big_int_of_int 1) (big_int_of_int 2)) in -test 1 eq_big_int (numerator_ratio r, big_int_of_int 1) && -test 2 eq_big_int (denominator_ratio r, big_int_of_int 6) -;; - -let r = sub_ratio (create_ratio (big_int_of_int 2) zero_big_int) - (create_ratio (big_int_of_int 1) (big_int_of_int (-2))) in -test 3 eq_big_int (numerator_ratio r, big_int_of_int 4) && -test 4 eq_big_int (denominator_ratio r, zero_big_int) -;; - -let r = sub_ratio (create_ratio (big_int_of_int 2) (big_int_of_int 3)) - (create_ratio (big_int_of_int 1) zero_big_int) in -test 5 eq_big_int (numerator_ratio r, big_int_of_int (-3)) && -test 6 eq_big_int (denominator_ratio r, zero_big_int) -;; - -let r = sub_ratio (create_ratio (big_int_of_int 2) zero_big_int) - (create_ratio (big_int_of_int 1) zero_big_int) in -test 7 eq_big_int (numerator_ratio r, zero_big_int) && -test 8 eq_big_int (denominator_ratio r, zero_big_int) -;; - -testing_function "mult_ratio" -;; - -let r = mult_ratio (create_ratio (big_int_of_int 2) (big_int_of_int 3)) - (create_ratio (big_int_of_int 7) (big_int_of_int 5)) in -test 1 eq_big_int (numerator_ratio r, big_int_of_int 14) && -test 2 eq_big_int (denominator_ratio r, big_int_of_int 15) -;; - -let r = mult_ratio (create_ratio (big_int_of_int 2) zero_big_int) - (create_ratio (big_int_of_int 1) (big_int_of_int (-2))) in -test 3 eq_big_int (numerator_ratio r, big_int_of_int (-2)) && -test 4 eq_big_int (denominator_ratio r, zero_big_int) -;; - -let r = mult_ratio (create_ratio (big_int_of_int 2) (big_int_of_int 3)) - (create_ratio (big_int_of_int 1) zero_big_int) in -test 5 eq_big_int (numerator_ratio r, big_int_of_int 2) && -test 6 eq_big_int (denominator_ratio r, zero_big_int) -;; - -let r = mult_ratio (create_ratio (big_int_of_int 2) zero_big_int) - (create_ratio (big_int_of_int 1) zero_big_int) in -test 7 eq_big_int (numerator_ratio r, big_int_of_int 2) && -test 8 eq_big_int (denominator_ratio r, zero_big_int) -;; - -testing_function "div_ratio" -;; - -let r = div_ratio (create_ratio (big_int_of_int 2) (big_int_of_int 3)) - (create_ratio (big_int_of_int 5) (big_int_of_int 7)) in -test 1 eq_big_int (numerator_ratio r, big_int_of_int 14) && -test 2 eq_big_int (denominator_ratio r, big_int_of_int 15) -;; - -let r = div_ratio (create_ratio (big_int_of_int 2) zero_big_int) - (create_ratio (big_int_of_int 1) (big_int_of_int (-2))) in -test 3 eq_big_int (numerator_ratio r, big_int_of_int (-4)) && -test 4 eq_big_int (denominator_ratio r, zero_big_int) -;; - -let r = div_ratio (create_ratio (big_int_of_int 2) (big_int_of_int 3)) - (create_ratio (big_int_of_int 1) zero_big_int) in -test 5 eq_big_int (numerator_ratio r, zero_big_int) && -test 6 eq_big_int (denominator_ratio r, big_int_of_int 3) -;; - -let r = div_ratio (create_ratio (big_int_of_int 2) zero_big_int) - (create_ratio (big_int_of_int 1) zero_big_int) in -test 7 eq_big_int (numerator_ratio r, zero_big_int) && -test 8 eq_big_int (denominator_ratio r, zero_big_int) -;; - -testing_function "integer_ratio" -;; - -test 1 -eq_big_int (integer_ratio - (create_ratio (big_int_of_int 5) (big_int_of_int 3)), - big_int_of_int 1) -;; -test 2 -eq_big_int (integer_ratio - (create_ratio (big_int_of_int 5) (big_int_of_int (-3))), - big_int_of_int (-1)) -;; -test 3 -eq_big_int (integer_ratio - (create_ratio (big_int_of_int 3) (big_int_of_int 2)), - big_int_of_int 1) -;; -test 4 -eq_big_int (integer_ratio - (create_ratio (big_int_of_int 3) (big_int_of_int (-2))), - big_int_of_int (-1)) -;; - -failwith_test 5 -integer_ratio (create_ratio (big_int_of_int 3) zero_big_int) -(Failure("integer_ratio "^infinite_failure)) -;; - -testing_function "floor_ratio" -;; - -test 1 -eq_big_int (floor_ratio - (create_ratio (big_int_of_int 5) (big_int_of_int 3)), - big_int_of_int 1) -;; -test 2 -eq_big_int (floor_ratio - (create_ratio (big_int_of_int 5) (big_int_of_int (-3))), - big_int_of_int (-2)) -;; -test 3 -eq_big_int (floor_ratio - (create_ratio (big_int_of_int 3) (big_int_of_int 2)), - big_int_of_int 1) -;; -test 4 -eq_big_int (floor_ratio - (create_ratio (big_int_of_int 3) (big_int_of_int (-2))), - big_int_of_int (-2)) -;; - -failwith_test 5 floor_ratio (create_ratio (big_int_of_int 3) zero_big_int) -Division_by_zero -;; - - -testing_function "round_ratio" -;; - -test 1 -eq_big_int (round_ratio - (create_ratio (big_int_of_int 5) (big_int_of_int 3)), - big_int_of_int 2) -;; -test 2 -eq_big_int (round_ratio - (create_ratio (big_int_of_int 5) (big_int_of_int (-3))), - big_int_of_int (-2)) -;; -test 3 -eq_big_int (round_ratio - (create_ratio (big_int_of_int 3) (big_int_of_int 2)), - big_int_of_int 2) -;; -test 4 -eq_big_int (round_ratio - (create_ratio (big_int_of_int 3) (big_int_of_int (-2))), - big_int_of_int (-2)) -;; - -failwith_test 5 -round_ratio (create_ratio (big_int_of_int 3) zero_big_int) -Division_by_zero -;; - - -testing_function "ceiling_ratio" -;; - -test 1 -eq_big_int (ceiling_ratio - (create_ratio (big_int_of_int 5) (big_int_of_int 3)), - big_int_of_int 2) -;; -test 2 -eq_big_int (ceiling_ratio - (create_ratio (big_int_of_int 5) (big_int_of_int (-3))), - big_int_of_int (-1)) -;; -test 3 -eq_big_int (ceiling_ratio - (create_ratio (big_int_of_int 3) (big_int_of_int 2)), - big_int_of_int 2) -;; -test 4 -eq_big_int (ceiling_ratio - (create_ratio (big_int_of_int 3) (big_int_of_int (-2))), - big_int_of_int (-1)) -;; -test 5 -eq_big_int (ceiling_ratio - (create_ratio (big_int_of_int 4) (big_int_of_int 2)), - big_int_of_int 2) -;; -failwith_test 6 -ceiling_ratio (create_ratio (big_int_of_int 3) zero_big_int) -Division_by_zero -;; - -testing_function "eq_ratio" -;; - -test 1 -eq_ratio (create_ratio (big_int_of_int 5) (big_int_of_int 3), - create_ratio (big_int_of_int (-20)) (big_int_of_int (-12))) -;; -test 2 -eq_ratio (create_ratio (big_int_of_int 1) zero_big_int, - create_ratio (big_int_of_int 2) zero_big_int) -;; - -let neq_ratio x y = not (eq_ratio x y);; - -test 3 -neq_ratio (create_ratio (big_int_of_int 1) zero_big_int, - create_ratio (big_int_of_int (-1)) zero_big_int) -;; -test 4 -neq_ratio (create_ratio (big_int_of_int 1) zero_big_int, - create_ratio zero_big_int zero_big_int) -;; -test 5 -eq_ratio (create_ratio zero_big_int zero_big_int, - create_ratio zero_big_int zero_big_int) -;; - -testing_function "compare_ratio" -;; - -test 1 -eq_int (compare_ratio (create_ratio (big_int_of_int 0) (big_int_of_int 0)) - (create_ratio (big_int_of_int 0) (big_int_of_int 0)), - 0) -;; -test 2 -eq_int (compare_ratio (create_ratio (big_int_of_int 0) (big_int_of_int 0)) - (create_ratio (big_int_of_int 1) (big_int_of_int 0)), - 0) -;; -test 3 -eq_int (compare_ratio (create_ratio (big_int_of_int 0) (big_int_of_int 0)) - (create_ratio (big_int_of_int (-1)) (big_int_of_int 0)), - 0) -;; -test 4 -eq_int (compare_ratio (create_ratio (big_int_of_int 1) (big_int_of_int 0)) - (create_ratio (big_int_of_int 0) (big_int_of_int 0)), - 0) -;; -test 5 -eq_int (compare_ratio (create_ratio (big_int_of_int (-1)) (big_int_of_int 0)) - (create_ratio (big_int_of_int 0) (big_int_of_int 0)), - 0) -;; -test 6 -eq_int (compare_ratio (create_ratio (big_int_of_int 0) (big_int_of_int 0)) - (create_ratio (big_int_of_int 5) (big_int_of_int 3)), - 0) -;; -test 7 -eq_int (compare_ratio (create_ratio (big_int_of_int 5) (big_int_of_int 3)) - (create_ratio (big_int_of_int 0) (big_int_of_int 0)), - 0) -;; -test 8 -eq_int (compare_ratio (create_ratio (big_int_of_int 0) (big_int_of_int 0)) - (create_ratio (big_int_of_int (-5)) (big_int_of_int 3)), - 0) -;; -test 9 -eq_int (compare_ratio (create_ratio (big_int_of_int (-5)) (big_int_of_int 3)) - (create_ratio (big_int_of_int 0) (big_int_of_int 0)), - 0) -;; -test 10 -eq_int (compare_ratio (create_ratio (big_int_of_int 0) (big_int_of_int 0)) - (create_ratio (big_int_of_int 0) (big_int_of_int 1)), - 0) -;; -test 11 -eq_int (compare_ratio (create_ratio (big_int_of_int 0) (big_int_of_int 1)) - (create_ratio (big_int_of_int 0) (big_int_of_int 0)), - 0) -;; -test 12 -eq_int (compare_ratio (create_ratio (big_int_of_int 1) (big_int_of_int 0)) - (create_ratio (big_int_of_int 1) (big_int_of_int 0)), - 0) -;; -test 13 -eq_int (compare_ratio (create_ratio (big_int_of_int 1) (big_int_of_int 0)) - (create_ratio (big_int_of_int 2) (big_int_of_int 0)), - 0) -;; -test 14 -eq_int (compare_ratio (create_ratio (big_int_of_int 1) (big_int_of_int 0)) - (create_ratio (big_int_of_int (-1)) (big_int_of_int 0)), - 1) -;; -test 15 -eq_int (compare_ratio (create_ratio (big_int_of_int (-1)) (big_int_of_int 0)) - (create_ratio (big_int_of_int 1) (big_int_of_int 0)), - (-1)) -;; -test 16 -eq_int (compare_ratio (create_ratio (big_int_of_int 5) (big_int_of_int 3)) - (create_ratio (big_int_of_int 1) (big_int_of_int 0)), - (-1)) -;; -test 17 -eq_int (compare_ratio (create_ratio (big_int_of_int 1) (big_int_of_int 0)) - (create_ratio (big_int_of_int 5) (big_int_of_int 3)), - 1) -;; -test 18 -eq_int (compare_ratio (create_ratio (big_int_of_int (-5)) (big_int_of_int 3)) - (create_ratio (big_int_of_int 1) (big_int_of_int 0)), - (-1)) -;; -test 19 -eq_int (compare_ratio (create_ratio (big_int_of_int 1) (big_int_of_int 0)) - (create_ratio (big_int_of_int (-5)) (big_int_of_int 3)), - 1) -;; -test 20 -eq_int (compare_ratio (create_ratio (big_int_of_int 1) (big_int_of_int 0)) - (create_ratio (big_int_of_int 0) (big_int_of_int 3)), - 1) -;; -test 21 -eq_int (compare_ratio (create_ratio (big_int_of_int (-1)) (big_int_of_int 0)) - (create_ratio (big_int_of_int (-1)) (big_int_of_int 0)), - 0) -;; -test 22 -eq_int (compare_ratio (create_ratio (big_int_of_int (-1)) (big_int_of_int 0)) - (create_ratio (big_int_of_int (-2)) (big_int_of_int 0)), - 0) -;; -test 23 -eq_int (compare_ratio (create_ratio (big_int_of_int 5) (big_int_of_int 3)) - (create_ratio (big_int_of_int (-1)) (big_int_of_int 0)), - 1) -;; -test 24 -eq_int (compare_ratio (create_ratio (big_int_of_int (-1)) (big_int_of_int 0)) - (create_ratio (big_int_of_int 5) (big_int_of_int 3)), - (-1)) -;; -test 25 -eq_int (compare_ratio (create_ratio (big_int_of_int (-5)) (big_int_of_int 3)) - (create_ratio (big_int_of_int (-1)) (big_int_of_int 0)), - 1) -;; -test 26 -eq_int (compare_ratio (create_ratio (big_int_of_int (-1)) (big_int_of_int 0)) - (create_ratio (big_int_of_int (-5)) (big_int_of_int 3)), - (-1)) -;; -test 27 -eq_int (compare_ratio (create_ratio (big_int_of_int (-1)) (big_int_of_int 0)) - (create_ratio (big_int_of_int 0) (big_int_of_int 3)), - (-1)) -;; -test 28 -eq_int (compare_ratio (create_ratio (big_int_of_int 5) (big_int_of_int 3)) - (create_ratio (big_int_of_int 3) (big_int_of_int 2)), - 1) -;; -test 29 -eq_int (compare_ratio (create_ratio (big_int_of_int 3) (big_int_of_int 2)) - (create_ratio (big_int_of_int 5) (big_int_of_int 3)), - (-1)) -;; -test 30 -eq_int (compare_ratio (create_ratio (big_int_of_int 5) (big_int_of_int 3)) - (create_ratio (big_int_of_int (-3)) (big_int_of_int 2)), - 1) -;; -test 31 -eq_int (compare_ratio (create_ratio (big_int_of_int (-3)) (big_int_of_int 2)) - (create_ratio (big_int_of_int 5) (big_int_of_int 3)), - (-1)) -;; -test 32 -eq_int (compare_ratio (create_ratio (big_int_of_int 3) (big_int_of_int 2)) - (create_ratio (big_int_of_int 0) (big_int_of_int 3)), - 1) -;; -test 33 -eq_int (compare_ratio (create_ratio (big_int_of_int 0) (big_int_of_int 2)) - (create_ratio (big_int_of_int 5) (big_int_of_int 3)), - (-1)) -;; -test 34 -eq_int (compare_ratio (create_ratio (big_int_of_int (-3)) (big_int_of_int 2)) - (create_ratio (big_int_of_int 0) (big_int_of_int 3)), - (-1)) -;; -test 35 -eq_int (compare_ratio (create_ratio (big_int_of_int 0) (big_int_of_int 2)) - (create_ratio (big_int_of_int (-5)) (big_int_of_int 3)), - 1) -;; -test 36 -eq_int (compare_ratio (create_ratio (big_int_of_int 0) (big_int_of_int 2)) - (create_ratio (big_int_of_int 0) (big_int_of_int 3)), - 0) -;; - -testing_function "eq_big_int_ratio" -;; - -test 1 -eq_big_int_ratio (big_int_of_int 3, - (create_ratio (big_int_of_int 3) (big_int_of_int 1))) -;; -test 2 -eq -(not (eq_big_int_ratio (big_int_of_int 1) - (create_ratio (big_int_of_int 3) (big_int_of_int 1))), -true) -;; - -test 3 -eq -(not (eq_big_int_ratio (big_int_of_int 1) - (create_ratio (big_int_of_int 3) (big_int_of_int 2))), - true) -;; - -test 4 -eq -(not (eq_big_int_ratio (big_int_of_int 1) - (create_ratio (big_int_of_int 3) (big_int_of_int 0))), - true) -;; - -test 5 -eq -(not (eq_big_int_ratio (big_int_of_int 1) - (create_ratio (big_int_of_int (-3)) (big_int_of_int 2))), - true) -;; - -testing_function "compare_big_int_ratio" -;; - -test 1 -eq_int (compare_big_int_ratio - (big_int_of_int 1) - (create_ratio (big_int_of_int 3) (big_int_of_int 0)), (-1)) -;; -test 2 -eq_int (compare_big_int_ratio - (big_int_of_int 1) - (create_ratio (big_int_of_int 0) (big_int_of_int 0)), 0) -;; -test 3 -eq_int (compare_big_int_ratio - (big_int_of_int 1) - (create_ratio (big_int_of_int (-3)) (big_int_of_int 0)), 1) -;; -test 4 -eq_int (compare_big_int_ratio - (big_int_of_int (-1)) - (create_ratio (big_int_of_int 3) (big_int_of_int 0)), (-1)) -;; -test 5 -eq_int (compare_big_int_ratio - (big_int_of_int (-1)) - (create_ratio (big_int_of_int 0) (big_int_of_int 0)), 0) -;; -test 6 -eq_int (compare_big_int_ratio - (big_int_of_int (-1)) - (create_ratio (big_int_of_int (-3)) (big_int_of_int 0)), 1) -;; -test 7 -eq_int (compare_big_int_ratio - (big_int_of_int 1) - (create_ratio (big_int_of_int 1) (big_int_of_int 1)), 0) -;; -test 8 -eq_int (compare_big_int_ratio - (big_int_of_int 1) - (create_ratio (big_int_of_int 3) (big_int_of_int 2)), (-1)) -;; -test 9 -eq_int (compare_big_int_ratio - (big_int_of_int 1) - (create_ratio (big_int_of_int 2) (big_int_of_int 3)), 1) -;; - - - -testing_function "int_of_ratio" -;; - -test 1 -eq_int (int_of_ratio (create_ratio (big_int_of_int 4) (big_int_of_int 2)), - 2) -;; - -test 2 -eq_int (int_of_ratio - (create_ratio (big_int_of_int biggest_int) (big_int_of_int 1)), - biggest_int) -;; - -failwith_test 3 -int_of_ratio (create_ratio (big_int_of_int 4) (big_int_of_int 0)) -(Failure "integer argument required") -;; - -failwith_test 4 -int_of_ratio (create_ratio (succ_big_int (big_int_of_int biggest_int)) - (big_int_of_int 1)) -(Failure "integer argument required") -;; - -failwith_test 5 -int_of_ratio (create_ratio (big_int_of_int 4) (big_int_of_int 3)) -(Failure "integer argument required") -;; - -testing_function "ratio_of_int" -;; - -test 1 -eq_ratio (ratio_of_int 3, - create_ratio (big_int_of_int 3) (big_int_of_int 1)) -;; - -test 2 -eq_ratio (ratio_of_nat (nat_of_int 2), - create_ratio (big_int_of_int 2) (big_int_of_int 1)) -;; - -testing_function "nat_of_ratio" -;; - -let nat1 = nat_of_ratio (create_ratio (big_int_of_int 3) (big_int_of_int 1)) -and nat2 = nat_of_int 3 in -test 1 -eq (eq_nat nat1 0 (length_nat nat1) nat2 0 (length_nat nat2), true) -;; - -failwith_test 2 -nat_of_ratio (create_ratio (big_int_of_int 3) (big_int_of_int 0)) -(Failure "nat_of_ratio") -;; - -failwith_test 3 -nat_of_ratio (create_ratio (big_int_of_int (-3)) (big_int_of_int 1)) -(Failure "nat_of_ratio") -;; - -failwith_test 4 -nat_of_ratio (create_ratio (big_int_of_int 3) (big_int_of_int 2)) -(Failure "nat_of_ratio") -;; - -testing_function "ratio_of_big_int" -;; - -test 1 -eq_ratio (ratio_of_big_int (big_int_of_int 3), - create_ratio (big_int_of_int 3) (big_int_of_int 1)) -;; - -testing_function "big_int_of_ratio" -;; - -test 1 -eq_big_int (big_int_of_ratio - (create_ratio (big_int_of_int 3) (big_int_of_int 1)), - big_int_of_int 3) -;; -test 2 -eq_big_int (big_int_of_ratio - (create_ratio (big_int_of_int (-3)) (big_int_of_int 1)), - big_int_of_int (-3)) -;; - -failwith_test 3 -big_int_of_ratio (create_ratio (big_int_of_int 3) (big_int_of_int 0)) -(Failure "big_int_of_ratio") -;; - -testing_function "string_of_ratio" -;; - -test 1 -eq_string (string_of_ratio - (create_ratio (big_int_of_int 43) (big_int_of_int 35)), - "43/35") -;; -test 2 -eq_string (string_of_ratio - (create_ratio (big_int_of_int 42) (big_int_of_int 0)), - "1/0") -;; - -set_normalize_ratio_when_printing false -;; - -test 3 -eq_string (string_of_ratio - (create_ratio (big_int_of_int 42) (big_int_of_int 35)), - "42/35") -;; - -set_normalize_ratio_when_printing true -;; - -test 4 -eq_string (string_of_ratio - (create_ratio (big_int_of_int 42) (big_int_of_int 35)), - "6/5") -;; - -testing_function "ratio_of_string" -;; - -test 1 -eq_ratio (ratio_of_string ("123/3456"), - create_ratio (big_int_of_int 123) (big_int_of_int 3456)) -;; - -(*********** -test 2 -eq_ratio (ratio_of_string ("12.3/34.56"), - create_ratio (big_int_of_int 1230) (big_int_of_int 3456)) -;; -test 3 -eq_ratio (ratio_of_string ("1.23/325.6"), - create_ratio (big_int_of_int 123) (big_int_of_int 32560)) -;; -test 4 -eq_ratio (ratio_of_string ("12.3/345.6"), - create_ratio (big_int_of_int 123) (big_int_of_int 3456)) -;; -test 5 -eq_ratio (ratio_of_string ("12.3/0.0"), - create_ratio (big_int_of_int 123) (big_int_of_int 0)) -;; -***********) -test 6 -eq_ratio (ratio_of_string ("0/0"), - create_ratio (big_int_of_int 0) (big_int_of_int 0)) -;; - -test 7 -eq_ratio (ratio_of_string "1234567890", - create_ratio (big_int_of_string "1234567890") unit_big_int) -;; -failwith_test 8 -ratio_of_string "frlshjkurty" (Failure "invalid digit");; - -(*********** -testing_function "msd_ratio" -;; - -test 1 -eq_int (msd_ratio (create_ratio (big_int_of_int 0) (big_int_of_int 1)), - 0) -;; -test 2 -eq_int (msd_ratio (create_ratio (big_int_of_int 1) (big_int_of_int 12)), - (-2)) -;; -test 3 -eq_int (msd_ratio (create_ratio (big_int_of_int 12) (big_int_of_int 1)), - 1) -;; -test 4 -eq_int (msd_ratio (create_ratio (big_int_of_int 1) (big_int_of_int 2)), - (-1)) -;; -test 5 -eq_int (msd_ratio (create_ratio (big_int_of_int 2) (big_int_of_int 1)), - 0) -;; -test 6 -eq_int (msd_ratio (create_ratio (big_int_of_int 25) (big_int_of_int 21)), - 0) -;; -test 7 -eq_int (msd_ratio (create_ratio (big_int_of_int 35) (big_int_of_int 21)), - 0) -;; -test 8 -eq_int (msd_ratio (create_ratio (big_int_of_int 215) (big_int_of_int 31)), - 0) -;; -test 9 -eq_int (msd_ratio (create_ratio (big_int_of_int 2) (big_int_of_int 30)), - (-2)) -;; -test 10 -eq_int (msd_ratio (create_ratio (big_int_of_int 2345) - (big_int_of_int 23456)), - (-2)) -;; -test 11 -eq_int (msd_ratio (create_ratio (big_int_of_int 2345) - (big_int_of_int 2346)), - (-1)) -;; -test 12 -eq_int (msd_ratio (create_ratio (big_int_of_int 2345) - (big_int_of_int 2344)), - 0) -;; -test 13 -eq_int (msd_ratio (create_ratio (big_int_of_int 23456) - (big_int_of_int 2345)), - 1) -;; -test 14 -eq_int (msd_ratio (create_ratio (big_int_of_int 23467) - (big_int_of_int 2345)), - 1) -;; -failwith_test 15 -msd_ratio (create_ratio (big_int_of_int 1) (big_int_of_int 0)) -("msd_ratio "^infinite_failure) -;; -failwith_test 16 -msd_ratio (create_ratio (big_int_of_int (-1)) (big_int_of_int 0)) -("msd_ratio "^infinite_failure) -;; -failwith_test 17 -msd_ratio (create_ratio (big_int_of_int 0) (big_int_of_int 0)) -("msd_ratio "^infinite_failure) -;; -*************************) - -testing_function "round_futur_last_digit" -;; - -let s = Bytes.of_string "+123456" in -test 1 eq (round_futur_last_digit s 1 (pred (Bytes.length s)), - false) && -test 2 eq_bytes (s, Bytes.of_string "+123466") -;; - -let s = Bytes.of_string "123456" in -test 3 eq (round_futur_last_digit s 0 (Bytes.length s), false) && -test 4 eq_bytes (s, Bytes.of_string "123466") -;; - -let s = Bytes.of_string "-123456" in -test 5 eq (round_futur_last_digit s 1 (pred (Bytes.length s)), - false) && -test 6 eq_bytes (s, Bytes.of_string "-123466") -;; - -let s = Bytes.of_string "+123496" in -test 7 eq (round_futur_last_digit s 1 (pred (Bytes.length s)), - false) && -test 8 eq_bytes (s, Bytes.of_string "+123506") -;; - -let s = Bytes.of_string "123496" in -test 9 eq (round_futur_last_digit s 0 (Bytes.length s), false) && -test 10 eq_bytes (s, Bytes.of_string "123506") -;; - -let s = Bytes.of_string "-123496" in -test 11 eq (round_futur_last_digit s 1 (pred (Bytes.length s)), - false) && -test 12 eq_bytes (s, Bytes.of_string "-123506") -;; - -let s = Bytes.of_string "+996" in -test 13 eq (round_futur_last_digit s 1 (pred (Bytes.length s)), - true) && -test 14 eq_bytes (s, Bytes.of_string "+006") -;; - -let s = Bytes.of_string "996" in -test 15 eq (round_futur_last_digit s 0 (Bytes.length s), true) && -test 16 eq_bytes (s, Bytes.of_string "006") -;; - -let s = Bytes.of_string "-996" in -test 17 eq (round_futur_last_digit s 1 (pred (Bytes.length s)), - true) && -test 18 eq_bytes (s, Bytes.of_string "-006") -;; - -let s = Bytes.of_string "+6666666" in -test 19 eq (round_futur_last_digit s 1 (pred (Bytes.length s)), - false) && -test 20 eq_bytes (s, Bytes.of_string "+6666676") -;; - -let s = Bytes.of_string "6666666" in -test 21 eq (round_futur_last_digit s 0 (Bytes.length s), false) && -test 22 eq_bytes (s, Bytes.of_string "6666676") -;; - -let s = Bytes.of_string "-6666666" in -test 23 eq (round_futur_last_digit s 1 (pred (Bytes.length s)), - false) && -test 24 eq_bytes (s, Bytes.of_string "-6666676") -;; - -testing_function "approx_ratio_fix" -;; - -let s = approx_ratio_fix 5 - (create_ratio (big_int_of_int 2) - (big_int_of_int 3)) in -test 1 -eq_string (s, "+0.66667") -;; - -test 2 -eq_string (approx_ratio_fix 5 - (create_ratio (big_int_of_int 20) - (big_int_of_int 3)), - "+6.66667") -;; -test 3 -eq_string (approx_ratio_fix 5 - (create_ratio (big_int_of_int 2) - (big_int_of_int 30)), - "+0.06667") -;; -test 4 -eq_string (approx_ratio_fix 5 - (create_ratio (big_int_of_string "999996") - (big_int_of_string "1000000")), - "+1.00000") -;; -test 5 -eq_string (approx_ratio_fix 5 - (create_ratio (big_int_of_string "299996") - (big_int_of_string "100000")), - "+2.99996") -;; -test 6 -eq_string (approx_ratio_fix 5 - (create_ratio (big_int_of_string "2999996") - (big_int_of_string "1000000")), - "+3.00000") -;; -test 7 -eq_string (approx_ratio_fix 4 - (create_ratio (big_int_of_string "299996") - (big_int_of_string "100000")), - "+3.0000") -;; -test 8 -eq_string (approx_ratio_fix 5 - (create_ratio (big_int_of_int 29996) - (big_int_of_string "100000")), - "+0.29996") -;; -test 9 -eq_string (approx_ratio_fix 5 - (create_ratio (big_int_of_int 0) - (big_int_of_int 1)), - "+0") -;; -failwith_test 10 -(approx_ratio_fix 5) (create_ratio (big_int_of_int 1) (big_int_of_int 0)) -(Failure "approx_ratio_fix infinite or undefined rational number") -;; -failwith_test 11 -(approx_ratio_fix 5) (create_ratio (big_int_of_int 0) (big_int_of_int 0)) -(Failure "approx_ratio_fix infinite or undefined rational number") -;; - -(* PR#4566 *) -test 12 -eq_string (approx_ratio_fix 8 - (create_ratio (big_int_of_int 9603) - (big_int_of_string "100000000000")), - - "+0.00000010") -;; -test 13 -eq_string (approx_ratio_fix 1 - (create_ratio (big_int_of_int 94) - (big_int_of_int 1000)), - "+0.1") -;; -test 14 -eq_string (approx_ratio_fix 1 - (create_ratio (big_int_of_int 49) - (big_int_of_int 1000)), - "+0.0") -;; - -testing_function "approx_ratio_exp" -;; - -test 1 -eq_string (approx_ratio_exp 5 - (create_ratio (big_int_of_int 2) - (big_int_of_int 3)), - "+0.66667e0") -;; -test 2 -eq_string (approx_ratio_exp 5 - (create_ratio (big_int_of_int 20) - (big_int_of_int 3)), - "+0.66667e1") -;; -test 3 -eq_string (approx_ratio_exp 5 - (create_ratio (big_int_of_int 2) - (big_int_of_int 30)), - "+0.66667e-1") -;; -test 4 -eq_string (approx_ratio_exp 5 - (create_ratio (big_int_of_string "999996") - (big_int_of_string "1000000")), - "+1.00000e0") -;; -test 5 -eq_string (approx_ratio_exp 5 - (create_ratio (big_int_of_string "299996") - (big_int_of_string "100000")), - "+0.30000e1") -;; -test 6 -eq_string (approx_ratio_exp 5 - (create_ratio (big_int_of_int 29996) - (big_int_of_string "100000")), - "+0.29996e0") -;; -test 7 -eq_string (approx_ratio_exp 5 - (create_ratio (big_int_of_int 0) - (big_int_of_int 1)), - "+0.00000e0") -;; -failwith_test 8 -(approx_ratio_exp 5) (create_ratio (big_int_of_int 1) (big_int_of_int 0)) -(Failure "approx_ratio_exp infinite or undefined rational number") -;; -failwith_test 9 -(approx_ratio_exp 5) (create_ratio (big_int_of_int 0) (big_int_of_int 0)) -(Failure "approx_ratio_exp infinite or undefined rational number") -;; - -testing_function "float_of_ratio";; -let ok = ref true in -for i = 1 to 100 do - let p = Random.int64 0x20000000000000L - and pexp = Random.int 100 - and q = Random.int64 0x20000000000000L - and qexp = Random.int 100 in - if not (eq_float - (float_of_ratio - (create_ratio - (shift_left_big_int (big_int_of_int64 p) pexp) - (shift_left_big_int (big_int_of_int64 q) qexp))) - (ldexp (Int64.to_float p) pexp /. - ldexp (Int64.to_float q) qexp)) - then ok := false -done; -test 1 eq (!ok, true) -;; |
