home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 5 / Apprentice-Release5.iso / Source Code / C / Applications / Moscow ML 1.31 / source code / mosml / src / mosmllib / test / word8array.sml < prev    next >
Encoding:
Text File  |  1996-07-03  |  4.8 KB  |  130 lines  |  [TEXT/R*ch]

  1. (* test/word8array.sml -- some test cases for Word8Array 
  2.    PS 1994-12-21, 1995-05-11 *)
  3.  
  4. use "auxil.sml";
  5.  
  6. local
  7.     open Word8Array 
  8.     infix 9 sub;
  9.     val array0 = fromList [];
  10. in
  11.  
  12. val i2w = Word8.intToWord;
  13.  
  14. val w127 = i2w 127;
  15.  
  16. val a = fromList (map i2w [0,1,2,3,4,5,6]);
  17. val b = fromList (map i2w [44,55,66]);
  18. val c = fromList (map i2w [0,1,2,3,4,5,6]);
  19.  
  20. val test1 = 
  21.     check'(fn () => a<>c);
  22. val test2 = 
  23.     check'(fn () => 
  24.        array(0, w127) <> array0
  25.        andalso array(0, w127) <> tabulate(0, fn _ => w127)
  26.        andalso tabulate(0, fn _ => w127) <> fromList []
  27.        andalso array(0, w127) <> array(0, w127)
  28.        andalso tabulate(0, fn _ => w127) <> tabulate(0, fn _ => w127)
  29.        andalso fromList [] <> fromList []);
  30.  
  31. val d = tabulate(100, fn i => i2w (i mod 7));
  32.  
  33. val test3 = check' (fn () => d sub 27 = i2w 6);
  34.  
  35. val test4a = (tabulate(maxLen+1, i2w) seq "WRONG")
  36.             handle Size => "OK" | _ => "WRONG";
  37.  
  38. val test4b = (tabulate(~1, i2w)       seq "WRONG")
  39.             handle Size => "OK" | _ => "WRONG";
  40.  
  41. val test4c = 
  42.     check'(fn () => length (tabulate(0, fn i => i2w (i div 0))) = 0);
  43.  
  44. val test5a = check'(fn () => length (fromList []) = 0 andalso length a = 7);
  45. val test5b = check'(fn () => length array0 = 0);
  46.  
  47. val test6a = (c sub ~1 seq "WRONG") handle Subscript => "OK" | _ => "WRONG";
  48. val test6b = (c sub 7  seq "WRONG") handle Subscript => "OK" | _ => "WRONG";
  49. val test6c = check'(fn () => c sub 0 = i2w 0);
  50.  
  51. val e = array(203, i2w 0);
  52. val _ = (copy{src=d, si=0, dst=e, di=0,        len=length d}; 
  53.      copy{src=b, si=0, dst=e, di=length d, len=length b};
  54.      copy{src=d, si=0, dst=e, di=length d + length b, len=length d});
  55.      
  56. fun a2v a = extract(a, 0, NONE);
  57. val ev = Word8Vector.concat [a2v d, a2v b, a2v d];
  58.  
  59. val test7 = check'(fn () => length e = 203);
  60.  
  61. val test8a = (update(e, ~1, w127); "WRONG")
  62.              handle Subscript => "OK" | _ => "WRONG";
  63. val test8b = (update(e, length e, w127); "WRONG")
  64.              handle Subscript => "OK" | _ => "WRONG";
  65.  
  66. val f = extract (e, 100, SOME 3);
  67.  
  68. val test9 = check'(fn () => f = a2v b);
  69.  
  70. val test9a = check'(fn () => ev = extract(e, 0, NONE)
  71.             andalso ev = extract(e, 0, SOME (length e)));
  72. val test9b = 
  73.     check'(fn () => Word8Vector.fromList [] = extract(e, 100, SOME 0));
  74. val test9c = (extract(e, ~1, SOME (length e))  seq "WRONG") 
  75.              handle Subscript => "OK" | _ => "WRONG"
  76. val test9d = (extract(e, length e+1, SOME 0) seq "WRONG") 
  77.              handle Subscript => "OK" | _ => "WRONG"
  78. val test9e = (extract(e, 0, SOME (length e+1)) seq "WRONG") 
  79.              handle Subscript => "OK" | _ => "WRONG"
  80. val test9f = (extract(e, 20, SOME ~1)        seq "WRONG") 
  81.              handle Subscript => "OK" | _ => "WRONG"
  82. val test9g = (extract(e, ~1, NONE)  seq "WRONG") 
  83.              handle Subscript => "OK" | _ => "WRONG"
  84. val test9h = (extract(e, length e+1, NONE) seq "WRONG") 
  85.              handle Subscript => "OK" | _ => "WRONG"
  86. val test9i = 
  87.     check'(fn () => a2v (fromList []) = extract(e, length e, SOME 0)
  88.        andalso a2v (fromList []) = extract(e, length e, NONE));
  89.  
  90. val _ = copy{src=e, si=0, dst=e, di=0, len=length e};
  91. val g = array(203, w127);
  92. val _ = copy{src=e, si=0, dst=g, di=0, len=length e};
  93.  
  94. val test10a = check'(fn () => ev = extract(e, 0, NONE)
  95.               andalso ev = extract(e, 0, SOME (length e)));
  96. val test10b = check'(fn () => ev = extract(g, 0, NONE)
  97.              andalso ev = extract(g, 0, SOME (length g)));
  98.  
  99. val _ = copy{src=g, si=203, dst=g, di=0, len=0};
  100. val test10c = check'(fn () => ev = extract(g, 0, NONE));
  101.  
  102. val _ = copy{src=g, si=0, dst=g, di=203, len=0};
  103. val test10d = check'(fn () => ev = extract(g, 0, NONE));
  104.  
  105. val _ = copy{src=g, si=0, dst=g, di=1, len=length g-1};
  106. val test10e = check'(fn () => a2v b = extract(g, 101, SOME 3));
  107.  
  108. val _ = copy{src=g, si=1, dst=g, di=0, len=length g-1};
  109. val test10f = check'(fn () => a2v b = extract(g, 100, SOME 3));
  110.  
  111. val _ = copy{src=g, si=202, dst=g, di=202, len=1};
  112. val test10g = check'(fn () => g sub 202 = i2w ((202-1-103) mod 7));
  113. val test10h = check'(fn () =>
  114.              (copy{src=array0, si=0, dst=array0, di=0, len=0}; 
  115.               array0 <> array(0, w127)));
  116.  
  117. val test11a = (copy{src=g, si= ~1, dst=g, di=0, len=length g}; "WRONG") 
  118.               handle Subscript => "OK" | _ => "WRONG"
  119. val test11b = (copy{src=g, si=0, dst=g, di= ~1, len=length g}; "WRONG") 
  120.               handle Subscript => "OK" | _ => "WRONG"
  121. val test11c = (copy{src=g, si=1, dst=g, di=0, len=length g}; "WRONG") 
  122.               handle Subscript => "OK" | _ => "WRONG"
  123. val test11d = (copy{src=g, si=0, dst=g, di=1, len=length g}; "WRONG") 
  124.               handle Subscript => "OK" | _ => "WRONG"
  125. val test11e = (copy{src=g, si=0, dst=g, di=0, len=length g+1}; "WRONG") 
  126.               handle Subscript => "OK" | _ => "WRONG"
  127. val test11f = (copy{src=g, si=203, dst=g, di=0, len=1}; "WRONG") 
  128.               handle Subscript => "OK" | _ => "WRONG"
  129. end;
  130.