Unverified Commit 7ab78e4a authored by hrbrmstr's avatar hrbrmstr 🛌 Committed by GitHub
Browse files

Merge pull request #3 from amoeba/issue-2-bestunits

Add a function for displaying speed test results with nice units
parents 0147ca84 69c87fd4
......@@ -5,7 +5,9 @@ Version: 0.1.0
Date: 2017-11-09
Authors@R: c(
person("Bob", "Rudis", email = "bob@rud.is", role = c("aut", "cre"),
comment = c(ORCID = "0000-0001-5670-2640"))
comment = c(ORCID = "0000-0001-5670-2640")),
person("Bryce", "Mecum", email = "petridish@gmail.com", role = "ctb",
comment = c(ORCID = "0000-0002-0381-3766"))
)
Author: Bob Rudis (bob@rud.is)
Maintainer: Bob Rudis <bob@rud.is>
......
......@@ -32,11 +32,11 @@ spd_test <- function() {
cat(white$bold("Analyzing download speed"))
down <- spd_download_test(best, config, FALSE, timeout=5, .progress="dots")
cat(green("Download: ") %+% white$bold(as.integer(max(down$bw))) %+% white$bold(" Mbit/s\n"))
cat(green("Download: ") %+% white$bold(nice_speed(max(down$bw))) %+% "\n")
cat(white$bold("\nAnalyzing upload speed"))
up <- spd_upload_test(best, config, FALSE, timeout=10, .progress="dots")
cat(green("Upload: ") %+% white$bold(as.integer(max(up$bw))) %+% white$bold(" Mbit/s\n"))
cat(green("Upload: ") %+% white$bold(nice_speed(max(up$bw))) %+% "\n")
}
......@@ -30,3 +30,21 @@ sPOST <- purrr::safely(httr::POST)
query=list(ts=as.numeric(Sys.time())) # try to bust transparent proxy caches
)
}
#' Convert a test speed, in Mbits/s, to its string representation along with
#' appropriate units for the magnitude of the test speed
#'
#' - Assumes number is in Mbits/s to start off with
#' - Only chooses between Kbit/s, Mbit/s, and Gbit/s
#'
#' @param number numeric The speed to be converted
#' @return character The character representation of the speed
nice_speed <- function(number) {
if (number < 1) {
return(as.character(as.integer(number * 1000)) %+% " Kbit/s")
} else if (number >= 1000) {
return(as.character(as.integer(number / 1000)) %+% " Gbit/s")
} else {
return(as.character(as.integer(number)) %+% " Mbit/s")
}
}
......@@ -4,3 +4,9 @@ test_that("we can do something", {
#expect_that(some_function(), is_a("data.frame"))
})
test_that("speeds are displayed in appropriate units", {
expect_match(nice_speed(0.1), "Kbit/s")
expect_match(nice_speed(1), "Mbit/s")
expect_match(nice_speed(1000), "Gbit/s")
})
\ No newline at end of file
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment