<commit_before>/*
 *
 * GAMS - General Algebraic Modeling System C++ API
 *
 * Copyright (c) 2017 GAMS Software GmbH <<EMAIL>>
 * Copyright (c) 2017 GAMS Development Corp. <<EMAIL>>
 *
 * Permission is hereby granted, free of charge, to any person obtaining a copy
 * of this software and associated documentation files (the "Software"), to deal
 * in the Software without restriction, including without limitation the rights
 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
 * copies of the Software, and to permit persons to whom the Software is
 * furnished to do so, subject to the following conditions:
 *
 * The above copyright notice and this permission notice shall be included in all
 * copies or substantial portions of the Software.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
 * SOFTWARE.
 */

#include "gamscheckpoint.h"
#include "gamsmodelinstance.h"
#include "gamsoptions.h"
#include "gamsparameter.h"
#include "gamsvariable.h"
#include "testgamsmodelinstance.h"

using namespace gams;

QString TestGAMSModelInstance::classname()  { return "TestGAMSModelInstance"; }

void TestGAMSModelInstance::testDefaultConstructor()  {
     GAMSModelInstance mi;
     QVERIFY( ! mi.isValid() );
     GAMSModifier mod;

     QVERIFY_EXCEPTION_THROWN( mi.name(), GAMSException );
     QVERIFY_EXCEPTION_THROWN( mi.copyModelInstance(), GAMSException );
     QVERIFY_EXCEPTION_THROWN( mi.instantiate("solve", mod), GAMSException );
     QVERIFY_EXCEPTION_THROWN( mi.interrupt(), GAMSException );
     QVERIFY_EXCEPTION_THROWN( mi.syncDb(), GAMSException );
     QVERIFY_EXCEPTION_THROWN( mi.solve(), GAMSException );
     QVERIFY_EXCEPTION_THROWN( mi.checkpoint(), GAMSException );
     QVERIFY_EXCEPTION_THROWN( mi.modelStatus(), GAMSException );
     QVERIFY_EXCEPTION_THROWN( mi.solveStatus(), GAMSException );
     QVERIFY_EXCEPTION_THROWN( mi.solveStatusAsString(), GAMSException );
     QVERIFY_EXCEPTION_THROWN( mi.logID(), GAMSException );

     GAMSModelInstance anothermi;
     QVERIFY( ! anothermi.isValid() );
     QVERIFY( anothermi == mi );

     anothermi = mi;
     QVERIFY( ! anothermi.isValid() );
     QVERIFY( mi == anothermi );
}

void TestGAMSModelInstance::testAssignmentOperator()  {
    // given
    GAMSWorkspaceInfo wsInfo;
    GAMSWorkspace ws(wsInfo);
    GAMSModelInstance mi1 = ws.addCheckpoint().addModelInstance();

    GAMSModelInstance mi2 = mi1;
    QVERIFY( mi2 == mi1 );

    GAMSModelInstance mi3;
    mi1 = mi3;
    QVERIFY( mi1 == mi3 );
    QVERIFY( mi1 != mi2 );
}

void TestGAMSModelInstance::testEqualToOperator()  {
    // given
    GAMSWorkspaceInfo wsInfo;
    GAMSWorkspace ws(wsInfo);
    GAMSModelInstance mi1 = ws.addCheckpoint().addModelInstance();

    GAMSModelInstance mi2 = mi1;
    QVERIFY( mi2 == mi1 );

    GAMSModelInstance mi3;
    mi1 = mi3;
    QVERIFY( mi1 == mi3 );
}

void TestGAMSModelInstance::testNotEqualToOperator()  {
    // given
    GAMSWorkspaceInfo wsInfo;
    GAMSWorkspace ws(wsInfo);
    GAMSCheckpoint cp = ws.addCheckpoint("mycp");
    GAMSModelInstance mi1 = cp.addModelInstance();

    GAMSModelInstance mi2 = cp.addModelInstance();
    QVERIFY( mi2 != mi1 );

    GAMSModelInstance mi3 = ws.addCheckpoint().addModelInstance();
    QVERIFY( mi1 != mi3 );
}


