Ashlesh Gawande | 0b2897e | 2018-06-20 14:40:47 -0500 | [diff] [blame] | 1 | /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ |
| 2 | /* |
Davide Pesavento | 47eb6d9 | 2024-02-12 20:25:51 -0500 | [diff] [blame] | 3 | * Copyright (c) 2014-2024, The University of Memphis |
Ashlesh Gawande | 0b2897e | 2018-06-20 14:40:47 -0500 | [diff] [blame] | 4 | * |
| 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 Gawande | 0cf4b60 | 2019-01-18 15:58:17 -0600 | [diff] [blame] | 9 | * of the GNU Lesser General Public License as published by the Free Software Foundation, |
Ashlesh Gawande | 0b2897e | 2018-06-20 14:40:47 -0500 | [diff] [blame] | 10 | * 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 Gawande | 0cf4b60 | 2019-01-18 15:58:17 -0600 | [diff] [blame] | 14 | * PURPOSE. See the GNU Lesser General Public License for more details. |
Ashlesh Gawande | 0b2897e | 2018-06-20 14:40:47 -0500 | [diff] [blame] | 15 | * |
Ashlesh Gawande | 0cf4b60 | 2019-01-18 15:58:17 -0600 | [diff] [blame] | 16 | * You should have received a copy of the GNU Lesser General Public License along with |
Ashlesh Gawande | 0b2897e | 2018-06-20 14:40:47 -0500 | [diff] [blame] | 17 | * PSync, e.g., in COPYING.md file. If not, see <http://www.gnu.org/licenses/>. |
| 18 | **/ |
| 19 | |
Ashlesh Gawande | 78b94ad | 2018-12-13 15:29:19 -0600 | [diff] [blame] | 20 | #include "PSync/detail/bloom-filter.hpp" |
Ashlesh Gawande | 0b2897e | 2018-06-20 14:40:47 -0500 | [diff] [blame] | 21 | |
Davide Pesavento | 5b3cf76 | 2020-04-03 16:20:04 -0400 | [diff] [blame] | 22 | #include "tests/boost-test.hpp" |
| 23 | |
Ashlesh Gawande | 0b2897e | 2018-06-20 14:40:47 -0500 | [diff] [blame] | 24 | #include <ndn-cxx/name.hpp> |
| 25 | |
Davide Pesavento | 47eb6d9 | 2024-02-12 20:25:51 -0500 | [diff] [blame] | 26 | namespace psync::tests { |
| 27 | |
| 28 | using detail::BloomFilter; |
Ashlesh Gawande | 0b2897e | 2018-06-20 14:40:47 -0500 | [diff] [blame] | 29 | |
| 30 | BOOST_AUTO_TEST_SUITE(TestBloomFilter) |
| 31 | |
| 32 | BOOST_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 | |
| 41 | BOOST_AUTO_TEST_CASE(NameAppendAndExtract) |
| 42 | { |
Davide Pesavento | db78956 | 2020-12-19 23:01:08 -0500 | [diff] [blame] | 43 | ndn::Name bfName("/test"); |
Ashlesh Gawande | 0b2897e | 2018-06-20 14:40:47 -0500 | [diff] [blame] | 44 | BloomFilter bf(100, 0.001); |
| 45 | bf.insert("/memphis"); |
Ashlesh Gawande | 0b2897e | 2018-06-20 14:40:47 -0500 | [diff] [blame] | 46 | bf.appendToName(bfName); |
| 47 | |
Davide Pesavento | 5b3cf76 | 2020-04-03 16:20:04 -0400 | [diff] [blame] | 48 | BloomFilter bfFromName(100, 0.001, bfName.at(-1)); |
Ashlesh Gawande | 0b2897e | 2018-06-20 14:40:47 -0500 | [diff] [blame] | 49 | |
Davide Pesavento | 5b3cf76 | 2020-04-03 16:20:04 -0400 | [diff] [blame] | 50 | BOOST_CHECK_EQUAL(bfName.at(1).toNumber(), 100); |
| 51 | BOOST_CHECK_EQUAL(bfName.at(2).toNumber(), 1); |
Ashlesh Gawande | 0b2897e | 2018-06-20 14:40:47 -0500 | [diff] [blame] | 52 | BOOST_CHECK_EQUAL(bf, bfFromName); |
| 53 | |
Davide Pesavento | 5b3cf76 | 2020-04-03 16:20:04 -0400 | [diff] [blame] | 54 | BOOST_CHECK_THROW(BloomFilter(200, 0.001, bfName.at(-1)), std::runtime_error); |
Ashlesh Gawande | 0b2897e | 2018-06-20 14:40:47 -0500 | [diff] [blame] | 55 | } |
| 56 | |
| 57 | BOOST_AUTO_TEST_SUITE_END() |
| 58 | |
Davide Pesavento | 47eb6d9 | 2024-02-12 20:25:51 -0500 | [diff] [blame] | 59 | } // namespace psync::tests |