ts010015.pp 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. program ttyped;
  2. Type
  3. TRec = record
  4. X,Y : longint;
  5. end;
  6. TRecFile = File of TRec;
  7. var TF : TRecFile;
  8. LF : File of longint;
  9. i,j,k,l : longint;
  10. t : Trec;
  11. begin
  12. Write ('Writing files...');
  13. assign (LF,'longint.dat');
  14. rewrite (LF);
  15. for i:=1 to 10 do
  16. write (LF,i);
  17. close (LF);
  18. Assign (TF,'TRec.dat');
  19. rewrite (TF);
  20. for i:=1 to 10 do
  21. for j:=1 to 10 do
  22. begin
  23. t.x:=i;
  24. t.y:=j;
  25. write (TF,T);
  26. end;
  27. close (TF);
  28. writeln ('Done');
  29. reset (LF);
  30. reset (TF);
  31. Write ('Sequential read test...');
  32. for i:=1 to 10 do
  33. begin
  34. read (LF,J);
  35. if j<>i then writeln ('Read of longint failed at :',i);
  36. end;
  37. for i:=1 to 10 do
  38. for j:=1 to 10 do
  39. begin
  40. read (tf,t);
  41. if (t.x<>i) or (t.y<>j) then
  42. writeln ('Read of record failed at :',i,',',j);
  43. end;
  44. writeln ('Done.');
  45. Write ('Random access read test...');
  46. For i:=1 to 10 do
  47. begin
  48. k:=random(10);
  49. seek (lf,k);
  50. read (lf,j);
  51. if j<>k+1 then
  52. Writeln ('Failed random read of longint at pos ',k,' : ',j);
  53. end;
  54. For i:=1 to 10 do
  55. for j:=1 to 10 do
  56. begin
  57. k:=random(10);
  58. l:=random(10);
  59. seek (tf,k*10+l);
  60. read (tf,t);
  61. if (t.x<>k+1) or (t.y<>l+1) then
  62. Writeln ('Failed random read of longint at pos ',k,',',l,' : ',t.x,',',t.y);
  63. end;
  64. Writeln ('Done.');
  65. close (lf);
  66. close (TF);
  67. erase (lf);
  68. erase (tf);
  69. end.