今天我与一位同事讨论了是否要测试是否在课堂上测试私人成员或私人状态.他几乎让我相信为什么它有意义.这个问题的目的不是复制已经存在的关于测试私有成员的性质和原因的StackOverflow问题,例如:将单元测试作为正在测试的类的朋友有什么问题?
在我看来,同事的建议有点脆弱,将朋友声明介绍给单元测试实现课程.在我看来,这是一个禁忌,因为我们将测试代码的一些依赖性引入测试代码,而测试代码已经依赖于测试代码=>循环依赖.即使像重命名测试类这样无辜的事情也会导致破坏单元测试并在测试代码中强制执行代码更改.
我想请C++专家来判断另一个提案,它依赖于我们被允许专门化模板功能的事实.想象一下班级:
// tested_class.h
struct tested_class
{
tested_class(int i) : i_(i) {}
//some function which do complex things with i
// and sometimes return a result
private:
int i_;
};
Run Code Online (Sandbox Code Playgroud)
我不喜欢让i_的吸气剂让它变得可测试.所以我的提议是类中的'test_backdoor'函数模板声明:
// tested_class.h
struct tested_class
{
explicit
tested_class(int i=0) : i_(i) {}
template<class Ctx>
static void test_backdoor(Ctx& ctx);
//some function which do complex things with i
// and sometimes return a result
private:
int i_;
};
Run Code Online (Sandbox Code Playgroud)
通过添加这个函数,我们可以使类的私有成员可测试.注意,不依赖于单元测试类,也不依赖于模板函数实现.在此示例中,单元测试实现使用Boost Test框架.
// tested_class_test.cpp
namespace
{
struct ctor_test_context
{
tested_class& tc_;
int …Run Code Online (Sandbox Code Playgroud) 我目前在我的LaTeX文档中使用\ textnumero符号.因此,我需要包含'textcomp'包.这样做时我得到一个编译器错误说明:
!包textcomp错误:符号\ texnumero不是由
TS1编码中的(textcomp)字体系列ptm 提供的.
(textcomp)改为使用默认系列.
\usepackage[T1]{fontenc}
\usepackage{times}
\usepackage{ucs}
\usepackage[latin1]{inputenc}
\usepackage[textcomp]
%... somewhere in the document
\textnumero ...
Run Code Online (Sandbox Code Playgroud)
我怎样才能摆脱这条消息?我可以为数字符号设置其他字体或编码吗?
非常感谢,
Ovanes
尝试访问者模式和泛型方法我在C#.NET中发现了一种差异.AFAIK C#编译器更喜欢泛型方法的显式重载,因此以下代码:
public abstract class A
{
public abstract void Accept(Visitor v);
}
public class B : A
{
public override void Accept(Visitor v)
{ v.Visit(this); }
}
public class C : A
{
public override void Accept(Visitor v)
{ v.Visit(this); }
}
public class D : A
{
public override void Accept(Visitor v)
{ v.Visit(this); }
}
public class Visitor
{
public void Visit(B b)
{ Console.WriteLine("visiting B"); }
public void Visit(C c)
{ Console.WriteLine("visiting C"); }
public void …Run Code Online (Sandbox Code Playgroud) 我目前卡住了,有两个单独的词汇表:main&acronyms.Acronyms术语表在文本中首次使用时打印脚注,但main词汇表没有.是否有任何方法可以制作任何其他词汇表,而不是acronyms在首次使用该术语时打印脚注?我不明白怎么做.
以下是使用TeXnic Center和MiKTeX 2.7编译的代码示例:
\documentclass{article}
\usepackage{index}
\usepackage[toc,style=long3colheaderborder,footnote,acronym]{glossaries}
\makeindex
\makeglossaries
\newglossaryentry{appdomain}{name={application domain}, description={app Domain Description...}}
\newglossaryentry{sample}{name={[has been inserted aaa]},description={testing testing 123}}
\newacronym{aca}{aca}{a contrived acronym}
\begin{document}
\section{this is a test section}
This is the test line... a \gls{sample} \gls{appdomain}
\index{entry} and \gls{aca}
\thispagestyle{empty}\cleardoublepage
\printglossary[type=main,title={Glossary},toctitle={Glossary}]
\thispagestyle{empty}\cleardoublepage
\printglossary[type=\acronymtype,title={List of Abbreviations},toctitle={List of Abbreviations}]
\printindex
\thispagestyle{empty}\cleardoublepage
\end{document}
Run Code Online (Sandbox Code Playgroud)
我想样本和应用程序域包含脚注和说明或脚注说明:请参阅词汇表
非常感谢,
Ovanes
我在带有LLVM 3.2的Mac OS X 10.8上安装了最新版本的XCode.现在我想切换到llvm/clang 3.3.
在我目前的项目中,我使用CMake和clang 3.2以及libc ++,它们运行正常.
现在我以为我可以用自制软件切换.所以我做的是发出以下命令:
brew install llvm --with-clang --with-asan
Run Code Online (Sandbox Code Playgroud)
这个构建了新的clang并在/ usr/local/bin中更新了它.
使用以下参数运行cmake:
cmake -G "Unix Makefiles" -DCMAKE_BUILD_TYPE=Debug -DCMAKE_C_COMPILER=/usr/local/bin/clang -DCMAKE_CXX_COMPILER=/usr/local/bin/clang++ ../
Run Code Online (Sandbox Code Playgroud)
成功,我的CMake输出如下:
-- Compiler: Clang
-- CXX_FLAGS: -Wall -std=c++11 -stdlib=libc++
-- Boost version: 1.53.0
-- adding include directory: /usr/local/include
-- adding include directory: /usr/local/include
-- adding include directory: /usr/local/include
-- adding include directory: /usr/local/include
-- Boost version: 1.53.0
-- Found the following Boost libraries:
-- filesystem
-- system
-- exception
-- Boost version: 1.53.0
-- …Run Code Online (Sandbox Code Playgroud) 在C++中,这样的语句是有效的:
&Variable;
Run Code Online (Sandbox Code Playgroud)
IMO它没有任何意义,所以我的问题是,如果你这样做,它会以任何方式影响编译结果,还是编译器会优化它?
谢谢!
在C/C++中,我们可以在堆栈或堆上存储变量,函数,成员函数,类的实例.
每个如何实施?如何管理(高级别)?gcc是否预先分配了一大块内存用于堆栈和堆,然后根据请求发送?原始内存来自RAM吗?
可以在堆而不是堆栈上分配函数吗?
--Clarification--
Run Code Online (Sandbox Code Playgroud)
我真的在询问堆和堆栈存储器的实现和管理.在阅读引用的问题后,我找不到任何解决这个问题的方法......感谢链接
我是 Protocol Buffers 的新手,目前我看到以下问题:
我们将proto2语法与 Protocol Buffers 3.2.0 库一起使用,并观察到required在序列化期间未强制执行字段。
这是 Catch C++ 测试的基本示例:
syntax = "proto2";
package simple_test;
message SimpleMessage
{
required string field1 = 1;
required string field2 = 2;
}
Run Code Online (Sandbox Code Playgroud)
#include "simple.pb.h"
#include <catch.hpp>
#include <string>
SCENARIO("Verify that serialization with missing required fields fails", "[protobuf]")
{
GIVEN("a message")
{
simple_test::SimpleMessage m;
WHEN("field1 is set and field2 is not and both are required")
{
m.set_field1("aaa");
THEN("serializing this message to string buffer must fail")
{
std::string …Run Code Online (Sandbox Code Playgroud) c++ ×4
latex ×2
c ×1
c# ×1
clang ×1
footnotes ×1
generics ×1
glossaries ×1
heap-memory ×1
homebrew ×1
llvm ×1
macos ×1
members ×1
methods ×1
optimization ×1
overloading ×1
private ×1
protected ×1
reference ×1
stack-memory ×1
unit-testing ×1
upgrade ×1