Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- let rnd_sign x =
- if x mod 2 = 0 then (-1) else 1;;
- (* Test for abs_b : test_abs_b *)
- let r_test_abs_b x =
- let rnd = Random.int x in let rnd = (rnd_sign rnd) * rnd in
- let (a, b) = (rnd, abs_b (from_int rnd)) and
- (c, d::l) = (abs rnd, (from_int (abs rnd)))
- in
- (*((a, b), (c, d::l), b = l);;*)
- b = l;;
- let rec test_abs_b n =
- if n <= 0 then
- true
- else
- r_test_abs_b 500000 && test_abs_b (n-1);;
- (* Test for from_int and to_int : test21 *)
- let test1 x =
- let rnd = Random.int x in let rnd = (rnd_sign rnd) * rnd in
- let (a, b) = (rnd, to_int (from_int rnd))
- in
- a = b;;
- let rec test21 n =
- if n <= 0 then
- true
- else
- test1 50000000 && test21 (n-1);;
- (* Test for add_n : test_add_n *)
- let r_test_add_n x =
- let rnd = Random.int x and rnd2 = Random.int x in
- let a = abs_b (from_int rnd) and b = abs_b (from_int rnd2) in
- let c = add_n a b and e = abs_b (from_int (rnd + rnd2)) in
- let d = c = e
- (*in ((rnd, rnd2), (a, b), (c, e), d);;*)
- in d;;
- let rec test_add_n n =
- if n <= 0 then
- true
- else
- r_test_add_n 500000000 && test_add_n (n-1);;
- (* Test for add_b : test_add_b *)
- let r_test_add_b x =
- let rnd = Random.int x and rnd2 = Random.int x in
- let rnd = (rnd_sign rnd) * rnd and rnd2 = (rnd_sign rnd2 ) * rnd2 in
- let a = (from_int rnd) and b = (from_int rnd2) in
- let c = add_b a b and e = from_int (rnd + rnd2) in
- let d = c = e
- (* in ((rnd, rnd2), (a, b), (c, e), d);; *)
- in d;;
- let rec test_add_b n =
- if n <= 0 then
- true
- else
- r_test_add_b 500000000 && test_add_b (n-1);;
- (* Test for diff_n : test_diff_n *)
- let r_test_diff_n x =
- let rnd = Random.int x in let rnd2 = Random.int rnd in
- let a = abs_b (from_int rnd) and b = abs_b (from_int rnd2) in
- let c = diff_n a b and e = abs_b (from_int (rnd - rnd2)) in
- let d = c = e
- in d;;
- (*in ((rnd, rnd2), (a, b), (c, e), d);;*)
- let rec test_diff_n n =
- if n <= 0 then
- true
- else
- r_test_diff_n 500000000 && test_diff_n (n-1);;
- (* Test for add_b : test_add_b *)
- let r_test_add_b x =
- let rnd = Random.int x and rnd2 = Random.int x in
- let rnd = (rnd_sign rnd) * rnd and rnd2 = (rnd_sign rnd2) * rnd2 in
- let a = (from_int rnd) and b = (from_int rnd2) in
- let c = add_b a b and e = (from_int (rnd + rnd2)) in
- let d = c = e
- in d;;
- (*in ((rnd, rnd2), (a, b), (c, e), d);;*)
- let rec test_add_b n =
- if n <= 0 then
- true
- else
- r_test_add_b 500000000 && test_add_b (n-1);;
- (* Test for diff_b : test_diff_b *)
- let r_test_diff_b x =
- let rnd = Random.int x and rnd2 = Random.int x in
- let rnd = (rnd_sign rnd) * rnd and rnd2 = (rnd_sign rnd2) * rnd2 in
- let a = (from_int rnd) and b = (from_int rnd2) in
- let c = diff_b a b and e = (from_int (rnd - rnd2)) in
- let d = c = e
- in d;;
- (* in ((rnd, rnd2), (a, b), (c, e), d);; *)
- let rec test_diff_b n =
- if n <= 0 then
- true
- else
- r_test_diff_b 500000000 && test_diff_b (n-1);;
- (* Test for shift : test_shift *)
- let r_test_shift x =
- let rnd = Random.int x and rnd2 = Random.int 10 in
- let a = (from_int rnd) and b = (from_int rnd2) in
- let c = shift a rnd2 and e = (from_int (rnd * (int_of_float (2. ** (float_of_int rnd2))))) in
- let d = c = e
- in d;;
- (* in ((rnd, rnd2), (a, b), (c, e), d);; *)
- let rec test_shift n =
- if n <= 0 then
- true
- else
- r_test_shift 500000000 && test_shift (n-1);;
- (* Test for mult_b : test_mult_b *)
- let r_test_mult_b x =
- let rnd = Random.int x and rnd2 = Random.int x in
- let rnd = (rnd_sign rnd) * rnd and rnd2 = (rnd_sign rnd2) * rnd2 in
- let a = (from_int rnd) and b = (from_int rnd2) in
- let c = mult_b a b and e = (from_int (rnd * rnd2)) in
- let d = c = e
- in d;;
- (* in ((rnd, rnd2), (a, b), (c, e), d);; *)
- let rec test_mult_b n =
- if n <= 0 then
- true
- else
- r_test_mult_b 500000000 && test_mult_b (n-1);;
- (* Test for quot_b : test_quot_b *)
- let r_test_quot_b x =
- let rnd = Random.int x in let rnd2 = (Random.int (rnd-1))+1 in
- let rnd = (rnd_sign rnd) * rnd and rnd2 = (rnd_sign rnd2) * rnd2 in
- let a = (from_int rnd) and b = (from_int rnd2) in
- let c = quot_b a b and e = (from_int (rnd / rnd2)) in
- let d = c = e
- in d;;
- (* in ((rnd, rnd2), (a, b), (c, e), d);; *)
- let rec test_quot_b n =
- if n <= 0 then
- true
- else
- r_test_quot_b 500000000 && test_quot_b (n-1);;
- (* Test for mod_b : test_mod_b *)
- let r_test_mod_b x =
- let rnd = Random.int x in let rnd2 = (Random.int (rnd-1))+1 in
- let rnd = (rnd_sign rnd) * rnd and rnd2 = (rnd_sign rnd2) * rnd2 in
- let a = (from_int rnd) and b = (from_int rnd2) in
- let c = div_b a b and (x,y) = div rnd rnd2 in let e = ((from_int x), (from_int y)) in
- let d = c = e
- in d;;
- (* in ((rnd, rnd2), (a, b), (c, e), d);; *)
- let rec test_mod_b n =
- if n <= 0 then
- true
- else
- r_test_mod_b 500000000 && test_mod_b (n-1);;
- print_string "Test function abs_b"; test_abs_b 50000;;
- print_string "Test function from_int and to_int"; test_abs_b 100000;;
- print_string "Test function add_n"; test_add_n 100000;;
- print_string "Test function add_b"; test_add_b 100000;;
- print_string "Test function diff_n"; test_diff_n 100000;;
- print_string "Test function diff_b"; test_diff_b 100000;;
- print_string "Test function shift"; test_shift 100000;;
- print_string "Test function mult_b"; test_mult_b 100000;;
- print_string "Test function mod_b"; test_mod_b 100000;;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement