Skip to content

Commit 75d5d1c

Browse files
more tests on scaling
1 parent bddd13a commit 75d5d1c

File tree

2 files changed

+11
-1
lines changed

2 files changed

+11
-1
lines changed

test/Project.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
[deps]
22
DataStructures = "864edb3b-99cc-5e75-8d2d-829cb0a9cfe8"
3+
Dates = "ade2ca70-3891-5945-98fb-dc099432e06a"
34
GRIBDatasets = "82be9cdb-ee19-4151-bdb3-b400788d9abc"
45
NCDatasets = "85f8d34a-cbdd-5861-8df4-14fed0d494ab"
56
Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40"

test/test_scaling.jl

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ using NCDatasets
22
using Test
33
import CommonDataModel as CDM
44
using DataStructures
5+
using Dates
56

67
fname = tempname()
78
ds = NCDataset(fname,"c")
@@ -50,10 +51,12 @@ struct MemoryDataset <: CDM.AbstractDataset
5051
unlimited::Vector{String}
5152
end
5253

53-
data = randn(30,31)
54+
data = rand(-100:100,30,31)
5455
mv = MemoryVariable("data",["lon","lat"], data, OrderedDict{String,Any}(
5556
"units" => "days since 2000-01-01"))
5657

58+
Base.getindex(v::MemoryVariable,ij...) = v.data[ij...]
59+
Base.setindex!(v::MemoryVariable,data,ij...) = v.data[ij...] = data
5760
CDM.name(v::MemoryVariable) = v.name
5861
CDM.dimnames(v::MemoryVariable) = v.dimnames
5962
Base.size(v::MemoryVariable) = size(v.data)
@@ -81,6 +84,12 @@ CDM.attribnames(md::Union{MemoryDataset,MemoryVariable}) = keys(md.attrib)
8184
CDM.attrib(md::Union{MemoryDataset,MemoryVariable},name::AbstractString) = md.attrib[name]
8285

8386

87+
time_origin = DateTime(2000,1,1)
88+
@test md["data"][1,1] == time_origin + Dates.Millisecond(data[1,1]*24*60*60*1000)
89+
90+
md["data"][1,2] = DateTime(2000,2,1)
91+
@test md["data"].var[1,2] == Dates.value(md["data"][1,2] - time_origin) ÷ (24*60*60*1000)
92+
8493
io = IOBuffer()
8594
CDM.show(io,md)
8695
@test occursin("Attributes",String(take!(io)))

0 commit comments

Comments
 (0)