我有Visual Studio 2015.我想用NuGet Package Manager为C#项目添加NUnit的测试,我希望有可能在VS和VS中运行测试.
首先我创建新的C#项目:文件 - >新建 - >项目 - >>已安装 - >模板 - > Visual C# - >>控制台应用程序 - >>确定
然后我安装NUnit:工具 - > NuGet包管理器 - >管理解决方案的NuGet包...然后我安装包:
在输出中我看到:
Successfully installed 'NUnit 3.0.0-beta-4' to Tmp.
Successfully installed 'NUnit.Runners 2.6.4' to Tmp.
Successfully installed 'NUnitTestAdapter 2.0.0' to Tmp.
Run Code Online (Sandbox Code Playgroud)
然后我使用下面的代码:
namespace NUnit.Tests
{
using System;
using NUnit.Framework;
[TestFixture]
public class Tests
{
[Test]
public void t1() …
Run Code Online (Sandbox Code Playgroud) 在C++参考中,我发现了有关C++中允许的属性语法的信息,它是:
[[attribute-list]]
[[ using attribute-namespace : attribute-list ]]
Run Code Online (Sandbox Code Playgroud)
"其中attribute-list是一个逗号分隔的零个或多个属性的序列(可能以省略号结尾...表示包扩展)"
我试过用它,但我发现之间没有区别:
[[deprecated]] void f()
{
}
Run Code Online (Sandbox Code Playgroud)
和
[[deprecated...]] void f()
{
}
Run Code Online (Sandbox Code Playgroud)
在这两种情况下输出都是相同的.
我正在开发一个现有程序的更新.我正在用boost :: program_options替换Posix的getopt_long().但是我的工作并没有像我应该的那样工作:我希望阅读如下的论点:
-server=www.example.com
-c config.txt
Run Code Online (Sandbox Code Playgroud)
我尝试了boost :: program_options :: command_line_style的许多可能性,但是我找不到能够使行为等于getopt_long的组合.
我发现了这个论点:
-server=www.example.com
Run Code Online (Sandbox Code Playgroud)
我需要旗帜:
command_line_style::allow_long_disguise | command_line_style::long_allow_adjacent
Run Code Online (Sandbox Code Playgroud)
但我有建立标志的问题:
-c config.txt
Run Code Online (Sandbox Code Playgroud)
我找到了旗帜:
command_line_style::allow_short | command_line_style::allow_dash_for_short | command_line_style::short_allow_next
Run Code Online (Sandbox Code Playgroud)
给我几乎我想要的东西.几乎是因为:
ProgramOptionsParserTest.cpp:107: Failure
Value of: params.config
Actual: " config.txt"
Expected: expectedParams.config
Which is: "config.txt"
Run Code Online (Sandbox Code Playgroud)
所以在使用boost :: algorithm :: trim()后,它将是我想要的.
所以我的问题是:是否可以使用boost :: program_options处理像-c config.txt这样的参数但没有boost :: algorithm :: trim()?
编辑 我注意到上面的标志不适用于未注册的参数.我有注册选项:
programOptionsDescription.add_options()
("help,h", "display help message")
("config,c", value<std::string>(), "use configfile")
("server,s", value<std::string>(), "server")
("ipport,p", value<uint16_t>(), "server port");
Run Code Online (Sandbox Code Playgroud)
但是当我使用未注册的选项时(是的,我有basic_command_line_parser :: allow_unregistered()):
-calibration=something
Run Code Online (Sandbox Code Playgroud)
我知道了:
the argument ('alibration=something') for …
Run Code Online (Sandbox Code Playgroud) 我想以最短的代码方式计算字符串中的所有数字.我试过这样的方式:
#include <string>
#include <algorithm>
unsigned countNumbers(const std::string s) {
return count_if(s.begin(), s.end(), isdigit);
}
Run Code Online (Sandbox Code Playgroud)
错误信息是:
a.cc: In function ‘unsigned int countNumbers(std::string)’:
a.cc:5:45: error: no matching function for call to ‘count_if(std::basic_string<char>::const_iterator, std::basic_string<char>::const_iterator, <unresolved overloaded function type>)’
a.cc:5:45: note: candidate is:
/usr/include/c++/4.6/bits/stl_algo.h:4607:5: note: template<class _IIter, class _Predicate> typename std::iterator_traits<_InputIterator>::difference_type std::count_if(_IIter, _IIter, _Predicate)
Run Code Online (Sandbox Code Playgroud)
我知道count_if()想要的函数如下:bool(*f)(char); 作为第三个参数,所以我试图强制转换函数:
unsigned countNumbers(const std::string s) {
return count_if(s.begin(), s.end(), reinterpret_cast<bool (*)( char )>(isdigit));
}
Run Code Online (Sandbox Code Playgroud)
错误信息是:
a.cc: In function ‘unsigned int countNumbers(std::string)’:
a.cc:5:80: error: overloaded function with no contextual …
Run Code Online (Sandbox Code Playgroud) 差不多2天我仍然有同样的问题 - 客户端和服务器"对话",但我不知道为什么在通信过程中突然出现问题.我尝试了很多东西,不幸的是仍然是同样的问题.
我在Windows 7上使用python 2.7.5.
我的代码: cs_common.py
import socket
import os
import sys
import errno
from time import sleep
HOST = 'localhost'
MY_IP = socket.gethostbyname(socket.gethostname())
PORT = 50007
timeout_in_seconds = 2
def createSocket4server(host, port):
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.bind((host, port))
s.listen(4)
return s
def createSocket4Client(host, port, timeout_in_seconds=3):
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.connect( (host, port) )
print 'connected to %s port %s' % (host, port)
return s
sent = 0
def sendToSocket(socket_, data): # to debug
global sent
print sent, …
Run Code Online (Sandbox Code Playgroud) 我在C99中找到了可变长度数组,但看起来它的行为与malloc + free几乎相同.
我找到的实际差异:
太大的阵列处理:
unsigned size = 4000000000;
int* ptr = malloc(size); // ptr is 0, program doesn't crash
int array[size]; // segmentation fault, program crashes
Run Code Online (Sandbox Code Playgroud)内存泄漏:只能在动态数组分配中使用:
int* ptr = malloc(size);
...
if(...)
return;
...
free(ptr);
Run Code Online (Sandbox Code Playgroud)对象的生命和从函数返回的可能性:动态分配的数组生命直到内存释放,并且可以从分配内存的函数返回.
调整大小:仅使用指向已分配内存的指针调整大小.
我的问题是:
我在Windows 7上安装了Microsoft Visual Studio 2013社区版.我想以比下载标题和二进制文件或自行编译更新的方式为C++安装gtest和gmock.
我找到了Tools> Nuget Package Manager> Manage Nugets Packages for Solution我选择了Online,然后输入gtest.从搜索结果中我发现了Google Test,所以我已经为我当前的项目安装了它.安装后,下面的代码编译:
#include <iostream>
#include <gtest\gtest.h>
using namespace std;
using namespace ::testing;
int factorian(int n)
{
if (n == 0 || n == 1)
return 1;
else
return n*factorian(n - 1);
}
TEST(factorianTest, simpleTest)
{
ASSERT_EQ(1, factorian(0));
ASSERT_EQ(1, factorian(1));
ASSERT_EQ(2, factorian(2));
}
int main(int argc, char* argv[])
{
InitGoogleTest(&argc, argv);
return RUN_ALL_TESTS();
}
Run Code Online (Sandbox Code Playgroud)
但它没有链接:
错误1错误LNK2019:未解析的外部符号"bool __cdecl testing :: internal :: IsTrue(bool)"(?IsTrue @ internal @ testing @@ YA_N_N …
我想做这样的事情:
TEST(MyTestFixture, printAfterExpectationFailure)
{
const string request("bring me tea");
const string&& response = sendRequestAndGetResponse(request);
checkResponseWithExpectarions1(response);
checkResponseWithExpectarions2(response);
checkResponseWithExpectarions3(response);
checkResponseWithExpectarions4(response);
if (anyOfExpectsFailed())
cout << "Request: " << request << "\nresponse: " << response << endl;
}
TEST(MyTestFixture, printAfterAssertionFailure)
{
const string request("bring me tea");
const string&& response = sendRequestAndGetResponse(request);
doWhenFailure([&request, &response]()
{
cout << "Request: " << request << "\nresponse: " << response << endl;
});
checkResponseWithAssertion1(response);
checkResponseWithAssertion2(response);
checkResponseWithAssertion3(response);
checkResponseWithAssertion4(response);
}
Run Code Online (Sandbox Code Playgroud)
我仅在期望/断言失败时才打印一些其他信息。
我知道我可以做这样的事情:
#define MY_ASSERT_EQ(lhr, rhs, message) if(lhs != rhs) ASSERT_EQ(lhs, rhs) …
Run Code Online (Sandbox Code Playgroud) 我的任务是显示指定的文本,例如"dummy123".但问题是我不能既不使用"也不能"做那样的事情.正如我所知,在Java中没有像预处理器那样
#define W(x) #x;
Run Code Online (Sandbox Code Playgroud)
如何使用没有引号的代码:
public class A
{
public static void main(String[] args)
{
System.out.println("dummy123");
}
}
Run Code Online (Sandbox Code Playgroud) 我正在为一些下载依赖项的项目安装依赖项vcpkg
(该项目是 Hyperledger Iroha,但这并不重要)。不幸的是,当使用我的编译器(g++ 12.1.0)编译依赖项时,其中一个包(abseil)无法编译。
它不编译的原因很容易在代码中修复 - 只需更改一行。
\n该线由cmake
:
CMake Error at scripts/cmake/vcpkg_execute_build_process.cmake:146 (message):\n Command failed: /usr/bin/cmake --build . --config Debug --target install -- -v -j13\n Working Directory: /home/agh/Pulpit/blockchain/internship2022/iroha/vcpkg-build/buildtrees/abseil/x64-linux-dbg\n See logs for more information:\n /home/agh/Pulpit/blockchain/internship2022/iroha/vcpkg-build/buildtrees/abseil/install-x64-linux-dbg-out.log\n
Run Code Online (Sandbox Code Playgroud)\n错误是:
\n/home/agh/Pulpit/blockchain/internship2022/iroha/vcpkg-build/buildtrees/abseil/src/ca9688e9f6-e4cda1d679.clean/absl/debugging/failure_signal_handler.cc:139:32: error: no matching function for call to \xe2\x80\x98max(long int, int)\xe2\x80\x99\n 139 | size_t stack_size = (std::max(SIGSTKSZ, 65536) + page_mask) & ~page_mask;\n | ~~~~~~~~^~~~~~~~~~~~~~~~~\nIn file included from /usr/include/c++/12.1.0/algorithm:60,\n
Run Code Online (Sandbox Code Playgroud)\n原因很容易修复 - 我只需要更改一行即可解决此问题。\n不幸的是,当我更改代码行并重新运行后:
\nvcpkg install abseil\n …
Run Code Online (Sandbox Code Playgroud) c++ ×6
googletest ×2
algorithm ×1
arrays ×1
assert ×1
assertions ×1
attributes ×1
boost ×1
c ×1
c# ×1
c99 ×1
casting ×1
client ×1
cmake ×1
dependencies ×1
ellipsis ×1
expectations ×1
free ×1
function ×1
getopt-long ×1
java ×1
linker ×1
malloc ×1
nuget ×1
nunit ×1
python ×1
sockets ×1
string ×1
tcp ×1
vcpkg ×1