草庐IT

test_compare

全部标签

c++ - atomic_compare_exchange 大于而不是等于?

C++11对atomicvariables有一个“比较和交换”操作.语义是:Atomicallycomparesthevaluepointedtobyobjwiththevaluepointedtobyexpected,andifthoseareequal,replacestheformerwithdesired(performsread-modify-writeoperation).Otherwise,loadstheactualvaluepointedtobyobjinto*expected(performsloadoperation).我想做同样的事情,但不是在值相等时设置*ob

c++ - 如何让自定义运算符 == 与 Google Test 一起使用?

我在将自定义重载“==”运算符与PCL和GoogleTest(GTest)结合使用时遇到问题#includenamespacepcl{structPointXYZ;}booloperator==(pcl::PointXYZp1,pcl::PointXYZp2){returnp1.x-p2.xTEST(Foo,bar){pcl::PointXYZa{2,3,4};pcl::PointXYZPb{2,3,4};EXPECT_EQ(a,b);//Compileerrornomatchforoperator==}intmain(intargc,char**argv){testing::Init

c++ - atomic_compare_exchange 与互斥锁

用这样的block替换互斥锁有什么意义voidstack_push(stack*s,node*n){node*head;do{head=s->head;n->next=head;}while(!atomic_compare_exchange(s->head,head,n));}不明白用这个原子交换替换互斥量我们能得到什么好处? 最佳答案 有很多优点;速度很多(在Windows上,比如10倍或100倍-在Linux上没那么快,比如10%好)它可以更好地扩展MUCH(尽管仍然不够-只能扩展到大约100个逻辑核心)它MUCH更酷,而且你看

c++ - gtest 中对 testing::internal::EqFailure 的 undefined reference

我正在尝试使用GoogleTest对函数进行测试,现在它不再找到EqFailurething:/usr/include/gtest/gtest.h:1337:undefinedreferenceto`testing::internal::EqFailure(charconst*,charconst*,testing::internal::Stringconst&,testing::internal::Stringconst&,bool)'我正在这样写测试:test_file.cpp:#include#include"tools/CMorphology.hpp"TEST(erode_Mo

c++ - Test t; 之间有什么区别?和测试 t();?如果 Test 是一个类

这个问题在这里已经有了答案:关闭10年前。PossibleDuplicate:Whyistherenocalltotheconstructor?我正在使用VisualStudio2012,假设Test是一个类classTest{};当我创建一个新的Test实例时,下面两种方式有什么区别?方式一Testt;方式二Testt();我在下面的代码中遇到了这个问题,本来,我用方式2定义了一个A的实例,我只得到一个错误,因为B没有提供默认构造函数,但是当我用方式1定义它时,我得到了一个额外的错误。classB{B(inti){}};classA{A(){}Bb;};intmain(void){A

c++ - cppreference 中 atomic_compare_exchange_weak 的示例代码是否正确?

在http://en.cppreference.com/w/cpp/atomic/atomic_compare_exchange,以下示例代码作为std::atomic_compare_exchange_weak的示例使用:voidappend(list*s,node*n){node*head;do{head=s->head;n->next=head;}while(!std::atomic_compare_exchange_weak(s->head,head,n));}我的理解是这个有比较*(s->head)的效果与head,当我认为需要的是比较s->head与head.第一个参数应该

c++ - 在测试用例中获取 BOOST TEST 测试套件名称

我正在使用BOOSTTEST,我想知道是否有办法从测试用例中找到测试套件。我知道我可以通过以下方式找到测试用例的名称:boost::unit_test::framework::current_test_case().p_name还有办法找出套件名称吗?我的套件案例结构是:套件--->案例1______|-->案例2______|-->案例3谢谢 最佳答案 一个unit_test不仅有p_name还有p_parent_id,也就是测试套件的ID。这两个属性都继承自test_unit,它是unit_test和test_suite的公共(

c++ - 如何在 CppUnitTestFramework 中对具有 TEST_CLASS 的类使用继承

我有一个继承自另一个类的类,如下所示:classTestClass:publicBaseClass我想知道是否可以使用TEST_CLASS宏或作为C++的Microsoft单元测试框架一部分的其他宏将其作为测试类。我试过:classTEST_CLASS(TestClass:publicBaseClass)但是IDE给出了错误'Error:expectedeitheradefinitionoratagname'并且编译器错误是errorC3861:'__GetTestClassInfo':identifiernotfound我知道在测试类上继承可能是不好的做法,但它会使测试的实现更容易。

c++ - string::compare 确定字母顺序是否可靠?

简单地说,如果输入始终是相同的大小写(这里是小写),并且字符始终是ASCII,是否可以使用string::compare可靠地确定两个字符串的字母顺序?因此,对于stringA.compare(stringB),如果结果为0,则它们相同,如果为负数,则stringA按字母顺序排在stringB之前,如果为正数,则stringA排在stringB之后? 最佳答案 根据cplusplus.com上的文档,Thememberfunctionreturns0ifallthecharactersinthecomparedcontentscom

c++ - 错误 : out-of-line definition of 'test' does not match any declaration in 'B<dim>'

我有一个小问题让我很烦!!我不知道下面的代码似乎有什么问题。我应该能够实现从父类(superclass)继承的功能,不是吗?但我得到error:out-of-linedefinitionof'test'doesnotmatchanydeclarationin'B'templateclassA{public:virtualdoubletest()const;};templateclassB:publicA{};templatedoubleB::test()const{return0;}我在Mac上使用clang(AppleLLVM5.1版)。 最佳答案