void TestGAMSModelInstance::testIsValid()  {
    // given
    GAMSWorkspaceInfo wsInfo;
    GAMSWorkspace ws(wsInfo);
    GAMSCheckpoint cp = ws.addCheckpoint();
    // when, then
    QVERIFY( cp.isValid() );
}

void TestGAMSModelInstance::testGetSyncDb()  {
    // given
    GAMSWorkspaceInfo wsInfo;
    GAMSWorkspace ws(wsInfo);
    GAMSCheckpoint cp = ws.addCheckpoint();

    GAMSModelInstance mi = cp.addModelInstance();
    // when, then
    QCOMPARE( mi.syncDb().getNrSymbols(), 0);

    GAMSParameter bmult = mi.syncDb().addParameter("bmult", 0, "demand multiplier");
    // when, then
    QCOMPARE( mi.syncDb().getNrSymbols(), 1);
    QVERIFY( mi.syncDb().getParameter("bmult") == bmult );
}

void TestGAMSModelInstance::testInstantiate_data()  { getTestData(); }
void TestGAMSModelInstance::testInstantiate()  {
    QFETCH(double, modifier);

    // given
    GAMSWorkspaceInfo wsInfo;
    GAMSWorkspace ws(wsInfo);
    GAMSCheckpoint cp = ws.addCheckpoint();
    ws.addJobFromString(getModelText()).run(cp);

    GAMSModelInstance mi = cp.addModelInstance();
    GAMSParameter bmult = mi.syncDb().addParameter("bmult", 0, "demand multiplier");
    GAMSOptions opt = ws.addOptions();
    opt.setAllModelTypes("cplexd");
    // when, then
    try {
       mi.instantiate("transport use lp min z", opt, GAMSModifier(bmult));
       bmult.addRecord().setValue( modifier );
       mi.solve();
    } catch(GAMSException) { QVERIFY(false); }
}

void TestGAMSModelInstance::testInstantiateBeforeInitializingCP()  {
    // given
    GAMSWorkspaceInfo wsInfo;
    GAMSWorkspace ws(wsInfo);
    GAMSCheckpoint cp = ws.addCheckpoint();
    ws.addJobFromString(getModelText());

    GAMSModelInstance mi = cp.addModelInstance();
    GAMSParameter bmult = mi.syncDb().addParameter("bmult", 0, "demand multiplier");
    GAMSOptions opt = ws.addOptions();
    opt.setAllModelTypes("cplexd");
    // when, then
    QVERIFY_EXCEPTION_THROWN( mi.instantiate("transport use lp min z",  opt, GAMSModifier(bmult)) ,
                              GAMSException );
}

void TestGAMSModelInstance::testSolve_data() { getTestData(); }

void TestGAMSModelInstance::testSolve()  {
    QFETCH(double, modifier);
    QFETCH(int, SolveStatus);
    QFETCH(int, ModelStatus);
    QFETCH(double, obj);

    // given
    GAMSWorkspaceInfo wsInfo;
    GAMSWorkspace ws(wsInfo);
    GAMSCheckpoint cp = ws.addCheckpoint();
    ws.addJobFromString(getModelText()).run(cp);

    GAMSModelInstance mi = cp.addModelInstance();

    GAMSParameter bmult = mi.syncDb().addParameter("bmult", 0, "demand multiplier");
    GAMSOptions opt = ws.addOptions();
    opt.setAllModelTypes("cplexd");

    mi.instantiate("transport use lp min z", opt, GAMSModifier(bmult));
    bmult.addRecord().setValue( modifier );

    // when
    mi.solve();
    // then
    QVERIFY( mi.solveStatus() == SolveStatus );
    QVERIFY( mi.modelStatus() == ModelStatus );
    QVERIFY( equals( mi.syncDb().getVariable("z").findRecord().level(), obj) );
}

