-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathtest.nim
62 lines (56 loc) · 1.87 KB
/
test.nim
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
# Copyright 2016 UniCredit S.p.A.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
import unittest, teafiles, os, tables
type Tick = object
date: int64
price: float64
volume: int64
suite "reading files":
test "reading a file while knowing the type":
var f = teafile[Tick]("acme.tea")
echo f
f.close()
test "reading an untyped file":
var f = dynteafile("acme.tea")
echo f
echo "We can read fields dynamically, knowing the type: ", f[0]["Time", int64]
echo "...or even not knowing it: ", f[0]["Time"]
echo "We can also iterate over a single field:"
for price in f.col("Price", float64):
echo price
echo "Even without knowing the exact type:"
for price in f.floatcol("Price"):
echo price
f.close()
suite "writing files":
test "writing a file and reading it back":
var f = teafile[Tick]("acme.tea")
var w = create("acme2.tea", meta(f))
for tick in f:
append[Tick](w, tick)
w.close()
f.close()
var g = dynteafile("acme2.tea")
echo g
g.close()
removeFile("acme2.tea")
suite "metadata":
test "reading metadata from a file":
var f = teafile[Tick]("acme.tea")
let metadata = meta(f)
check metadata.content.description == "ACME at NYSE"
check metadata.namevalues.ints["decimals"] == 2
check metadata.time.ticksPerDay == 86400000
check metadata.items.fields[0].name == "Time"
f.close()