虽然这里有一个相同的问题,但我找不到我的问题的答案,所以这里提出我的问题:
我正在使用mocha和chai测试我的节点js应用程序.我正在使用sinion来包装我的功能.
describe('App Functions', function(){
let mockObj = sinon.stub(testApp, 'getObj', (dbUrl) => {
//some stuff
});
it('get results',function(done) {
testApp.someFun
});
}
describe('App Errors', function(){
let mockObj = sinon.stub(testApp, 'getObj', (dbUrl) => {
//some stuff
});
it('throws errors',function(done) {
testApp.someFun
});
}
Run Code Online (Sandbox Code Playgroud)
当我尝试运行此测试时,它给了我错误
Attempted to wrap getObj which is already wrapped
Run Code Online (Sandbox Code Playgroud)
我也尝试过
beforeEach(function () {
sandbox = sinon.sandbox.create();
});
afterEach(function () {
sandbox.restore();
});
Run Code Online (Sandbox Code Playgroud)
在每个描述中,但仍然给我同样的错误.
我正在尝试并行运行函数数组,当每个人都完成时我想要对该结果进行处理.我正在使用承诺.现在,我可以将所有函数放在一个数组中,并且可以做Promise.all(函数数组)但是我有类似的数组
[[promise1, promise2], [promise3,promise4], [promise5,promise6]],
Run Code Online (Sandbox Code Playgroud)
每个承诺都是承诺的功能.Promise参考文档说Promise.all中的参数应该是一个可迭代的对象,我的数组是可迭代的.但这对我不起作用.我认为它正在执行[promise1,promise2]作为承诺而不是个人承诺.
任何人都可以帮助我如何实现它,还是有更好的方法?
我正在使用https://github.com/go-redis/redis包进行 Redis DB 调用。对于单元测试,我想模拟这个调用,是否有任何模拟库或方法来做到这一点?
我试图解决问题,其中给出了一个整数数组,我需要找到给定数组中所有可能的元素对的总和.例如,数组是1,2,3,4那么它应该给1 + 2 + 1 + 3 + 1 + 4 + 2 + 3 + 2 + 4 + 3 + 4 = 30
现在,我尝试了不同的东西,但我不能带任何复杂度小于O(n ^ 2)的算法.有没有人对复杂度小于O(n ^ 2)的算法有所了解
我正在将我的代码转换为多线程到性能增强.
我有shared_ptr的向量和另一个类的对象,我从vector向量传递shared_ptr,并将对象作为参数传递给函数.我使用std :: async调用它,但它给了我以下错误:
line from where I am making async call : required from here
/usr/include/c++/4.8.2/functional1697.61: error: no type named 'type'
in 'class std::result_of<void (*(std::shared_ptr<A>, B))
(const std::shared_ptr<A>&, B&)>'typedef typename
result_of<_Callable(_Args...)>::type result_type;
Run Code Online (Sandbox Code Playgroud)
这是代码片段:
void foo(std::vector<std::shared_ptr<A>>& a, B b){
std::vector<std::future<void>> tasks;
for(auto& sptr : a ){
tasks.push_back(std::async(std::launch::async, foo1, a, b))
}
void foo1(const std::shared_ptr<A>& a, B& b ){
//do some stuff
}
Run Code Online (Sandbox Code Playgroud)
你能帮我么.谢谢
我已经在docker容器(Kubernetes)中安装了influxdb,并且已经在该容器上安装了持久卷。但是influxdb不会将数据写入该卷。任何人都可以告诉我步骤,以便influxdb写入特定容量的数据。谢谢
我正在使用这里的以下示例
考虑我有以下课程
#include <iostream>
class Distance {
private:
int feet;
int inches;
public:
Distance() : feet(), inches() {}
Distance(int f, int i) : feet(f), inches(i) {}
friend std::ostream &operator<<( std::ostream &output, const Distance &D )
{
output << "F : " << D.feet << " I : " << D.inches;
return output;
}
friend std::istream &operator>>( std::istream &input, Distance &D )
{
input >> D.feet >> D.inches;
return input;
}
};
Run Code Online (Sandbox Code Playgroud)
我正在使用 Gtest 来测试这个类。
但我找不到更好的方法来测试它。
我可以使用 gtest 中提供的宏ASSERT_NO_THROW …
c++ ×2
node.js ×2
algorithm ×1
arrays ×1
c++11 ×1
docker ×1
future ×1
go ×1
googletest ×1
influxdb ×1
javascript ×1
kubernetes ×1
mocking ×1
promise ×1
redis ×1
shared-ptr ×1
sinon ×1