-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #9 from IainNZ/v07
Update Humanize.jl to Julia v0.7, refactor.
- Loading branch information
Showing
6 changed files
with
132 additions
and
163 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,17 +1,10 @@ | ||
language: julia | ||
os: | ||
- linux | ||
- osx | ||
julia: | ||
- 0.4 | ||
- 0.5 | ||
- 0.6 | ||
- 0.7 | ||
- nightly | ||
notifications: | ||
email: false | ||
sudo: false | ||
script: | ||
- if [[ -a .git/shallow ]]; then git fetch --unshallow; fi | ||
- julia -e 'Pkg.clone(pwd()); Pkg.test("Humanize"; coverage=true)' | ||
after_success: | ||
- julia -e 'cd(Pkg.dir("Humanize")); Pkg.add("Coverage"); using Coverage; Codecov.submit(process_folder())' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,2 @@ | ||
julia 0.4 | ||
julia 0.7-beta | ||
Dates |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,101 +1,86 @@ | ||
using Humanize | ||
using Base.Test | ||
import Dates | ||
using Test | ||
import Humanize | ||
|
||
function test_datasize() | ||
println("test_datasize") | ||
@testset "Humanize" begin | ||
|
||
tests = [300, 3000, 3000000, 3000000000, 3000000000000, 1e26, 3141592] | ||
results = Dict( :dec => ["450.000 B", "4.500 kB", "4.500 MB", "4.500 GB", "4.500 TB", "150.000 YB", "4.712 MB"], | ||
:bin => ["630.000 B", "6.152 KiB", "6.008 MiB", "5.867 GiB", "5.730 TiB", "173.708 YiB", "6.292 MiB"], | ||
:gnu => ["480.000", "4.688K", "4.578M", "4.470G", "4.366T", "132.349Y", "4.794M"]) | ||
for (style,mult) in [(:dec,1.5), (:bin,2.1), (:gnu, 1.6)] | ||
println(" $style") | ||
for i in 1:length(tests) | ||
size = tests[i] * mult | ||
@test datasize(size,style=style,format="%.3f") == results[style][i] | ||
@testset "datasize" begin | ||
VALUES = [300, 3000, 3000000, 3000000000, 3000000000000, 1e26, 3141592] | ||
MULTIPLIERS = Dict(:dec => 1.5, :bin => 2.1, :gnu => 1.6) | ||
RESULTS = Dict( | ||
:dec => ["450.000 B", "4.500 kB", "4.500 MB", "4.500 GB", "4.500 TB", "150.000 YB", "4.712 MB"], | ||
:bin => ["630.000 B", "6.152 KiB", "6.008 MiB", "5.867 GiB", "5.730 TiB", "173.708 YiB", "6.292 MiB"], | ||
:gnu => ["480.000", "4.688K", "4.578M", "4.470G", "4.366T", "132.349Y", "4.794M"] | ||
) | ||
@testset "$style" for style in (:dec, :bin, :gnu) | ||
for (value, result) in zip(VALUES, RESULTS[style]) | ||
size = value * MULTIPLIERS[style] | ||
@test Humanize.datasize(size, style=style, format="%.3f") == result | ||
end | ||
end | ||
end | ||
end # testset datasize. | ||
|
||
@testset "timedelta" begin | ||
# Years, months, days, hours, minutes, seconds, result. | ||
DATA = [((0, 0, 0, 0, 0, 0), "a moment"), | ||
((0, 0, 0, 0, 0, 1), "a second"), | ||
((0, 0, 0, 0, 0, 30), "30 seconds"), | ||
((0, 0, 0, 0, 1, 30), "a minute"), | ||
((0, 0, 0, 0, 2, 0), "2 minutes"), | ||
((0, 0, 0, 1, 30, 30), "an hour"), | ||
((0, 0, 0, 23, 50, 50), "23 hours"), | ||
((0, 0, 1, 0, 0, 0), "a day"), | ||
((0, 0, 500, 0, 0, 0), "1 year, 4 months"), | ||
((0, 0, 365*2 + 35, 0, 0, 0), "2 years"), | ||
((0, 0, 10000, 0, 0, 0), "27 years"), | ||
((0, 0, 365 + 30, 0, 0, 0), "1 year, 1 month"), | ||
((0, 0, 365 + 4, 0, 0, 0), "a year"), | ||
((0, 0, 35, 0, 0, 0), "a month"), | ||
((0, 0, 65, 0, 0, 0), "2 months"), | ||
((0, 0, 9, 0, 0, 0), "9 days"), | ||
((0, 0, 365, 0, 0, 0), "a year")] | ||
|
||
function test_timedelta() | ||
println("test_timedelta") | ||
|
||
test = [(0,0,0,0,0,0), "a moment", | ||
(0,0,0,0,0,1), "a second", | ||
(0,0,0,0,0,30), "30 seconds", | ||
(0,0,0,0,1,30), "a minute", | ||
(0,0,0,0,2,0), "2 minutes", | ||
(0,0,0,1,30,30), "an hour", | ||
(0,0,0,23,50,50), "23 hours", | ||
(0,0,1,0,0,0), "a day", | ||
(0,0,500,0,0,0), "1 year, 4 months", | ||
(0,0,365*2+35,0,0,0), "2 years", | ||
(0,0,10000,0,0,0), "27 years", | ||
(0,0,365+30,0,0,0), "1 year, 1 month", | ||
(0,0,365+4,0,0,0), "a year", | ||
(0,0,35,0,0,0), "a month", | ||
(0,0,65,0,0,0), "2 months", | ||
(0,0,9,0,0,0), "9 days", | ||
(0,0,365,0,0,0), "a year"] | ||
n_test = div(length(test),2) | ||
|
||
#timedelta(years::Int,months::Int,days::Int,hours::Int,mins::Int,secs::Int) | ||
println(" direct") | ||
for i in 1:n_test | ||
@test timedelta(test[2i-1]...) == test[2i] | ||
end | ||
#timedelta(dt_diff::Dates.Millisecond) | ||
println(" DateTime diff") | ||
for i in 1:n_test | ||
offset = test[2i-1] | ||
@testset "datetime diff $output" for (inputs, output) in DATA | ||
base_datetime = Dates.DateTime(2014,1,1,0,0,0) | ||
new_datetime = Dates.Year(offset[1]) + base_datetime | ||
new_datetime += Dates.Month(offset[2]) | ||
new_datetime += Dates.Day(offset[3]) | ||
new_datetime += Dates.Hour(offset[4]) | ||
new_datetime += Dates.Minute(offset[5]) | ||
new_datetime += Dates.Second(offset[6]) | ||
@test timedelta(new_datetime-base_datetime) == test[2i] | ||
end | ||
#timedelta(d_diff::Dates.Day) | ||
println(" Date diff") | ||
for i in 1:n_test | ||
offset = test[2i-1] | ||
sum(offset[1:3]) == 0 && continue | ||
base_date = Dates.Date(2014,1,1) | ||
new_date = Dates.Year(offset[1]) + base_date | ||
new_date += Dates.Month(offset[2]) | ||
new_date += Dates.Day(offset[3]) | ||
@test timedelta(new_date-base_date) == test[2i] | ||
new_datetime = Dates.Year(inputs[1]) + base_datetime | ||
new_datetime += Dates.Month(inputs[2]) | ||
new_datetime += Dates.Day(inputs[3]) | ||
new_datetime += Dates.Hour(inputs[4]) | ||
new_datetime += Dates.Minute(inputs[5]) | ||
new_datetime += Dates.Second(inputs[6]) | ||
@test Humanize.timedelta(new_datetime - base_datetime) == output | ||
end | ||
end | ||
|
||
@testset "date diff $output" for (inputs, output) in DATA | ||
sum(inputs[1:3]) == 0 && continue # Hour-scale or less. | ||
base_date = Dates.Date(2014, 1, 1) | ||
new_date = Dates.Year(inputs[1]) + base_date | ||
new_date += Dates.Month(inputs[2]) | ||
new_date += Dates.Day(inputs[3]) | ||
@test Humanize.timedelta(new_date - base_date) == output | ||
end | ||
end # testset timedelta. | ||
|
||
function test_digitsep() | ||
println("test_digitsep") | ||
|
||
test = ( | ||
(1, "1"), | ||
@testset "digitsep" begin | ||
DATA = ((1, "1"), | ||
(12, "12"), | ||
(123, "123"), | ||
(1234, "1,234"), | ||
(12345, "12,345"), | ||
(123456, "123,456"), | ||
(1234567, "1,234,567"), | ||
(12345678, "12,345,678") | ||
) | ||
|
||
n_test = length(test) | ||
|
||
#digitsep(value::Integer) | ||
println(" direct") | ||
for t in test | ||
@test digitsep(t[1]) == t[2] | ||
(12345678, "12,345,678"), | ||
(-1, "-1"), | ||
(-12, "-12"), | ||
(-123, "-123"), | ||
(-1234, "-1,234"), | ||
(-12345, "-12,345"), | ||
(-123456, "-123,456"), | ||
(-1234567, "-1,234,567"), | ||
(-12345678, "-12,345,678")) | ||
@testset "digitsep $output" for (input, output) in DATA | ||
@test Humanize.digitsep(input) == output | ||
end | ||
|
||
end | ||
end # testset digitsep. | ||
|
||
test_datasize() | ||
test_timedelta() | ||
test_digitsep() | ||
end # testset Humanize. |