即时通讯这真的很烦人的错误信息.我知道我只是新手,但这似乎是我能想到的事情.任何人都可以告诉我哪里出错了吗?
运行时的消息是: Debug Assertion Failed!程序:....文件:c:\ program files\microsoft visual studio 10.0\vc\include\vector行:932表达式:向量下标超出范围
而代码是
#include "VectorIntStorage.h"
#include <iostream>
#include <fstream>
#include <string>
#include <vector>
#include <algorithm>
using namespace std;
void VectorIntStorage::Read(istream& r)
{
char c[13];
r >> c;
r >> NumberOfInts; //gets number of ints for vector
//numberVector = new std::vector<int> numberVector;
for(int i = 0; i < NumberOfInts; i++)
{
r >> numberVector[i];
cout << numberVector[i] << endl;
if(_sortRead) //true
{
for(int k = 0; k < i; k++)
{
if(numberVector[i] < …Run Code Online (Sandbox Code Playgroud) 我曾经在我的代码中插入java1.4的断言构造并发现它非常实用,因为它允许我在调试时启用插入的断言并在编译时禁用它们.
我的问题是:
是否可以对Guava库中的现代Preconditions.checkArgument(..)等做同样的事情?
这一点很重要.我们可能在代码中有大量的番石榴前置条件检查,但是大多数是用于调试目的,并且当这些前提条件的数量很快变大时可能会影响性能.
谢谢你的想法.
我的代码在MS VS 2012中编译后,接受输入,然后崩溃并使用以下报告:
Debug Assertion Failed!
...\include\xstring
Line:1662
Expression:string subscript out of range
Run Code Online (Sandbox Code Playgroud)
代码如下:
#include "stdafx.h"
#include <iostream>
#include <string>
#include <vector>
#include <cassert>
#include <time.h>
using namespace std;
const unsigned short MAX_STRINGS = 10;
const unsigned int MAX_SIZE=10000;
vector<string> strings;
unsigned int len;
string GetLongestCommonSubstring( string string1, string string2 );
inline void readNumberSubstrings();
inline const string getMaxSubstring();
void readNumberSubstrings()
{
cin >> len;
assert(len > 1 && len <=MAX_STRINGS);
strings.resize(len);
for(unsigned int i=0; i<len;i++)
strings[i]=string(MAX_SIZE,0);
for(unsigned int i=0; i<len; …Run Code Online (Sandbox Code Playgroud) 我在调试模式下运行我的代码,程序弹出一个断言失败的消息.请帮我找出导致此断言失败的部分.:{
Debug Assertion Failed!
Expression: vector iterators incompatible
Run Code Online (Sandbox Code Playgroud)
码:
int main()
{
vector<int> a(5);
fill(a.begin(), a.end(), 5);
a[2] = 3;
a[1] = 2; //so now a = {5,2,3,5,5}
auto it = a.begin();
for (; it != a.end();)
{
if (*it == 5)
a.erase(it); //Remove 5
else
it++;
}
copy(a.begin(), a.end(), ostream_iterator<int>(cout, "\n"));
}
Run Code Online (Sandbox Code Playgroud) 我有两个interface{}s a,b来自JSON解码和用户输入,让我们说:
var a interface{} = ...
var b interface{} = ...
Run Code Online (Sandbox Code Playgroud)
我知道他们是数字.它们可以是以下任何类型:
unit
unit8
uint16
uint32
uint64
int
int8
int16
int32
int64
float
float32
float64
Run Code Online (Sandbox Code Playgroud)
我写了一些测试代码如下.事实证明,当一个变量是int,它将失败并带有int64断言.
var a interface{} = 1
v, f := a.(int64)
fmt.Println(v, f) //0 false
v1, f1 := a.(int)
fmt.Println(v1, f1) //1 true
Run Code Online (Sandbox Code Playgroud)
所以现在我的问题如下:为了比较这两个数字,为了获得这两个interface{}变量的类型,我是否必须测试这些超过10种类型的所有排列?理想情况下,我只想将它们投射到int64或float64,但如果它们是int或者float,我将无法找到它们,直到用尽所有可能的类型.
我找到了JUnit 的解决方案,但找不到 TestNG 的解决方案。
我正在尝试使用 NUnit 为一种方法编写单元测试,该方法可能需要 1 到 3 秒才能完成。为了验证测试,我需要做的就是检查 aList<string> entries是否在 1 到 3 秒的跨度内增加。
我目前的解决方案是使用Thread.Sleep():
1. int currentEntries = entries.count;
2. Call methodA()
3. Thread.Sleep(3000);
4. int updatedEntries = entries.count;
5. Assert.That(updatedEntries, Is.EqualTo(currentEntries+1));
Run Code Online (Sandbox Code Playgroud)
此解决方案始终至少需要 3 秒,即使 methodA() 完成得更快。
我曾尝试使用 NUnits 延迟约束:
Assert.That(entries.Count, Is.EqualTo(currentEntries+1).After(3).Seconds.PollEvery(250).MilliSeconds);
Run Code Online (Sandbox Code Playgroud)
这本来是理想的,因为它支持轮询。但是After约束仍然会立即评估,而不是在 3 秒后评估,如这里所讨论的。
这个问题有更好的解决方案吗?
我正在用 JavaScript 编写邮递员测试来断言下面的场景。我有一个 id 1111,响应返回一个 id 数组。我想编写一个测试以将 1111 匹配到数组中的一个 id 中。
我曾尝试使用包含功能,即
pm.test("The response contains a valid id in the response", function() {
pm.expect(jsonData.results[0].totalId.children).to.include("1111");
});
Run Code Online (Sandbox Code Playgroud)
{
"totalId": "0000",
"children": [{
"id": "888"
},
{
"id": "3323"
},
{
"id": "1111"
}
]
}
Run Code Online (Sandbox Code Playgroud)
任何建议。
我正在将Robot Framework与Java配合使用。我的问题是:在Robot Framework中执行断言的最佳方法是什么?我应该导入JUnit(或类似的库)并在自己的关键字中使用if声明吗?
是否有一个用于断言的关键字库?我的意思是一个包含如下关键字的库:
Assert True &{value_to_check}
Assert List Contains &{list_of_elements} &{element_to_find} # using java equals method
Run Code Online (Sandbox Code Playgroud)
谢谢!
例如,如果我想断言值应该是 Value1 或 Value2(两者都可以接受):
It 'Value must match Value1 or Value2' {
$params.value | Should -be "Value1" || "Value2"
}`
Run Code Online (Sandbox Code Playgroud)
这是无效的语法 - 有没有办法用 Pester 做到这一点?