blob: 1788cd139752f08304154fb7d431478217c1317b [file] [log] [blame]
Ashlesh Gawande0b2897e2018-06-20 14:40:47 -05001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2/*
Ashlesh Gawande5a895472020-01-25 18:07:32 -08003 * Copyright (c) 2014-2020, The University of Memphis
Ashlesh Gawande0b2897e2018-06-20 14:40:47 -05004 *
5 * This file is part of PSync.
6 * See AUTHORS.md for complete list of PSync authors and contributors.
7 *
8 * PSync is free software: you can redistribute it and/or modify it under the terms
Ashlesh Gawande0cf4b602019-01-18 15:58:17 -06009 * of the GNU Lesser General Public License as published by the Free Software Foundation,
Ashlesh Gawande0b2897e2018-06-20 14:40:47 -050010 * either version 3 of the License, or (at your option) any later version.
11 *
12 * PSync is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
13 * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
Ashlesh Gawande0cf4b602019-01-18 15:58:17 -060014 * PURPOSE. See the GNU Lesser General Public License for more details.
Ashlesh Gawande0b2897e2018-06-20 14:40:47 -050015 *
Ashlesh Gawande0cf4b602019-01-18 15:58:17 -060016 * You should have received a copy of the GNU Lesser General Public License along with
Ashlesh Gawande0b2897e2018-06-20 14:40:47 -050017 * PSync, e.g., in COPYING.md file. If not, see <http://www.gnu.org/licenses/>.
18 **/
19
Ashlesh Gawande78b94ad2018-12-13 15:29:19 -060020#include "PSync/detail/bloom-filter.hpp"
Ashlesh Gawande0b2897e2018-06-20 14:40:47 -050021
Davide Pesavento5b3cf762020-04-03 16:20:04 -040022#include "tests/boost-test.hpp"
23
Ashlesh Gawande0b2897e2018-06-20 14:40:47 -050024#include <ndn-cxx/name.hpp>
25
26namespace psync {
27
28using namespace ndn;
29
30BOOST_AUTO_TEST_SUITE(TestBloomFilter)
31
32BOOST_AUTO_TEST_CASE(Basic)
33{
34 BloomFilter bf(100, 0.001);
35
36 std::string insertName("/memphis");
37 bf.insert(insertName);
38 BOOST_CHECK(bf.contains(insertName));
39}
40
41BOOST_AUTO_TEST_CASE(NameAppendAndExtract)
42{
43 Name bfName("/test");
44 BloomFilter bf(100, 0.001);
45 bf.insert("/memphis");
Ashlesh Gawande0b2897e2018-06-20 14:40:47 -050046 bf.appendToName(bfName);
47
Davide Pesavento5b3cf762020-04-03 16:20:04 -040048 BloomFilter bfFromName(100, 0.001, bfName.at(-1));
Ashlesh Gawande0b2897e2018-06-20 14:40:47 -050049
Davide Pesavento5b3cf762020-04-03 16:20:04 -040050 BOOST_CHECK_EQUAL(bfName.at(1).toNumber(), 100);
51 BOOST_CHECK_EQUAL(bfName.at(2).toNumber(), 1);
Ashlesh Gawande0b2897e2018-06-20 14:40:47 -050052 BOOST_CHECK_EQUAL(bf, bfFromName);
53
Davide Pesavento5b3cf762020-04-03 16:20:04 -040054 BOOST_CHECK_THROW(BloomFilter(200, 0.001, bfName.at(-1)), std::runtime_error);
Ashlesh Gawande0b2897e2018-06-20 14:40:47 -050055}
56
57BOOST_AUTO_TEST_SUITE_END()
58
Davide Pesavento5b3cf762020-04-03 16:20:04 -040059} // namespace psync