zoukankan      html  css  js  c++  java
  • 词频统计器(测试)

    在网上学习了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] != '')
    			{
    				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] = '';
    				if (text[i] == '')
    					break;
    				else
    					i++;
    			}
    		};
    	};
    }
    

     测试结果:

  • 相关阅读:
    Python—模块
    Python之路_Day5
    Python之路_Day4
    Py获取本机指定网卡的ip地址
    Python之路_Day3
    Python之路—Day2作业
    Python之路—Day2
    Python之路—Day1作业
    Python之路—Day1
    Python数据类型
  • 原文地址:https://www.cnblogs.com/wangsen123/p/5909886.html
Copyright © 2011-2022 走看看