QCumber 用于 KDB 中的单元测试

问题描述 投票:0回答:1

我正在尝试弄清楚如何使用

qcumber
单元测试库。

我有

src/ti.q

sma: {mavg[x; y]}; /simple moving average

tests/sma.quke

feature sma
    before
        inputData: 1 2 3 4 5 6 7 8 9 10;
        expectedOutput: 1 1.5 2 2.5 3 4 5 6 7 8;
        period: 5;
    should
        expect
            .qu.compare[expectedOutput; sma[period;inputData]]

我通过

q $AXLIBRARIES_HOME/ws/qcumber.q_ -src ./src/ti.q -test ./tests -color -showAll
运行测试,给出

Starting qCumber: q test runner

q)Loading src file: src/ti.q
Running tests: tests

file ti.quke
    feature sma
        (should)
            - fail | (expect)
                error: inputData (line 7)


Summary:
0 tests passed
0 benchmarks failed
1 tests failed
0 tests skipped

显然我的

tests/sma.quke
文件存在问题,但我无法弄清楚如何从 q(.qu) 的测试框架中的文档传递常量。如何让我的
expect
块查看
before
块中定义的变量(如果确实需要
block
)?

kdb
1个回答
0
投票

我不确定这是否是首选方法,但我有一些事情可以处理,

feature sma
    should
        expect
        inputData: 1 2 3 4 5 6 7 8 9 10;
        expectedOutput: 1 1.5 2 2.5 3 4 5 6 7 8;
        period: 5;
        .qu.compare[expectedOutput; sma[period;inputData]]
© www.soinside.com 2019 - 2024. All rights reserved.