void TestGAMSModelInstance::testSolveBeforeInstantiate()  {
    // given
    GAMSWorkspaceInfo wsInfo;
    GAMSWorkspace ws(wsInfo);
    GAMSCheckpoint cp = ws.addCheckpoint();
    GAMSModelInstance mi = cp.addModelInstance();
    // when, then
    QVERIFY_EXCEPTION_THROWN( mi.solve(), GAMSException);

    ws.addJobFromString(getModelText()).run(cp);
    mi = cp.addModelInstance();
    // when, then
    QVERIFY_EXCEPTION_THROWN( mi.solve(), GAMSException);
}

void TestGAMSModelInstance::testGetModelSolveStatus_data() { getTestData(); }

void TestGAMSModelInstance::testGetModelSolveStatus()  {
    QFETCH(double, modifier);
    QFETCH(int, SolveStatus);
    QFETCH(QString, SolveStatusStr);
    QFETCH(int, ModelStatus);
    QFETCH(QString, ModelStatusStr);

    // given
    GAMSWorkspaceInfo wsInfo;
    GAMSWorkspace ws(wsInfo);
    GAMSCheckpoint cp = ws.addCheckpoint();
    ws.addJobFromString(getModelText()).run(cp);

    GAMSModelInstance mi = cp.addModelInstance();
    GAMSParameter bmult = mi.syncDb().addParameter("bmult", 0, "demand multiplier");
    GAMSOptions opt = ws.addOptions();
    opt.setAllModelTypes("cplexd");

    mi.instantiate("transport use lp min z", opt, GAMSModifier(bmult));
    bmult.addRecord().setValue( modifier );

    // when
    mi.solve();
    // then
    QVERIFY( mi.solveStatus() == SolveStatus );
    QCOMPARE( QString::fromStdString(mi.solveStatusAsString()).trimmed(), SolveStatusStr );
    QVERIFY( mi.modelStatus() == ModelStatus );
    QCOMPARE( QString::fromStdString(mi.modelStatusAsString()).trimmed(), ModelStatusStr );
}

void TestGAMSModelInstance::testCopyModelInstance() {
    // given
    GAMSWorkspaceInfo wsInfo;
    GAMSWorkspace ws(wsInfo);
    GAMSCheckpoint cp = ws.addCheckpoint();
    ws.addJobFromString(getModelText()).run(cp);

    GAMSModelInstance mi = cp.addModelInstance();
    GAMSParameter bmult = mi.syncDb().addParameter("bmult", 0, "demand multiplier");
    mi.instantiate("transport use lp min z", GAMSModifier(bmult));

    // when
    GAMSModelInstance newmi = mi.copyModelInstance("new transport mi");
    // then
    QVERIFY( newmi.isValid() );
    QCOMPARE( mi.syncDb().getNrSymbols(), newmi.syncDb().getNrSymbols() );
    QCOMPARE( newmi.syncDb().getParameter("bmult").numberRecords(), mi.syncDb().getParameter("bmult").numberRecords() );
}

void TestGAMSModelInstance::testGetCheckpoint()  {
    // given
    GAMSWorkspaceInfo wsInfo;
    GAMSWorkspace ws(wsInfo);
    GAMSCheckpoint cp = ws.addCheckpoint();
    GAMSModelInstance mi = cp.addModelInstance();
    // when, then
    QCOMPARE( mi.checkpoint(), cp);
}

