<commit_before>defmodule Benchee.Formatters.HTMLTest do
  use ExUnit.Case
  alias Benchee.Formatters.HTML
  import ExUnit.CaptureIO
  doctest Benchee.Formatters.HTML

  @test_directory "test_output"
  @filename "#{@test_directory}/my.html"
  @expected_filename "#{@test_directory}/my_some_input_comparison.html"
  @system_info %{
    elixir: "1.4.0",
    erlang: "19.1",
    os: "macOS",
    available_memory: "2 GB",
    cpu_speed: "2.80GHz",
    num_cores: 2
  }
  @scenario %Benchee.Benchmark.Scenario{
    job_name: "My Job",
    name: "My Job",
    run_times: [190, 200, 210],
    input_name: "Some Input",
    input: "Some Input",
    run_time_statistics: %Benchee.Statistics{
      average:       200.0,
      ips:           5000.0,
      std_dev:       20,
      std_dev_ratio: 0.1,
      std_dev_ips:   500,
      median:        190.0,
      sample_size:   3,
      minimum:       190,
      maximum:       210
    }
  }
  @sample_suite %Benchee.Suite{
                   scenarios: [@scenario],
                   system: @system_info,
                   configuration: %Benchee.Configuration{
                     formatter_options: %{html: %{file: @filename, auto_open: false}}
                   }
                 }
  test ".format returns an HTML-ish string for every input" do
    {format, _} = HTML.format @sample_suite

    Enum.each format, fn({_, html}) ->
      assert html =~ ~r/<html>.+<article>.+<\/html>/si
    end
  end

  test ".format has the important suite data in the html result" do
    Enum.each comparison_and_job_htmls(), fn(html) ->
      assert_includes html,
        [
          "[190,200,210]", "\"average\":200.0", "\"median\":190.0",
          "\"ips\":5.0e3", "My Job", ">3<", ">190 μs<", ">210 μs<", ">200 μs<",
          "5 K"
        ]
    end
  end

  test ".format has system info in the html result" do
    Enum.each comparison_and_job_htmls(), fn(html) ->
      assert_includes html,
        [
          "Elixir: #{@system_info[:elixir]}",
          "Erlang: #{@system_info[:erlang]}",
          "Operating system: #{@system_info[:os]}",
          "Available memory: #{@system_info[:available_memory]}",
          "CPU Information: #{@system_info[:cpu_speed]}",
          "Number of Available Cores: #{@system_info[:num_cores]}",
        ]
    end
  end

  test ".format also scales the run times to ms" do
    statistics = %Benchee.Statistics{
      average:       1500.0,
      ips:           666.66,
      std_dev:       150,
      std_dev_ratio: 0.1,
      std_dev_ips:   66.66,
      median:        1400.0,
      sample_size:   3,
      minimum:       1300,
      maximum:       1700
    }
    scenario = %Benchee.Benchmark.Scenario{
      @scenario | run_time_statistics: statistics
    }
    suite = %Benchee.Suite{@sample_suite | scenarios: [scenario]}

    Enum.each comparison_and_job_htmls(suite), fn(html) ->
      assert_includes html,
        [">1.50 ms<", ">666.66<", ">1.40 ms<", ">1.30 ms<", ">1.70 ms<"]
    end
  end

  test ".format produces the right JSON data without the input level" do
    {%{["Some Input", "comparison"] => html}, _} = HTML.format @sample_suite

    assert html =~ "{\"statistics\":{\"My Job\""
  end

  test ".format shows the units alright" do<commit_msg>when you update a deendency and dont run the test suite :angel:<commit_after>defmodule Benchee.Formatters.HTMLTest do
  use ExUnit.Case
  alias Benchee.Formatters.HTML
  import ExUnit.CaptureIO
  doctest Benchee.Formatters.HTML

  @test_directory "test_output"
  @filename "#{@test_directory}/my.html"
  @expected_filename "#{@test_directory}/my_some_input_comparison.html"
  @system_info %{
    elixir: "1.4.0",
    erlang: "19.1",
    os: "macOS",
    available_memory: "2 GB",
    cpu_speed: "2.80GHz",
    num_cores: 2
  }
  @scenario %Benchee.Benchmark.Scenario{
    job_name: "My Job",
    name: "My Job",
    run_times: [190, 200, 210],
    input_name: "Some Input",
    input: "Some Input",
    run_time_statistics: %Benchee.Statistics{
      average:       200.0,
      ips:           5000.0,
      std_dev:       20,
      std_dev_ratio: 0.1,
      std_dev_ips:   500,
      median:        190.0,
      sample_size:   3,
      minimum:       190,
      maximum:       210
    }
  }
  @sample_suite %Benchee.Suite{
                   scenarios: [@scenario],
                   system: @system_info,
                   configuration: %Benchee.Configuration{
                     formatter_options: %{html: %{file: @filename, auto_open: false}}
                   }
                 }
  test ".format returns an HTML-ish string for every input" do
    {format, _} = HTML.format @sample_suite

    Enum.each format, fn({_, html}) ->
      assert html =~ ~r/<html>.+<article>.+<\/html>/si
    end
  end

  test ".format has the important suite data in the html result" do
    Enum.each comparison_and_job_htmls(), fn(html) ->
      assert_includes html,
        [
          "[190,200,210]", "\"average\":200.0", "\"median\":190.0",
          "\"ips\":5.0e3", "My Job", ">3<", ">190 μs<", ">210 μs<", ">200 μs<",
          "5 K"
        ]
    end
  end

  test ".format has system info in the html result" do
    Enum.each comparison_and_job_htmls(), fn(html) ->
      assert_includes html,
        [
          "Elixir: #{@system_info[:elixir]}",
          "Erlang: #{@system_info[:erlang]}",
          "Operating system: #{@system_info[:os]}",
          "Available memory: #{@system_info[:available_memory]}",
          "CPU Information: #{@system_info[:cpu_speed]}",
          "Number of Available Cores: #{@system_info[:num_cores]}",
        ]
    end
  end

  test ".format also scales the run times to ms" do
    statistics = %Benchee.Statistics{
      average:       1500.0,
      ips:           666.66,
      std_dev:       150,
      std_dev_ratio: 0.1,
      std_dev_ips:   66.66,
      median:        1400.0,
      sample_size:   3,
      minimum:       1300,
      maximum:       1700
    }
    scenario = %Benchee.Benchmark.Scenario{
      @scenario | run_time_statistics: statistics
    }
    suite = %Benchee.Suite{@sample_suite | scenarios: [scenario]}

    Enum.each comparison_and_job_htmls(suite), fn(html) ->
      assert_includes html,
        [">1.50 ms<", ">666.66<", ">1.40 ms<", ">1.30 ms<", ">1.70 ms<"]
    end
  end

  test ".format produces the right JSON data without the input level" do
    {%{["Some Input", "comparison"] => html}, _} = HTML.format @sample_suite

    assert html =~ "\"statistics\":{\"My Job\""
  end

  test ".format shows the units alright" do
{'fraction_non_alphanumeric': 0.1413292589763178, 'fraction_numerical': 0.039113827349121465, 'mean_word_length': 2.240594059405941, 'pattern_counts': {'":': 8, '<': 27, '<?xml version=': 0, '>': 37, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '959511', 'n_tokens_mistral': 2383, 'n_tokens_neox': 2180, 'n_words': 528}