Skip to content

Commit

Permalink
Test for #237 + some more tests for format
Browse files Browse the repository at this point in the history
The previous commit and its refactoring already "accidentally"
fixed the bug as it removed the faulty duration_output and
substituted it with the existing memory_output that already that
takes care of this case.
  • Loading branch information
PragTob committed Jul 31, 2018
1 parent 9c8434f commit 3347e77
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 7 deletions.
10 changes: 4 additions & 6 deletions lib/benchee/conversion/format.ex
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,10 @@ defmodule Benchee.Conversion.Format do
custom separator string that will appear between the value and label in the
formatted output. If no `separator/0` function exists, the default separator
(a single space) will be used.
iex> Benchee.Conversion.Format.format({1.0, :kilobyte}, Benchee.Conversion.Memory)
"1 KB"
"""
def format({count, unit = %Unit{}}) do
format(count, label(unit), separator())
Expand All @@ -59,12 +63,6 @@ defmodule Benchee.Conversion.Format do
|> format
end

def format(number) do
number
|> Scale.scale()
|> format()
end

@default_separator " "
# should we need it again, a customer separator could be returned
# per module here
Expand Down
2 changes: 1 addition & 1 deletion lib/benchee/formatters/console/helpers.ex
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ defmodule Benchee.Formatters.Console.Helpers do
memory usage statistics.
"""

alias Benchee.Conversion.{Count, DeviationPercent, Duration, Format, Scale, Unit}
alias Benchee.Conversion.{Count, DeviationPercent, Format, Scale, Unit}
alias Benchee.Statistics

@type unit_per_statistic :: %{atom => Unit.t()}
Expand Down
35 changes: 35 additions & 0 deletions test/benchee/formatters/console/memory_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -378,6 +378,41 @@ defmodule Benchee.Formatters.Console.MemoryTest do
assert output =~ "Second"
refute output =~ "x memory usage"
end

test "it doesn't blow up if some come back with a median et. al. of nil" do
scenarios = [
%Scenario{
name: "First",
memory_usage_statistics: %Statistics{},
run_time_statistics: %Statistics{}
},
%Scenario{
name: "Second",
memory_usage_statistics: %Statistics{
average: 100.0,
median: 100.0,
sample_size: 5,
percentiles: %{99 => 100.0},
std_dev: 5.0,
std_dev_ratio: 0.10
},
run_time_statistics: %Statistics{}
}
]

output =
Enum.join(
Memory.format_scenarios(scenarios, %{
comparison: true,
unit_scaling: :best,
extended_statistics: false
})
)

assert output =~ "First"
assert output =~ "Second"
refute output =~ "x memory usage"
end
end

defp assert_column_width(name, string, expected_width) do
Expand Down

0 comments on commit 3347e77

Please sign in to comment.