void TestGAMSModelInstance::testGetName()  {
    // given
    GAMSWorkspaceInfo wsInfo;
    GAMSWorkspace ws(wsInfo);
    GAMSCheckpoint cp = ws.addCheckpoint();

    // when, then
    std::string cpname = "mycp";
    GAMSModelInstance mi1 = cp.addModelInstance(cpname);
    QCOMPARE( mi1.name(), cpname );

    // when, then
    GAMSModelInstance mi2 = cp.addModelInstance("");
    QVERIFY( mi2.name().find(defaultScratchFilePrefix) == 0 );

    // when, then
    GAMSModelInstance mi3 = cp.addModelInstance();
    QVERIFY( mi3.name().find(defaultScratchFilePrefix) == 0 );

    // when, then
    GAMSModelInstance mi4 = cp.addModelInstance();
    QVERIFY( mi4.name().find(defaultScratchFilePrefix) == 0 );
    QVERIFY( mi4.name() != mi3.name() );
}

void TestGAMSModelInstance::testGetLogID()  {
     // given
     GAMSWorkspaceInfo wsInfo;
     GAMSWorkspace ws(wsInfo);
     GAMSCheckpoint cp = ws.addCheckpoint();
     std::string cpname = "mycp";
     GAMSModelInstance mi1 = cp.addModelInstance(cpname);
     GAMSModelInstance mi2 = mi1;

     // when, then
     QCOMPARE( mi2.logID(), mi1.logID() );
     QVERIFY( mi1.logID()== mi2.logID() );

     GAMSCheckpoint cp3 = ws.addCheckpoint("mycp");
     GAMSModelInstance mi3 = cp3.addModelInstance();
     QVERIFY( mi3.logID() == mi1.logID());

     GAMSWorkspaceInfo anotherWsInfo;
     GAMSWorkspace anotherws(anotherWsInfo);
     GAMSCheckpoint cp4 = anotherws.addCheckpoint("mycp");
     GAMSModelInstance mi4 = cp4.addModelInstance();
     QVERIFY( mi4.logID() == anotherws.logID());
     QVERIFY( mi4.logID() != mi3.logID());
}
<commit_msg>TestGAMSModelInstance test updated.<commit_after>/*
 *
 * GAMS - General Algebraic Modeling System C++ API
 *
 * Copyright (c) 2017 GAMS Software GmbH <<EMAIL>>
 * Copyright (c) 2017 GAMS Development Corp. <<EMAIL>>
 *
 * Permission is hereby granted, free of charge, to any person obtaining a copy
 * of this software and associated documentation files (the "Software"), to deal
 * in the Software without restriction, including without limitation the rights
 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
 * copies of the Software, and to permit persons to whom the Software is
 * furnished to do so, subject to the following conditions:
 *
 * The above copyright notice and this permission notice shall be included in all
 * copies or substantial portions of the Software.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
 * SOFTWARE.
 */

#include "gamscheckpoint.h"
#include "gamsmodelinstance.h"
#include "gamsoptions.h"
#include "gamsparameter.h"
#include "gamsvariable.h"
#include "testgamsmodelinstance.h"

using namespace gams;

QString TestGAMSModelInstance::classname()  { return "TestGAMSModelInstance"; }

void TestGAMSModelInstance::testDefaultConstructor()  {
     GAMSModelInstance mi;
     QVERIFY( ! mi.isValid() );
     GAMSModifier mod;

     QVERIFY_EXCEPTION_THROWN( mi.name(), GAMSException );
     QVERIFY_EXCEPTION_THROWN( mi.copyModelInstance(), GAMSException );
     QVERIFY_EXCEPTION_THROWN( mi.instantiate("solve", mod), GAMSException );
     QVERIFY_EXCEPTION_THROWN( mi.interrupt(), GAMSException );
     QVERIFY_EXCEPTION_THROWN( mi.syncDb(), GAMSException );
     QVERIFY_EXCEPTION_THROWN( mi.solve(), GAMSException );
     QVERIFY_EXCEPTION_THROWN( mi.checkpoint(), GAMSException );
     QVERIFY_EXCEPTION_THROWN( mi.modelStatus(), GAMSException );
     QVERIFY_EXCEPTION_THROWN( mi.solveStatus(), GAMSException );
     QVERIFY_EXCEPTION_THROWN( mi.solveStatusAsString(), GAMSException );
     QVERIFY_EXCEPTION_THROWN( mi.logID(), GAMSException );

     GAMSModelInstance anothermi;
     QVERIFY( ! anothermi.isValid() );
     QVERIFY( anothermi == mi );

     anothermi = mi;
     QVERIFY( ! anothermi.isValid() );
     QVERIFY( mi == anothermi );
}

