blob: bb7b8e929b1f3532eb936f57e9aeab51c1bffe1f [file] [log] [blame]
Ashlesh Gawande0b2897e2018-06-20 14:40:47 -05001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2/*
Ashlesh Gawande0cf4b602019-01-18 15:58:17 -06003 * Copyright (c) 2014-2019, 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
22#include <boost/test/unit_test.hpp>
23#include <ndn-cxx/name.hpp>
24
25namespace psync {
26
27using namespace ndn;
28
29BOOST_AUTO_TEST_SUITE(TestBloomFilter)
30
31BOOST_AUTO_TEST_CASE(Basic)
32{
33 BloomFilter bf(100, 0.001);
34
35 std::string insertName("/memphis");
36 bf.insert(insertName);
37 BOOST_CHECK(bf.contains(insertName));
38}
39
40BOOST_AUTO_TEST_CASE(NameAppendAndExtract)
41{
42 Name bfName("/test");
43 BloomFilter bf(100, 0.001);
44 bf.insert("/memphis");
45
46 bf.appendToName(bfName);
47
48 BloomFilter bfFromName(100, 0.001, bfName.get(-1));
49
50 BOOST_CHECK_EQUAL(bfName.get(1).toNumber(), 100);
51 BOOST_CHECK_EQUAL(bfName.get(2).toNumber(), 1);
52 BOOST_CHECK_EQUAL(bf, bfFromName);
53
54 BOOST_CHECK_THROW(BloomFilter inCompatibleBf(200, 0.001, bfName.get(-1)), std::runtime_error);
55}
56
57BOOST_AUTO_TEST_SUITE_END()
58
59} // namespace psync