Advertisement
Carlotronics

EPITA - AFIT - Scalable file - tests

Dec 19th, 2018
441
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
OCaml 5.44 KB | None | 0 0
  1. let rnd_sign x =
  2.     if x mod 2 = 0 then (-1) else 1;;
  3.  
  4.  
  5.  
  6. (* Test for abs_b : test_abs_b *)
  7.  
  8.  
  9.     let r_test_abs_b x =
  10.         let rnd = Random.int x in let rnd = (rnd_sign rnd) * rnd in
  11.             let (a, b) = (rnd, abs_b (from_int rnd)) and
  12.             (c, d::l) = (abs rnd, (from_int (abs rnd)))
  13.             in
  14.             (*((a, b), (c, d::l), b = l);;*)
  15.             b = l;;
  16.  
  17.     let rec test_abs_b n =
  18.         if n <= 0 then
  19.             true
  20.         else
  21.             r_test_abs_b 500000 && test_abs_b (n-1);;
  22.  
  23.  
  24. (* Test for from_int and to_int : test21 *)
  25.  
  26.     let test1 x =
  27.         let rnd = Random.int x in let rnd = (rnd_sign rnd) * rnd in
  28.             let (a, b) = (rnd, to_int (from_int rnd))
  29.             in
  30.             a = b;;
  31.  
  32.     let rec test21 n =
  33.         if n <= 0 then
  34.             true
  35.         else
  36.             test1 50000000 && test21 (n-1);;
  37.  
  38.  
  39. (* Test for add_n : test_add_n *)
  40.  
  41.     let r_test_add_n x =
  42.         let rnd = Random.int x and rnd2 = Random.int x in
  43.         let a = abs_b (from_int rnd) and b = abs_b (from_int rnd2) in
  44.         let c = add_n a b and e = abs_b (from_int (rnd + rnd2)) in
  45.         let d = c = e
  46.         (*in ((rnd, rnd2), (a, b), (c, e), d);;*)
  47.         in d;;
  48.  
  49.     let rec test_add_n n =
  50.         if n <= 0 then
  51.             true
  52.         else
  53.             r_test_add_n 500000000 && test_add_n (n-1);;
  54.  
  55.  
  56. (* Test for add_b : test_add_b *)
  57.     let r_test_add_b x =
  58.         let rnd = Random.int x and rnd2 = Random.int x in
  59.         let rnd = (rnd_sign rnd) * rnd and rnd2 = (rnd_sign rnd2 ) * rnd2 in
  60.         let a =  (from_int rnd) and b =  (from_int rnd2) in
  61.         let c = add_b a b and e = from_int (rnd + rnd2) in
  62.         let d = c = e
  63.         (* in ((rnd, rnd2), (a, b), (c, e), d);; *)
  64.         in d;;
  65.  
  66.     let rec test_add_b n =
  67.         if n <= 0 then
  68.             true
  69.         else
  70.             r_test_add_b 500000000 && test_add_b (n-1);;
  71.  
  72.  
  73. (* Test for diff_n : test_diff_n *)
  74.  
  75.     let r_test_diff_n x =
  76.         let rnd = Random.int x in let rnd2 = Random.int rnd in
  77.         let a = abs_b (from_int rnd) and b = abs_b (from_int rnd2) in
  78.         let c = diff_n a b and e = abs_b (from_int (rnd - rnd2)) in
  79.         let d = c = e
  80.         in d;;
  81.         (*in ((rnd, rnd2), (a, b), (c, e), d);;*)
  82.  
  83.     let rec test_diff_n n =
  84.         if n <= 0 then
  85.             true
  86.         else
  87.             r_test_diff_n 500000000 && test_diff_n (n-1);;
  88.  
  89.  
  90. (* Test for add_b : test_add_b *)
  91.  
  92.     let r_test_add_b x =
  93.         let rnd = Random.int x and rnd2 = Random.int x in
  94.         let rnd = (rnd_sign rnd) * rnd and rnd2 = (rnd_sign rnd2) * rnd2 in
  95.         let a = (from_int rnd) and b = (from_int rnd2) in
  96.         let c = add_b a b and e = (from_int (rnd + rnd2)) in
  97.         let d = c = e
  98.         in d;;
  99.         (*in ((rnd, rnd2), (a, b), (c, e), d);;*)
  100.  
  101.     let rec test_add_b n =
  102.         if n <= 0 then
  103.             true
  104.         else
  105.             r_test_add_b 500000000 && test_add_b (n-1);;
  106.  
  107.  
  108. (* Test for diff_b : test_diff_b *)
  109.  
  110.     let r_test_diff_b x =
  111.         let rnd = Random.int x and rnd2 = Random.int x in
  112.         let rnd = (rnd_sign rnd) * rnd and rnd2 = (rnd_sign rnd2) * rnd2 in
  113.         let a = (from_int rnd) and b = (from_int rnd2) in
  114.         let c = diff_b a b and e = (from_int (rnd - rnd2)) in
  115.         let d = c = e
  116.         in d;;
  117.         (* in ((rnd, rnd2), (a, b), (c, e), d);; *)
  118.  
  119.     let rec test_diff_b n =
  120.         if n <= 0 then
  121.             true
  122.         else
  123.             r_test_diff_b 500000000 && test_diff_b (n-1);;
  124.  
  125.  
  126. (* Test for shift : test_shift *)
  127.  
  128.     let r_test_shift x =
  129.         let rnd = Random.int x and rnd2 = Random.int 10 in
  130.         let a = (from_int rnd) and b = (from_int rnd2) in
  131.         let c = shift a rnd2 and e = (from_int (rnd * (int_of_float (2. ** (float_of_int rnd2))))) in
  132.         let d = c = e
  133.         in d;;
  134.         (* in ((rnd, rnd2), (a, b), (c, e), d);; *)
  135.  
  136.     let rec test_shift n =
  137.         if n <= 0 then
  138.             true
  139.         else
  140.             r_test_shift 500000000 && test_shift (n-1);;
  141.  
  142.  
  143. (* Test for mult_b : test_mult_b *)
  144.  
  145.     let r_test_mult_b x =
  146.         let rnd = Random.int x and rnd2 = Random.int x in
  147.         let rnd = (rnd_sign rnd) * rnd and rnd2 = (rnd_sign rnd2) * rnd2 in
  148.         let a = (from_int rnd) and b = (from_int rnd2) in
  149.         let c = mult_b a b and e = (from_int (rnd * rnd2)) in
  150.         let d = c = e
  151.         in d;;
  152.         (* in ((rnd, rnd2), (a, b), (c, e), d);; *)
  153.  
  154.     let rec test_mult_b n =
  155.         if n <= 0 then
  156.             true
  157.         else
  158.             r_test_mult_b 500000000 && test_mult_b (n-1);;
  159.  
  160.  
  161. (* Test for quot_b : test_quot_b *)
  162.  
  163.     let r_test_quot_b x =
  164.         let rnd = Random.int x in let rnd2 = (Random.int (rnd-1))+1 in
  165.         let rnd = (rnd_sign rnd) * rnd and rnd2 = (rnd_sign rnd2) * rnd2 in
  166.         let a = (from_int rnd) and b = (from_int rnd2) in
  167.         let c = quot_b a b and e = (from_int (rnd / rnd2)) in
  168.         let d = c = e
  169.         in d;;
  170.         (* in ((rnd, rnd2), (a, b), (c, e), d);; *)
  171.  
  172.     let rec test_quot_b n =
  173.         if n <= 0 then
  174.             true
  175.         else
  176.             r_test_quot_b 500000000 && test_quot_b (n-1);;
  177.  
  178.  
  179. (* Test for mod_b : test_mod_b *)
  180.  
  181.     let r_test_mod_b x =
  182.         let rnd = Random.int x in let rnd2 = (Random.int (rnd-1))+1 in
  183.         let rnd = (rnd_sign rnd) * rnd and rnd2 = (rnd_sign rnd2) * rnd2 in
  184.         let a = (from_int rnd) and b = (from_int rnd2) in
  185.         let c = div_b a b and (x,y) = div rnd rnd2 in let e = ((from_int x), (from_int y)) in
  186.         let d = c = e
  187.         in d;;
  188.         (* in ((rnd, rnd2), (a, b), (c, e), d);; *)
  189.  
  190.     let rec test_mod_b n =
  191.         if n <= 0 then
  192.             true
  193.         else
  194.             r_test_mod_b 500000000 && test_mod_b (n-1);;
  195.  
  196. print_string "Test function abs_b"; test_abs_b 50000;;
  197.  
  198. print_string "Test function from_int and to_int"; test_abs_b 100000;;
  199.  
  200. print_string "Test function add_n"; test_add_n 100000;;
  201.  
  202. print_string "Test function add_b"; test_add_b 100000;;
  203.  
  204. print_string "Test function diff_n"; test_diff_n 100000;;
  205.  
  206. print_string "Test function diff_b"; test_diff_b 100000;;
  207.  
  208. print_string "Test function shift"; test_shift 100000;;
  209.  
  210. print_string "Test function mult_b"; test_mult_b 100000;;
  211.  
  212. print_string "Test function mod_b"; test_mod_b 100000;;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement