Skip to content

Commit

Permalink
Add tests on short-term storage/thermal cluster/renewable cluster rem…
Browse files Browse the repository at this point in the history
…oval (#1841)

For the `enabled` property, we depend on a "removal" mechanism. We must
therefore check that this mechanism indeed works _ie_ removes disabled
objects while retaining enabled objects.
  • Loading branch information
flomnes authored Jan 2, 2024
1 parent fb0ff3a commit 2aca866
Showing 1 changed file with 82 additions and 10 deletions.
92 changes: 82 additions & 10 deletions src/tests/src/libs/antares/study/test_study.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ BOOST_AUTO_TEST_CASE(area_add)
const auto areaA = study.areaAdd("A");
BOOST_CHECK(areaA != nullptr);
BOOST_CHECK_EQUAL(areaA->name, "A");
BOOST_CHECK(areaA->id == "a");
BOOST_CHECK_EQUAL(areaA->id, "a");
}

BOOST_FIXTURE_TEST_CASE(area_rename, OneAreaStudy)
Expand All @@ -68,27 +68,99 @@ BOOST_FIXTURE_TEST_CASE(area_rename, OneAreaStudy)

BOOST_FIXTURE_TEST_CASE(area_delete, OneAreaStudy)
{
BOOST_CHECK(study.areas.size() == 1);
BOOST_CHECK_EQUAL(study.areas.size(), 1);
BOOST_CHECK(study.areaDelete(areaA));
BOOST_CHECK(study.areas.empty());
}

BOOST_AUTO_TEST_SUITE_END() //areas

// Check that disabled objects are indeed removed from computations
BOOST_AUTO_TEST_SUITE(remove_disabled)
BOOST_FIXTURE_TEST_CASE(thermal_cluster_delete, OneAreaStudy)
{
auto disabledCluster = std::make_shared<ThermalCluster>(areaA);
disabledCluster->setName("Cluster1");
disabledCluster->enabled = false;

areaA->thermal.list.add(disabledCluster);
// Check that "Cluster1" is found
BOOST_CHECK_EQUAL(areaA->thermal.list.find("cluster1"), disabledCluster.get());

study.initializeRuntimeInfos(); // This should remove all disabled thermal clusters
// Check that "Cluster1" isn't found
BOOST_CHECK_EQUAL(areaA->thermal.list.find("cluster1"), nullptr);
}

BOOST_FIXTURE_TEST_CASE(renewable_cluster_delete, OneAreaStudy)
{
auto disabledCluster = std::make_shared<RenewableCluster>(areaA);
disabledCluster->setName("Cluster1");
disabledCluster->enabled = false;

areaA->renewable.list.add(disabledCluster);
// Check that "Cluster1" is found
BOOST_CHECK_EQUAL(areaA->renewable.list.find("cluster1"), disabledCluster.get());

study.initializeRuntimeInfos(); // This should remove all disabled renewable clusters
// Check that "Cluster1" isn't found
BOOST_CHECK_EQUAL(areaA->renewable.list.find("cluster1"), nullptr);
}

BOOST_FIXTURE_TEST_CASE(short_term_storage_delete, OneAreaStudy)
{
auto& sts = areaA->shortTermStorage.storagesByIndex;

auto addSTS = [&sts](std::string&& name,
bool enabled)
{
ShortTermStorage::STStorageCluster cluster;
cluster.properties.name = name;
cluster.properties.enabled = enabled;
sts.push_back(cluster);
};

addSTS("Cluster1", true);
addSTS("Cluster2", false);

auto findDisabledCluster = [&sts](std::string&& name)
{
return std::find_if(sts.begin(),
sts.end(),
[&name](ShortTermStorage::STStorageCluster& c)
{
return c.properties.name == name;
});
};

// Check that "Cluster1" and "Cluster2" are found
BOOST_CHECK(findDisabledCluster("Cluster1") != sts.end());
BOOST_CHECK(findDisabledCluster("Cluster2") != sts.end());

study.initializeRuntimeInfos(); // This should remove all disabled short-term storages

// Check that only "Cluster1" is found
BOOST_CHECK(findDisabledCluster("Cluster1") != sts.end());
BOOST_CHECK(findDisabledCluster("Cluster2") == sts.end());

// operator<< doesn't exist for iterators, Boost can't generate output in case of failure, so we use BOOST_CHECK instead of BOOST_CHECK_EQUAL
}

BOOST_AUTO_TEST_SUITE_END() // remove_disabled


BOOST_AUTO_TEST_SUITE(thermal_clusters_operations)

BOOST_FIXTURE_TEST_CASE(thermal_cluster_add, OneAreaStudy)
{
Study study;
Area& area = *study.areaAdd("A");
auto newCluster = std::make_shared<ThermalCluster>(&area);
auto newCluster = std::make_shared<ThermalCluster>(areaA);
newCluster->setName("Cluster");
BOOST_CHECK(newCluster->name() == "Cluster");
BOOST_CHECK(newCluster->id() == "cluster");
BOOST_CHECK_EQUAL(newCluster->name(), "Cluster");
BOOST_CHECK_EQUAL(newCluster->id(), "cluster");

area.thermal.list.add(newCluster);
BOOST_CHECK(area.thermal.list.find("cluster") == newCluster.get());
BOOST_CHECK(area.thermal.list.find("Cluster") == nullptr);
areaA->thermal.list.add(newCluster);
BOOST_CHECK_EQUAL(areaA->thermal.list.find("cluster"), newCluster.get());
BOOST_CHECK_EQUAL(areaA->thermal.list.find("Cluster"), nullptr);
}

/*!
Expand Down

0 comments on commit 2aca866

Please sign in to comment.