void TestGAMSModelInstance::testAssignmentOperator()  {
    // given
    GAMSWorkspaceInfo wsInfo;
    GAMSWorkspace ws(wsInfo);
    GAMSModelInstance mi1 = ws.addCheckpoint().addModelInstance();

    GAMSModelInstance mi2 = mi1;
    QVERIFY( mi2 == mi1 );

    GAMSModelInstance mi3;
    mi1 = mi3;
    QVERIFY( mi1 == mi3 );
    QVERIFY( mi1 != mi2 );
}

void TestGAMSModelInstance::testEqualToOperator()  {
    // given
    GAMSWorkspaceInfo wsInfo;
    GAMSWorkspace ws(wsInfo);
    GAMSModelInstance mi1 = ws.addCheckpoint().addModelInstance();

    GAMSModelInstance mi2 = mi1;
    QVERIFY( mi2 == mi1 );

    GAMSModelInstance mi3;
    mi1 = mi3;
    QVERIFY( mi1 == mi3 );
}

void TestGAMSModelInstance::testNotEqualToOperator()  {
    // given
    GAMSWorkspaceInfo wsInfo;
    GAMSWorkspace ws(wsInfo);
    GAMSCheckpoint cp = ws.addCheckpoint("mycp");
    GAMSModelInstance mi1 = cp.addModelInstance();

    GAMSModelInstance mi2 = cp.addModelInstance();
    QVERIFY( mi2 != mi1 );

    GAMSModelInstance mi3 = ws.addCheckpoint().addModelInstance();
    QVERIFY( mi1 != mi3 );
}


void TestGAMSModelInstance::testIsValid()  {
    // given
    GAMSWorkspaceInfo wsInfo;
    GAMSWorkspace ws(wsInfo);
    GAMSCheckpoint cp = ws.addCheckpoint();
    // when, then
    QVERIFY( cp.isValid() );
}

void TestGAMSModelInstance::testGetSyncDb()  {
    // given
    GAMSWorkspaceInfo wsInfo;
    GAMSWorkspace ws(wsInfo);
    GAMSCheckpoint cp = ws.addCheckpoint();

    GAMSModelInstance mi = cp.addModelInstance();
    // when, then
    QCOMPARE( mi.syncDb().getNrSymbols(), 0);

    GAMSParameter bmult = mi.syncDb().addParameter("bmult", 0, "demand multiplier");
    // when, then
    QCOMPARE( mi.syncDb().getNrSymbols(), 1);
    QVERIFY( mi.syncDb().getParameter("bmult") == bmult );
}

void TestGAMSModelInstance::testInstantiate_data()  { getTestData(); }
void TestGAMSModelInstance::testInstantiate()  {
    QFETCH(double, modifier);

    // given
    GAMSWorkspaceInfo wsInfo;
    GAMSWorkspace ws(wsInfo);
    GAMSCheckpoint cp = ws.addCheckpoint();
    ws.addJobFromString(getModelText()).run(cp);

    GAMSModelInstance mi = cp.addModelInstance();
    GAMSParameter bmult = mi.syncDb().addParameter("bmult", 0, "demand multiplier");
    GAMSOptions opt = ws.addOptions();
    opt.setAllModelTypes("cplexd");
    // when, then
    try {
       mi.instantiate("transport use lp min z", opt, GAMSModifier(bmult));
       bmult.addRecord().setValue( modifier );
       mi.solve();
    } catch(GAMSException) { QVERIFY(false); }
}

