Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
What's new
7
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Switch to GitLab Next
Sign in / Register
Toggle navigation
Open sidebar
hrbrmstr
speedtest
Commits
5d29d363
Unverified
Commit
5d29d363
authored
Nov 16, 2017
by
petridish
Browse files
Add a function for displaying speed test results with nice units
Closes
#2
parent
0147ca84
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
26 additions
and
2 deletions
+26
-2
R/test-main.r
R/test-main.r
+2
-2
R/util.r
R/util.r
+18
-0
tests/testthat/test-speedtest.R
tests/testthat/test-speedtest.R
+6
-0
No files found.
R/test-main.r
View file @
5d29d363
...
...
@@ -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"
)
}
R/util.r
View file @
5d29d363
...
...
@@ -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"
)
}
}
tests/testthat/test-speedtest.R
View file @
5d29d363
...
...
@@ -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
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment