Você não pode selecionar mais de 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.

38 linhas
947 B

9 anos atrás
  1. % This file is part of Jiffy released under the MIT license.
  2. % See the LICENSE file for more information.
  3. -module(jiffy_10_short_double_tests).
  4. -include_lib("eunit/include/eunit.hrl").
  5. -include("jiffy_util.hrl").
  6. filename() ->
  7. FName = "test/cases/short-doubles.txt",
  8. case filelib:is_file(FName) of
  9. true -> FName;
  10. false -> "../" ++ FName
  11. end.
  12. short_double_test_() ->
  13. {ok, Fd} = file:open(filename(), [read, binary, raw]),
  14. {timeout, 300, ?_assertEqual(0, run(Fd, 0))}.
  15. run(Fd, Acc) ->
  16. case file:read_line(Fd) of
  17. {ok, Data} ->
  18. V1 = re:replace(iolist_to_binary(Data), <<"\.\n">>, <<"">>),
  19. V2 = iolist_to_binary(V1),
  20. V3 = <<34, V2/binary, 34>>,
  21. R = jiffy:encode(jiffy:decode(V3)),
  22. case R == V3 of
  23. true -> run(Fd, Acc);
  24. false -> run(Fd, Acc + 1)
  25. end;
  26. eof ->
  27. Acc
  28. end.