zoukankan      html  css  js  c++  java
  • 2017秋软工

    要求1 对每个功能,先给出测试用例,然后再编码功能。请注意把测试用例视为功能需求完成的检验指标。

    要求2 在博客报告测试用例全部fail 到 全部pass 的过程,报告事实 (fail到修改代码或者测试用例,到pass) 以及收获。 除了最初的框架,测试用例中存在一次性pass没有经过fail的,也报告一次性通过,给出如此优秀地实现了这部分功能的代码。(40分)

    要求3 做好准备,在接下的一周你可能无法通过别人的测试用例。 (0分)

    要求4 使用coding.net做版本控制。checkin 前要求清理 临时文件、可执行程序,通常执行 build-clean可以达到效果。(5分)

    由于用堆栈进行后缀表达式的处理构造了很多函数,在这个单元测试过程中选取了主要的几个函数进行测试。

    测试代码:

    #include "stdafx.h"
    
    using namespace System;
    using namespace System::Text;
    using namespace System::Collections::Generic;
    using namespace Microsoft::VisualStudio::TestTools::UnitTesting;
    
    namespace TestProject1
    {
    [TestClass]
    public ref class UnitTest1
    {
    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;
            }
        };
    
    
        [TestMethod]
        double Operate( double a, unsigned char theta, double b )
        {
            switch ( theta )
            {
            case '+':
                return(a + b);
            case '-':
                return(a - b);
            case '*':
                return(a * b);
            case '/':
                return(a / b);
            default:
                return(0);
            }
        }
    
    
        [TestMethod]
        double GetAns( string str )
        {
            int    len;
            double    ans;
            len = str.length();
            char *num = new char[len];
            for ( int j = 0; j < len; j++ )
            {
                num[j] = str[j];
            }
            ans = EvaluateExpression( num );
            return(ans);
        }
    
    
        [TestMethod]
        double EvaluateExpression( char* MyExpression )
        {
            SC*OPTR = NULL;
            SF*OPND = NULL;
            char TempData[20];
            double Data, a, b;
            char theta, *c, Dr[] = { '#', '' };
            OPTR= Push( OPTR, '#' );
            c    = strcat( MyExpression, Dr );
            strcpy( TempData, "" );
            while ( *c != '#' || OPTR->c != '#' )
            {
                if ( !In( *c, OPSET ) )
                {
                    Dr[0] = *c;
                    strcat( TempData, Dr );
                    c++;
                    if ( In( *c, OPSET ) )
                    {
                        Data= atof( TempData );
                        OPND= Push( OPND, Data );
                        strcpy( TempData, "" );
                    }
                }
                else
                {
                    switch ( precede( OPTR->c, *c ) )
                    {
                    case '<':
                        OPTR = Push( OPTR, *c );
                        c++;
                        break;
                    case '=':
                        OPTR = Pop( OPTR );
                        c++;
                        break;
                    case '>':
                        theta= OPTR->c;
                        OPTR= Pop( OPTR );
                        b= OPND->f;
                        OPND= Pop( OPND );
                        a= OPND->f;
                        OPND= Pop( OPND );
                        OPND= Push( OPND, Operate( a, theta, b ) );
                        break;
                    }
                }
            }
            return(OPND->f);
        }
    }
    }
    View Code

    测试结果:

    版本控制:https://git.coding.net/137911934/ElementaryArithmetic.git

  • 相关阅读:
    HDU1720 A+B Coming
    HDU1390 ZOJ1383 Binary Numbers
    HDU1390 ZOJ1383 Binary Numbers
    HDU2504 又见GCD
    HDU2504 又见GCD
    HDU1335 POJ1546 UVA389 UVALive5306 ZOJ1334 Basically Speaking
    HDU1335 POJ1546 UVA389 UVALive5306 ZOJ1334 Basically Speaking
    HDU1020 ZOJ2478 Encoding
    HDU1020 ZOJ2478 Encoding
    HDU2097 Sky数
  • 原文地址:https://www.cnblogs.com/wangl009/p/7651361.html
Copyright © 2011-2022 走看看