void TestGAMSModelInstance::testInstantiateBeforeInitializingCP()  {
    // given
    GAMSWorkspaceInfo wsInfo;
    GAMSWorkspace ws(wsInfo);
    GAMSCheckpoint cp = ws.addCheckpoint();
    ws.addJobFromString(getModelText());

    GAMSModelInstance mi = cp.addModelInstance();
    GAMSParameter bmult = mi.syncDb().addParameter("bmult", 0, "demand multiplier");
    GAMSOptions opt = ws.addOptions();
    opt.setAllModelTypes("cplexd");
    // when, then
    QVERIFY_EXCEPTION_THROWN( mi.instantiate("transport use lp min z",  opt, GAMSModifier(bmult)) ,
                              GAMSException );
}

void TestGAMSModelInstance::testSolve_data() { getTestData(); }

void TestGAMSModelInstance::testSolve()  {
    QFETCH(double, modifier);
    QFETCH(int, SolveStatus);
    QFETCH(int, ModelStatus);
    QFETCH(double, obj);

    // given
    GAMSWorkspaceInfo wsInfo;
    GAMSWorkspace ws(wsInfo);
    GAMSCheckpoint cp = ws.addCheckpoint();
    ws.addJobFromString(getModelText()).run(cp);

    GAMSModelInstance mi = cp.addModelInstance();

    GAMSParameter bmult = mi.syncDb().addParameter("bmult", 0, "demand multiplier");
    GAMSOptions opt = ws.addOptions();
    opt.setAllModelTypes("cplexd");

    mi.instantiate("transport use lp min z", opt, GAMSModifier(bmult));
    bmult.addRecord().setValue( modifier );

    // when
    mi.solve();
    // then
    QVERIFY( mi.solveStatus() == SolveStatus );
    QVERIFY( mi.modelStatus() == ModelStatus );
    QVERIFY( equals( mi.syncDb().getVariable("z").findRecord().level(), obj) );
}

void TestGAMSModelInstance::testSolveBeforeInstantiate()  {
    // given
    GAMSWorkspaceInfo wsInfo;
    GAMSWorkspace ws(wsInfo);
    GAMSCheckpoint cp = ws.addCheckpoint();
    GAMSModelInstance mi = cp.addModelInstance();
    // when, then
    QVERIFY_EXCEPTION_THROWN( mi.solve(), GAMSException);

    ws.addJobFromString(getModelText()).run(cp);
    mi = cp.addModelInstance();
    // when, then
    QVERIFY_EXCEPTION_THROWN( mi.solve(), GAMSException);
}

void TestGAMSModelInstance::testGetModelSolveStatus_data() { getTestData(); }

void TestGAMSModelInstance::testGetModelSolveStatus()  {
    QFETCH(double, modifier);
    QFETCH(int, SolveStatus);
    QFETCH(QString, SolveStatusStr);
    QFETCH(int, ModelStatus);
    QFETCH(QString, ModelStatusStr);

    // given
    GAMSWorkspaceInfo wsInfo;
    GAMSWorkspace ws(wsInfo);
    GAMSCheckpoint cp = ws.addCheckpoint();
    ws.addJobFromString(getModelText()).run(cp);

    GAMSModelInstance mi = cp.addModelInstance();
    GAMSParameter bmult = mi.syncDb().addParameter("bmult", 0, "demand multiplier");
    GAMSOptions opt = ws.addOptions();
    opt.setAllModelTypes("cplexd");

    mi.instantiate("transport use lp min z", opt, GAMSModifier(bmult));
    bmult.addRecord().setValue( modifier );

    // when
    mi.solve();
    // then
    QVERIFY( mi.solveStatus() == SolveStatus );
    QCOMPARE( QString::fromStdString(mi.solveStatusAsString()).trimmed(), SolveStatusStr );
    QVERIFY( mi.modelStatus() == ModelStatus );
    QCOMPARE( QString::fromStdString(mi.modelStatusAsString()).trimmed(), ModelStatusStr );
}

