From: Fernando Herrera Date: Wed, 9 Oct 2024 19:42:26 +0000 (-0600) Subject: check an invariant of class IndexSet X-Git-Url: https://gitweb.dealii.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=34d088a6c2258b86d30d7abd5b9fbf067d27bf24;p=dealii.git check an invariant of class IndexSet --- diff --git a/tests/base/index_set_empty.cc b/tests/base/index_set_empty.cc new file mode 100644 index 0000000000..29d718b1fb --- /dev/null +++ b/tests/base/index_set_empty.cc @@ -0,0 +1,79 @@ +// ------------------------------------------------------------------------ +// +// SPDX-License-Identifier: LGPL-2.1-or-later +// Copyright (C) 2009 - 2018 by the deal.II authors +// +// This file is part of the deal.II library. +// +// Part of the source code is dual licensed under Apache-2.0 WITH +// LLVM-exception OR LGPL-2.1-or-later. Detailed license information +// governing the source code and code contributions can be found in +// LICENSE.md and CONTRIBUTING.md at the top level directory of deal.II. +// +// ------------------------------------------------------------------------ + + +// Test the invariant that IndexSet::is_empty() is the same as +// IndexSet::n_elements()==0. + +#include + +#include "../tests.h" + + +void +test() +{ + IndexSet index_set(20); + + if (index_set.is_empty() == (index_set.n_elements() == 0)) + { + deallog << "OK" << std::endl; + } + else + { + deallog << "Not OK" << std::endl; + } + + index_set.add_range(2, 4); + if (index_set.is_empty() == (index_set.n_elements() == 0)) + { + deallog << "OK" << std::endl; + } + else + { + deallog << "Not OK" << std::endl; + } + + index_set.add_index(6); + if (index_set.is_empty() == (index_set.n_elements() == 0)) + { + deallog << "OK" << std::endl; + } + else + { + deallog << "Not OK" << std::endl; + } + + index_set.pop_back(); + index_set.pop_back(); + index_set.pop_back(); + + if (index_set.is_empty() == (index_set.n_elements() == 0)) + { + deallog << "OK" << std::endl; + } + else + { + deallog << "Not OK" << std::endl; + } +} + + +int +main() +{ + initlog(); + + test(); +} diff --git a/tests/base/index_set_empty.output b/tests/base/index_set_empty.output new file mode 100644 index 0000000000..5f42bb230f --- /dev/null +++ b/tests/base/index_set_empty.output @@ -0,0 +1,5 @@ + +DEAL::OK +DEAL::OK +DEAL::OK +DEAL::OK