词频统计器(测试)
在网上学习了vs测试,发现都是以类为单位来测试类中的方法、属性。
然而我的四则运算代码,没有类,是照着C的风格写的。
于是我将代码中需要测试的方法 在测试类中进行重写。
测试有点牵强。
测试目标:是否从文章中能够提取出单词
测试代码:
#include "stdafx.h"
using namespace System;
using namespace System::Text;
using namespace System::Collections::Generic;
using namespace Microsoft::VisualStudio::TestTools::UnitTesting;
namespace TestProject2
{
[TestClass]
public ref class UnitTest
{
private:
TestContext^ testContextInstance;
public:
property Microsoft::VisualStudio::TestTools::UnitTesting::TestContext^ TestContext
{
Microsoft::VisualStudio::TestTools::UnitTesting::TestContext^ get()
{
return testContextInstance;
}
System::Void set(Microsoft::VisualStudio::TestTools::UnitTesting::TestContext^ value)
{
testContextInstance = value;
}
};
#pragma region Additional test attributes
#pragma endregion
[TestMethod]
void TestMethod1()
{
char text[1000] = { "How are you? I am fun thank you ,and you" };
int i = 0;
while (text[i] != '\0')
{
char s[30];
int j = 0;
while ((text[i] >= 'a'&&text[i] <= 'z') || (text[i] >= 'A'&&text[i] <= 'Z') || text[i] == '-')
{
if (text[i] >= 'A'&&text[i] <= 'Z')
text[i] += 'a' - 'A';
s[j++] = text[i++];
}
Assert::IsNotNull(s[j]);
s[j] = '\0';
if (text[i] == '\0')
break;
else
i++;
}
};
};
}
测试结果:

浙公网安备 33010602011771号