void TestGAMSModelInstance::testCopyModelInstance() {
    // given
    GAMSWorkspaceInfo wsInfo;
    GAMSWorkspace ws(wsInfo);
    GAMSCheckpoint cp = ws.addCheckpoint();
    ws.addJobFromString(getModelText()).run(cp);

    GAMSModelInstance mi = cp.addModelInstance();
    GAMSParameter bmult = mi.syncDb().addParameter("bmult", 0, "demand multiplier");
    mi.instantiate("transport use lp min z", GAMSModifier(bmult));

    // when
    GAMSModelInstance newmi = mi.copyModelInstance("new transport mi");
    // then
    QVERIFY( newmi.isValid() );
    QCOMPARE( mi.syncDb().getNrSymbols(), newmi.syncDb().getNrSymbols() );
    QCOMPARE( newmi.syncDb().getParameter("bmult").numberRecords(), mi.syncDb().getParameter("bmult").numberRecords() );
}

void TestGAMSModelInstance::testGetCheckpoint()  {
    // given
    GAMSWorkspaceInfo wsInfo;
    GAMSWorkspace ws(wsInfo);
    GAMSCheckpoint cp = ws.addCheckpoint();
    GAMSModelInstance mi = cp.addModelInstance();
    // when, then
    QCOMPARE( mi.checkpoint(), cp);
}

void TestGAMSModelInstance::testGetName()  {
    // given
    GAMSWorkspaceInfo wsInfo;
    GAMSWorkspace ws(wsInfo);
    GAMSCheckpoint cp = ws.addCheckpoint();

    // when, then
    std::string cpname = "mycp";
    GAMSModelInstance mi1 = cp.addModelInstance(cpname);
    QCOMPARE( mi1.name(), cpname );

    // when, then
    GAMSModelInstance mi2 = cp.addModelInstance("");
    QVERIFY( mi2.name().find(defaultScratchFilePrefix) == 0 );

    // when, then
    GAMSModelInstance mi3 = cp.addModelInstance();
    QVERIFY( mi3.name().find(defaultScratchFilePrefix) == 0 );

    // when, then
    GAMSModelInstance mi4 = cp.addModelInstance();
    QVERIFY( mi4.name().find(defaultScratchFilePrefix) == 0 );
    QVERIFY( mi4.name() != mi3.name() );
}

void TestGAMSModelInstance::testGetLogID()  {
     // given
     GAMSWorkspaceInfo wsInfo;
     GAMSWorkspace ws(wsInfo);
     GAMSCheckpoint cp = ws.addCheckpoint();
     std::string cpname = "mycp";
     GAMSModelInstance mi1 = cp.addModelInstance(cpname);
     GAMSModelInstance mi2 = mi1;
     // when, then
     QVERIFY( mi1.logID() == mi2.logID() );

     GAMSCheckpoint cp3 = ws.addCheckpoint(cpname);
     GAMSModelInstance mi3 = cp3.addModelInstance();
     QVERIFY( mi3.logID() == mi1.logID());

     GAMSWorkspaceInfo anotherWsInfo;
     GAMSWorkspace anotherWs(anotherWsInfo);
     GAMSCheckpoint cp4 = anotherWs.addCheckpoint(cpname);
     GAMSModelInstance mi4 = cp4.addModelInstance();
     QVERIFY(mi4.logID() == anotherWs.logID());
     QVERIFY(mi4.logID() != mi3.logID());
}

{'fraction_non_alphanumeric': 0.12323862853995501, 'fraction_numerical': 0.006884839583237711, 'mean_word_length': 3.941710138353368, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 11, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7146168', 'n_tokens_mistral': 7523, 'n_tokens_neox': 7099, 'n_words': 1519}