Line data Source code
1 : // Author(s): Maurice Laveaux 2 : // Copyright: see the accompanying file COPYING or copy at 3 : // https://github.com/mCRL2org/mCRL2/blob/master/COPYING 4 : // 5 : // Distributed under the Boost Software License, Version 1.0. 6 : // (See accompanying file LICENSE_1_0.txt or copy at 7 : // http://www.boost.org/LICENSE_1_0.txt) 8 : // 9 : 10 : #include "mcrl2/utilities/fixed_size_cache.h" 11 : 12 : #define BOOST_AUTO_TEST_MAIN 13 : #include <boost/test/included/unit_test.hpp> 14 : 15 : using namespace mcrl2::utilities; 16 : 17 : struct square_struct 18 : { 19 200 : int operator()(int value) 20 : { 21 200 : return value*value; 22 : } 23 : }; 24 : 25 2 : BOOST_AUTO_TEST_CASE(test_function_cache) 26 : { 27 1 : fifo_function_cache<square_struct, int> cache; 28 : 29 1 : std::vector<int> results; 30 101 : for (int i = 0; i < 100; ++i) 31 : { 32 100 : results.push_back(square_struct()(i)); 33 : } 34 : 35 101 : for (int i = 0; i < 100; ++i) 36 : { 37 100 : BOOST_CHECK_EQUAL(cache(i), results[i]); 38 : } 39 : 40 1 : }