electiontest.cpp

来自「一个语言识别引擎」· C++ 代码 · 共 59 行

CPP
59
字号
// -*- mode:C++; tab-width:4; c-basic-offset:4; indent-tabs-mode:nil -*-

/*
 * Copyright (C) 2006 Paul Fitzpatrick
 * CopyPolicy: Released under the terms of the GNU GPL v2.0.
 *
 */

#include <yarp/Election.h>

#include "TestList.h"

using namespace yarp;

class ElectionTest : public UnitTest {
public:
    virtual String getName() { return "ElectionTest"; }

    void testBasics() {
        report(0,"testing the basics of elections");
        String c1 = "Magnifico";
        String c2 = "Grasso";
        String c3 = "Bozo";
        ElectionOf<String> elector;
        elector.add("italy",&c1);
        elector.add("italy",&c2);
        elector.add("france",&c3);
        String *e1 = elector.getElect("italy");
        String *e2 = elector.getElect("france");
        checkTrue(e1!=NULL,"elected entity exists (1)");
        checkTrue(e2!=NULL,"elected entity exists (2)");
        if (e1!=NULL && e2!=NULL) {
            checkTrue((*e1==c1 || *e1==c2),"elected entity is accurate (1)");
            checkTrue(*e2==c3,"elected entity is accurate (2)");
        }
        elector.remove("italy",&c2);
        elector.remove("france",&c3);
        e1 = elector.getElect("italy");
        e2 = elector.getElect("france");
        checkTrue(e1!=NULL,"elected entity exists (1)");
        checkTrue(e2==NULL,"elected entity does not exist (2)");
        if (e1!=NULL) {
            checkTrue(*e1==c1,"elected entity is accurate (1)");
        }
    }


    virtual void runTests() {
        testBasics();
    }
};

static ElectionTest theElectionTest;

UnitTest& getElectionTest() {
    return theElectionTest;
}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?