Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 8 additions & 4 deletions src/lib/reporter/format.mbt
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@
fn format_us_as_ms(us : Int64) -> String {
let ms_whole = us / 1000L
let ms_frac = us % 1000L / 10L
"\{ms_whole}.\{ms_frac}ms"
let frac_str = if ms_frac < 10L { "0\{ms_frac}" } else { "\{ms_frac}" }
"\{ms_whole}.\{frac_str}ms"
}

///|
Expand All @@ -11,21 +12,24 @@ fn format_percentage(part : Int, total : Int) -> String {
let pct = part.to_double() / total.to_double() * 100.0
let whole = pct.to_int()
let frac = ((pct - whole.to_double()) * 100.0).to_int()
"\{whole}.\{frac}%"
let frac_str = if frac < 10 { "0\{frac}" } else { "\{frac}" }
"\{whole}.\{frac_str}%"
}

///|
fn format_rps(rps : Double) -> String {
let whole = rps.to_int()
let frac = ((rps - whole.to_double()) * 100.0).to_int()
"\{whole}.\{frac}"
let frac_str = if frac < 10 { "0\{frac}" } else { "\{frac}" }
"\{whole}.\{frac_str}"
}

///|
fn format_time(ms : Double) -> String {
let whole = (ms / 1000.0).to_int()
let frac = (ms % 1000.0 / 10.0).to_int()
"\{whole}.\{frac}s"
let frac_str = if frac < 10 { "0\{frac}" } else { "\{frac}" }
"\{whole}.\{frac_str}s"
}

///|
Expand Down
2 changes: 1 addition & 1 deletion src/lib/reporter/reporter_test.mbt
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ test "report_text with no errors omits errors section" {
)
let output = @reporter.report_text(stats)
inspect(output.contains("Errors"), content="false")
inspect(output.contains("Successful: 100 (100.0%)"), content="true")
inspect(output.contains("Successful: 100 (100.00%)"), content="true")
}

///|
Expand Down
68 changes: 56 additions & 12 deletions src/lib/reporter/reporter_wbtest.mbt
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
///|
test "format_us_as_ms zero" {
inspect(format_us_as_ms(0L), content="0.0ms")
inspect(format_us_as_ms(0L), content="0.00ms")
}

///|
test "format_us_as_ms 1us rounds to 0 fractional" {
inspect(format_us_as_ms(1L), content="0.0ms")
inspect(format_us_as_ms(1L), content="0.00ms")
}

///|
Expand All @@ -15,7 +15,7 @@ test "format_us_as_ms 999us" {

///|
test "format_us_as_ms 1000us exact millisecond" {
inspect(format_us_as_ms(1000L), content="1.0ms")
inspect(format_us_as_ms(1000L), content="1.00ms")
}

///|
Expand All @@ -30,7 +30,17 @@ test "format_us_as_ms 999999us" {

///|
test "format_us_as_ms 1000000us" {
inspect(format_us_as_ms(1000000L), content="1000.0ms")
inspect(format_us_as_ms(1000000L), content="1000.00ms")
}

///|
test "format_us_as_ms 80us single-digit fraction is zero-padded" {
inspect(format_us_as_ms(80L), content="0.08ms")
}

///|
test "format_us_as_ms 100us boundary already two digits" {
inspect(format_us_as_ms(100L), content="0.10ms")
}

///|
Expand All @@ -40,12 +50,12 @@ test "format_percentage zero total guard" {

///|
test "format_percentage zero of hundred" {
inspect(format_percentage(0, 100), content="0.0%")
inspect(format_percentage(0, 100), content="0.00%")
}

///|
test "format_percentage hundred of hundred" {
inspect(format_percentage(100, 100), content="100.0%")
inspect(format_percentage(100, 100), content="100.00%")
}

///|
Expand All @@ -55,12 +65,24 @@ test "format_percentage one third" {

///|
test "format_percentage fifty percent" {
inspect(format_percentage(50, 100), content="50.0%")
inspect(format_percentage(50, 100), content="50.00%")
}

///|
test "format_percentage single-digit fraction is zero-padded" {
// 661 / 2000 * 100 = 33.05%
inspect(format_percentage(661, 2000), content="33.05%")
}

///|
test "format_percentage whole zero single-digit fraction is zero-padded" {
// 1 / 2000 * 100 = 0.05%
inspect(format_percentage(1, 2000), content="0.05%")
}

///|
test "format_rps zero" {
inspect(format_rps(0.0), content="0.0")
inspect(format_rps(0.0), content="0.00")
}

///|
Expand All @@ -70,17 +92,27 @@ test "format_rps fractional" {

///|
test "format_rps large whole number" {
inspect(format_rps(1000.0), content="1000.0")
inspect(format_rps(1000.0), content="1000.00")
}

///|
test "format_rps two decimal places" {
inspect(format_rps(99.99), content="99.98")
}

///|
test "format_rps single-digit fraction is zero-padded" {
inspect(format_rps(8.05), content="8.05")
}

///|
test "format_rps whole zero single-digit fraction is zero-padded" {
inspect(format_rps(0.05), content="0.05")
}

///|
test "format_time zero" {
inspect(format_time(0.0), content="0.0s")
inspect(format_time(0.0), content="0.00s")
}

///|
Expand All @@ -90,19 +122,31 @@ test "format_time 999ms" {

///|
test "format_time 1000ms exact second" {
inspect(format_time(1000.0), content="1.0s")
inspect(format_time(1000.0), content="1.00s")
}

///|
test "format_time 60000ms" {
inspect(format_time(60000.0), content="60.0s")
inspect(format_time(60000.0), content="60.00s")
}

///|
test "format_time 100ms" {
inspect(format_time(100.0), content="0.10s")
}

///|
test "format_time single-digit fraction is zero-padded (61.05s regression)" {
// 61050ms = 61.05s; must not render as "61.5s"
inspect(format_time(61050.0), content="61.05s")
}

///|
test "format_time whole zero single-digit fraction is zero-padded" {
// 50ms = 0.05s
inspect(format_time(50.0), content="0.05s")
}

///|
test "format_double zero" {
inspect(format_double(0.0), content="0.00")
Expand Down
Loading