Exemple #1
0
    void Machinery::setup(const kerberos::StringMap & settings)
    {
        // -----------------------------------------------------------
        // Creates condition, algorithms, expositors, heuristics and io handlers.
        
        LINFO << "Starting conditions: " + settings.at("condition");
        std::vector<Condition *> conditions = Factory<Condition>::getInstance()->createMultiple(settings.at("condition"));
        for(int i = 0; i < conditions.size(); i++)
        {
            conditions[i]->setup(settings);
        }
        setCondition(conditions);

        LINFO << "Starting algorithm: " + settings.at("algorithm");
        Algorithm * algorithm = Factory<Algorithm>::getInstance()->create(settings.at("algorithm"));
        algorithm->setup(settings);
        setAlgorithm(algorithm);

        LINFO << "Starting expositor: " + settings.at("expositor");
        Expositor * expositor = Factory<Expositor>::getInstance()->create(settings.at("expositor"));
        expositor->setup(settings);
        setExpositor(expositor);

        LINFO << "Starting heuristic: " + settings.at("heuristic");
        Heuristic * heuristic = Factory<Heuristic>::getInstance()->create(settings.at("heuristic"));
        heuristic->setup(settings);
        setHeuristic(heuristic);  

        LINFO << "Starting io devices: " + settings.at("io");
        std::vector<Io *> ios = Factory<Io>::getInstance()->createMultiple(settings.at("io"));
        for(int i = 0; i < ios.size(); i++)
        {
            ios[i]->setup(settings);
        }
        setIo(ios);
    }
TEST(SEQUENCE_HEURISTIC, IS_VALID)
{
    Heuristic * heuristic = Factory<Heuristic>::getInstance()->create("Sequence");

    StringMap settings;
    settings["heuristics.Sequence.minimumChanges"] = "1";
    settings["heuristics.Sequence.minimumDuration"] = "2";
    settings["heuristics.Sequence.motionDelayTime"] = "1000";
    settings["heuristics.Sequence.noMotionDelayTime"] = "1000";
    heuristic->setup(settings);

    // ----------------------------
    // Mocking image

    Image image;
    ImageVector images;

    JSON json;
    JSON::AllocatorType& allocator = json.GetAllocator();

    json.SetObject();
    json.AddMember("numberOfChanges", 0, allocator);

    // --------------------
    // Nothing changed thus false.
    bool isValid = heuristic->isValid(image, images, json);
    EXPECT_EQ(false, isValid);

    // ---------------------
    // Changed, but this is only the first occurence thus again false.
    json.RemoveMember ("numberOfChanges");
    json.AddMember("numberOfChanges", 1, allocator);
    isValid = heuristic->isValid(image, images, json);
    EXPECT_EQ(false, isValid);

    // ---------------------
    // Changed and the second occurence thus true.
    isValid = heuristic->isValid(image, images, json);
    EXPECT_EQ(true, isValid);
}