(* Idea: a copy of each file with extension .txt is created. Each copy is compressed then decompressed. Then we compare the original file with the decompressed copy. The names of the files to be tested should therefore have the extension .txt and they should be in the same directory as the binary file generated by Eclipse i.e. _build . *) (* The list of novels to be tested. *) let text_extension = ".txt" let novels = (* Get all the filenames in the current directory and the "novels" directory. *) let novels = Sys.readdir (Sys.getcwd ()) in let novels = Array.append novels (Array.map (fun f -> "novels/" ^ f) (Sys.readdir (Sys.getcwd () ^ "/novels"))) in (* Turn the array into a list *) let novels = Array.to_list novels in (* Discard all nontext files *) List.filter (fun filename -> Filename.check_suffix filename text_extension) novels (* Names of the copies. *) let copy_extension = ".copy" let novel_copies = List.map (fun filename -> (filename^copy_extension)) novels (* Names of the compressed copies. *) let compressed_extension = ".zz" let compressed_copies = List.map (fun filename -> filename^compressed_extension) novel_copies let copy file = let src = open_in_bin file in let tgt = open_out_bin (file ^ ".copy") in try while true do output_string tgt ((input_line src)^"\n") done with | End_of_file -> ( close_in src ; close_out tgt) let original_vs_copy file = let original = file in let copy = file^copy_extension in if LazyIO.compare original copy then Printf.printf "The files %s and %s are the same.\n" original copy else Printf.printf "The files %s and %s differ.\n" original copy let compress file = let compressed = file ^ compressed_extension in Printf.printf "Compressing file %s to %s\n" file compressed ; flush stdout ; Zipper.compress file let decompress file = Printf.printf "Decompressing file %s to %s\n" file (Filename.chop_extension file) ; flush stdout ; Zipper.decompress file let () = (* Create the copies (.txt.copy) *) let () = List.iter copy novels in (* Compress the copies (.txt.copy.zz) *) let () = List.iter compress novel_copies in (* Decompress the copies (.txt.copy) so the former copies are overwritten *) let () = List.iter decompress compressed_copies in List.iter original_vs_copy novels