<commit_before>#include "gtest/gtest.h"
#include "cantera/thermo/FixedChemPotSSTP.h"
#include "cantera/thermo/ThermoFactory.h"
#include "cantera/base/ctml.h"

namespace Cantera
{

class FixedChemPotSstpConstructorTest : public testing::Test
{
};

TEST_F(FixedChemPotSstpConstructorTest, fromXML)
{
    ThermoPhase* p = newPhase("../data/LiFixed.xml", "");
    ASSERT_EQ((int) p->nSpecies(), 1);
    double mu;
    p->getChemPotentials(&mu);
    ASSERT_FLOAT_EQ(-2.3e7, mu);
    delete p;
}

TEST_F(FixedChemPotSstpConstructorTest, SimpleConstructor)
{
    FixedChemPotSSTP p("Li", -2.3e7);
    ASSERT_EQ((int) p.nSpecies(), 1);
    double mu;
    p.getChemPotentials(&mu);
    ASSERT_FLOAT_EQ(-2.3e7, mu);
}

#ifndef HAS_NO_PYTHON // skip these tests if the Python converter is unavailable
class InputFileConversionTest : public testing::Test
{
public:
    InputFileConversionTest() {
        appdelete();
    }

    ThermoPhase* p1;
    ThermoPhase* p2;
    void compare()
    {
        ASSERT_EQ(p1->nSpecies(), p2->nSpecies());
        for (size_t i = 0; i < p1->nSpecies(); i++) {
            ASSERT_EQ(p1->speciesName(i), p2->speciesName(i));
            ASSERT_EQ(p1->molecularWeight(i), p2->molecularWeight(i));
        }
    }
};

TEST_F(InputFileConversionTest, ExplicitConversion) {
    p1 = newPhase("../data/air-no-reactions.xml", "");
    ctml::ct2ctml("../data/air-no-reactions.cti");
    p2 = newPhase("air-no-reactions.xml", "");
    compare();
}

TEST_F(InputFileConversionTest, ImplicitConversion) {
    p1 = newPhase("../data/air-no-reactions.xml", "");
    p2 = newPhase("../data/air-no-reactions.cti", "");
    compare();
}
#endif

} // namespace Cantera<commit_msg>[ck2cti] Add tests calling ck2cti from C++<commit_after>#include "gtest/gtest.h"
#include "cantera/thermo/FixedChemPotSSTP.h"
#include "cantera/thermo/ThermoFactory.h"
#include "cantera/base/ctml.h"
#include <fstream>

namespace Cantera
{

class FixedChemPotSstpConstructorTest : public testing::Test
{
};

TEST_F(FixedChemPotSstpConstructorTest, fromXML)
{
    ThermoPhase* p = newPhase("../data/LiFixed.xml", "");
    ASSERT_EQ((int) p->nSpecies(), 1);
    double mu;
    p->getChemPotentials(&mu);
    ASSERT_FLOAT_EQ(-2.3e7, mu);
    delete p;
}

TEST_F(FixedChemPotSstpConstructorTest, SimpleConstructor)
{
    FixedChemPotSSTP p("Li", -2.3e7);
    ASSERT_EQ((int) p.nSpecies(), 1);
    double mu;
    p.getChemPotentials(&mu);
    ASSERT_FLOAT_EQ(-2.3e7, mu);
}

#ifndef HAS_NO_PYTHON // skip these tests if the Python converter is unavailable
class CtiConversionTest : public testing::Test
{
public:
    CtiConversionTest() {
        appdelete();
    }

    ThermoPhase* p1;
    ThermoPhase* p2;
    void compare()
    {
        ASSERT_EQ(p1->nSpecies(), p2->nSpecies());
        for (size_t i = 0; i < p1->nSpecies(); i++) {
            ASSERT_EQ(p1->speciesName(i), p2->speciesName(i));
            ASSERT_EQ(p1->molecularWeight(i), p2->molecularWeight(i));
        }
    }
};

TEST_F(CtiConversionTest, ExplicitConversion) {
    p1 = newPhase("../data/air-no-reactions.xml", "");
    ctml::ct2ctml("../data/air-no-reactions.cti");
    p2 = newPhase("air-no-reactions.xml", "");
    compare();
}

TEST_F(CtiConversionTest, ImplicitConversion) {
    p1 = newPhase("../data/air-no-reactions.xml", "");
    p2 = newPhase("../data/air-no-reactions.cti", "");
    compare();
}

class ChemkinConversionTest : public testing::Test {
public:
    void copyInputFile(const std::string& name) {
        std::string in_name = "../data/" + name;
        std::ifstream source(in_name.c_str(), std::ios::binary);
        std::ofstream dest(name.c_str(), std::ios::binary);
        dest << source.rdbuf();
    }
};

TEST_F(ChemkinConversionTest, ValidConversion) {
    copyInputFile("pdep-test.inp");
    ctml::ck2cti("pdep-test.inp");
    ThermoPhase* p = newPhase("pdep-test.cti", "");
    ASSERT_GT(p->temperature(), 0.0);
}

TEST_F(ChemkinConversionTest, FailedConversion) {
    copyInputFile("h2o2_missingThermo.inp");
    ASSERT_THROW(ctml::ck2cti("h2o2_missingThermo.inp"),
                 CanteraError);
}


#endif

} // namespace Cantera
{'fraction_non_alphanumeric': 0.16670705112672643, 'fraction_numerical': 0.015023019142234069, 'mean_word_length': 3.632996632996633, 'pattern_counts': {'":': 0, '<': 8, '<?xml version=': 0, '>': 23, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 8}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4208257', 'n_tokens_mistral': 1583, 'n_tokens_neox': 1518, 'n_words': 236}