Aleph-w 7.10.0
A C++ Library for Data Structures and Algorithms
Loading...
Searching...
No Matches
dynskiplist_test.cc
Go to the documentation of this file.
1
2/*
3 Aleph_w
4
5 Data structures & Algorithms
6 version 2.0.0b
7 https://github.com/lrleon/Aleph-w
8
9 This file is part of Aleph-w library
10
11 Copyright (c) 2002-2026 Leandro Rabindranath Leon
12
13 Permission is hereby granted, free of charge, to any person obtaining a copy
14 of this software and associated documentation files (the "Software"), to deal
15 in the Software without restriction, including without limitation the rights
16 to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
17 copies of the Software, and to permit persons to whom the Software is
18 furnished to do so, subject to the following conditions:
19
20 The above copyright notice and this permission notice shall be included in all
21 copies or substantial portions of the Software.
22
23 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
24 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
25 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
26 AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
27 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
28 OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
29 SOFTWARE.
30*/
31
32
33
38#include <gtest/gtest.h>
39#include <ah-random.H>
40#include <string>
41#include <vector>
42#include <algorithm>
43#include <tpl_array.H>
44#include <tpl_dynSkipList.H>
45
46#include <limits>
47#include <stdexcept>
48
49using namespace Aleph;
50
51namespace {
52
53class DynSkipListTest : public ::testing::Test
54{
55protected:
57};
58
59// A key that counts the keys alive, and whose copy throws when a budget
60// of copies runs out
61struct Counted_Key
62{
63 static inline int alive = 0;
64 static inline int copies_left = -1; // -1: no copy throws
65 int value = 0;
66
67 Counted_Key(const int v = 0) : value(v) { ++alive; }
68
69 Counted_Key(const Counted_Key & other) : value(other.value)
70 {
71 if (copies_left == 0)
72 throw std::runtime_error("the copy of a key");
73 if (copies_left > 0)
74 --copies_left;
75 ++alive;
76 }
77
78 Counted_Key & operator = (const Counted_Key &) = default;
79
80 ~Counted_Key() { --alive; }
81
82 bool operator < (const Counted_Key & other) const { return value < other.value; }
83
84 bool operator == (const Counted_Key & other) const { return value == other.value; }
85};
86
87// ============================================================================
88// Construction Tests
89// ============================================================================
90
91TEST_F(DynSkipListTest, DefaultConstruction)
92{
93 EXPECT_TRUE(sl.is_empty());
94 EXPECT_EQ(sl.size(), 0);
95}
96
97// Whatever copy of a key throws, a copy of a list, or a list built from a
98// range or from an initializer list, frees what it took, and the
99// exception reaches the caller
100TEST(DynSkipList, ConstructorsFreeWhatTheyTookWhenACopyOfAKeyThrows)
101{
103 for (int i = 1; i <= 5; ++i)
104 source.insert(Counted_Key(i));
105 const std::vector<Counted_Key> keys = {5, 3, 1, 4, 2};
106 const int before = Counted_Key::alive;
107
108 size_t failures = 0;
109 for (int k = 0; k < 100; ++k)
110 {
111 bool thrown = false;
112 Counted_Key::copies_left = k;
113 try
114 {
115 const DynSkipList<Counted_Key> copy(source);
116 EXPECT_EQ(copy.size(), source.size());
117 }
118 catch (const std::runtime_error &)
119 {
120 thrown = true;
121 }
122 Counted_Key::copies_left = -1;
123 EXPECT_EQ(Counted_Key::alive, before) << "the copy, at the copy " << k;
124 if (not thrown)
125 break;
126 ++failures;
127 }
128 EXPECT_GE(failures, 5u);
129
130 for (int k = 0; k < 5; ++k)
131 {
132 Counted_Key::copies_left = k;
133 EXPECT_THROW([&] { const DynSkipList<Counted_Key> l(keys.begin(), keys.end()); }(),
134 std::runtime_error);
135 EXPECT_EQ(Counted_Key::alive, before) << "the range, at the copy " << k;
136
137 Counted_Key::copies_left = k;
138 EXPECT_THROW(([&] { const DynSkipList<Counted_Key> l = {5, 3, 1, 4, 2}; }()),
139 std::runtime_error);
140 EXPECT_EQ(Counted_Key::alive, before) << "the initializer list, at the copy " << k;
141 }
142 Counted_Key::copies_left = -1;
143}
144
145TEST_F(DynSkipListTest, InitializerListConstruction)
146{
147 DynSkipList<int> sl2({5, 2, 8, 1, 9});
148
149 EXPECT_EQ(sl2.size(), 5);
150 EXPECT_TRUE(sl2.has(1));
151 EXPECT_TRUE(sl2.has(2));
152 EXPECT_TRUE(sl2.has(5));
153 EXPECT_TRUE(sl2.has(8));
154 EXPECT_TRUE(sl2.has(9));
155}
156
157TEST_F(DynSkipListTest, ConstructorWithSeed)
158{
159 DynSkipList<int> sl2(42, 0.5);
160 sl2.insert(1);
161 sl2.insert(2);
162 EXPECT_EQ(sl2.size(), 2);
163}
164
165TEST_F(DynSkipListTest, SetSeed)
166{
167 sl.set_seed(123);
168 EXPECT_EQ(sl.random_source(), Random_Source(Random_Source::Engine::Mersenne_Twister, 123));
169}
170
171TEST_F(DynSkipListTest, TheGeneratorDrawsTheLevels)
172{
173 // inserting draws from the generator, and the same seed draws the same
174 sl.set_seed(5);
175 DynSkipList<int> other(5UL);
176 EXPECT_EQ(sl.random_source(), other.random_source());
177 for (int i = 0; i < 50; ++i)
178 {
179 sl.insert(i);
180 other.insert(i);
181 }
182 EXPECT_EQ(sl.random_source(), other.random_source());
183 EXPECT_FALSE(sl.random_source()
184 == Random_Source(Random_Source::Engine::Mersenne_Twister, 5));
185}
186
187TEST_F(DynSkipListTest, CopyConstruction)
188{
189 sl.insert(1);
190 sl.insert(2);
191 sl.insert(3);
192
193 DynSkipList<int> sl2(sl);
194
195 EXPECT_EQ(sl2.size(), 3);
196 EXPECT_TRUE(sl2.has(1));
197 EXPECT_TRUE(sl2.has(2));
198 EXPECT_TRUE(sl2.has(3));
199
200 // Modify original, copy should be independent
201 sl.insert(4);
202 EXPECT_FALSE(sl2.has(4));
203}
204
205TEST_F(DynSkipListTest, MoveConstruction)
206{
207 sl.insert(1);
208 sl.insert(2);
209 sl.insert(3);
210
211 DynSkipList<int> sl2(std::move(sl));
212
213 EXPECT_EQ(sl2.size(), 3);
214 EXPECT_TRUE(sl2.has(1));
215 EXPECT_TRUE(sl2.has(2));
216 EXPECT_TRUE(sl2.has(3));
217
218 // Original should be empty
219 EXPECT_TRUE(sl.is_empty());
220}
221
222// An order with a state, which can be copied and moved but assigned only
223// by a move, as a lambda with a capture
224struct Order
225{
226 bool descending = false;
227
228 Order() = default;
229 explicit Order(const bool d) noexcept : descending(d) {}
230 Order(const Order &) = default;
231 Order(Order &&) = default;
232 Order & operator = (const Order &) = delete;
233 Order & operator = (Order &&) = default;
234
235 bool operator () (const int a, const int b) const noexcept
236 {
237 return descending ? b < a : a < b;
238 }
239};
240
241// The move constructs the comparison of the destination from that of the
242// source, which keeps it: it needs no copy assignment of it
243TEST(DynSkipList, MoveConstructsTheComparisonFromThatOfTheSource)
244{
246 src.get_compare() = Order(true);
247 for (int i = 0; i < 5; ++i)
248 src.insert(i);
249
250 DynSkipList<int, Order> dst(std::move(src));
251 EXPECT_TRUE(dst.get_compare().descending);
252 EXPECT_TRUE(src.get_compare().descending);
253 EXPECT_TRUE(src.is_empty());
255 dst.for_each([&keys] (const int k) { keys.append(k); });
256 ASSERT_EQ(keys.size(), 5u);
257 for (size_t i = 0; i < keys.size(); ++i)
258 EXPECT_EQ(keys(i), 4 - static_cast<int>(i));
259
260 // the source goes on with its comparison
261 src.insert(1);
262 src.insert(2);
263 EXPECT_EQ(src.get_first(), 2);
264
265 DynSkipList<int, Order> other(2UL);
266 other = std::move(dst);
267 EXPECT_EQ(other.size(), 5u);
268 EXPECT_EQ(other.get_first(), 4);
269}
270
271// A comparison that can only be moved
272struct Move_Only_Less
273{
274 Move_Only_Less() = default;
275 Move_Only_Less(const Move_Only_Less &) = delete;
276 Move_Only_Less & operator = (const Move_Only_Less &) = delete;
277 Move_Only_Less(Move_Only_Less &&) noexcept = default;
278 Move_Only_Less & operator = (Move_Only_Less &&) noexcept = default;
279
280 bool operator () (const int a, const int b) const noexcept { return a < b; }
281};
282
283// The move takes a comparison that cannot be copied: it moves it, and the
284// source is left empty and usable, with the one moved from
285TEST(DynSkipList, MoveTakesAComparisonThatCanOnlyBeMoved)
286{
288 for (const int i : {5, 1, 3})
289 src.insert(i);
290
291 DynSkipList<int, Move_Only_Less> dst(std::move(src));
292 EXPECT_EQ(dst.size(), 3u);
293 EXPECT_TRUE(src.is_empty());
294 EXPECT_EQ(dst.get_first(), 1);
295 EXPECT_NE(dst.search(3), nullptr);
296
297 src.insert(2);
298 EXPECT_EQ(src.size(), 1u);
299 EXPECT_EQ(src.get_first(), 2);
300
302 other = std::move(dst);
303 EXPECT_EQ(other.size(), 3u);
304}
305
306// ============================================================================
307// Insert Tests
308// ============================================================================
309
310TEST_F(DynSkipListTest, InsertSingle)
311{
312 int * result = sl.insert(42);
313
314 ASSERT_NE(result, nullptr);
315 EXPECT_EQ(*result, 42);
316 EXPECT_EQ(sl.size(), 1);
317 EXPECT_TRUE(sl.has(42));
318}
319
320TEST_F(DynSkipListTest, InsertDuplicate)
321{
322 sl.insert(42);
323 int * result = sl.insert(42);
324
325 EXPECT_EQ(result, nullptr); // Duplicate not inserted
326 EXPECT_EQ(sl.size(), 1);
327}
328
329TEST_F(DynSkipListTest, InsertMultiple)
330{
331 for (int i = 1; i <= 10; ++i)
332 sl.insert(i);
333
334 EXPECT_EQ(sl.size(), 10);
335
336 for (int i = 1; i <= 10; ++i)
337 EXPECT_TRUE(sl.has(i));
338}
339
340TEST_F(DynSkipListTest, InsertDescending)
341{
342 for (int i = 10; i >= 1; --i)
343 sl.insert(i);
344
345 EXPECT_EQ(sl.size(), 10);
346 EXPECT_EQ(sl.min(), 1);
347 EXPECT_EQ(sl.max(), 10);
348}
349
350TEST_F(DynSkipListTest, InsertRvalue)
351{
352 std::string str = "hello";
354
355 sl_str.insert(std::move(str));
356
357 EXPECT_EQ(sl_str.size(), 1);
358 EXPECT_TRUE(sl_str.has("hello"));
359}
360
361// ============================================================================
362// Search Tests
363// ============================================================================
364
365TEST_F(DynSkipListTest, SearchEmpty)
366{
367 EXPECT_EQ(sl.search(42), nullptr);
368}
369
370TEST_F(DynSkipListTest, SearchExisting)
371{
372 sl.insert(42);
373
374 int * result = sl.search(42);
375 ASSERT_NE(result, nullptr);
376 EXPECT_EQ(*result, 42);
377}
378
379TEST_F(DynSkipListTest, SearchNonExisting)
380{
381 sl.insert(42);
382
383 EXPECT_EQ(sl.search(41), nullptr);
384 EXPECT_EQ(sl.search(43), nullptr);
385}
386
387TEST_F(DynSkipListTest, HasContainsExist)
388{
389 sl.insert(42);
390
391 EXPECT_TRUE(sl.has(42));
392 EXPECT_TRUE(sl.contains(42));
393 EXPECT_TRUE(sl.exist(42));
394
395 EXPECT_FALSE(sl.has(43));
396 EXPECT_FALSE(sl.contains(43));
397 EXPECT_FALSE(sl.exist(43));
398}
399
400TEST_F(DynSkipListTest, Find)
401{
402 sl.insert(42);
403
404 EXPECT_EQ(sl.find(42), 42);
405
406 EXPECT_THROW((void)sl.find(43), std::domain_error);
407}
408
409TEST_F(DynSkipListTest, AppendOfARepeatedKeyReturnsTheKeyInTheSet)
410{
411 // append(Key &&) used to throw for a key already in the set, while
412 // append(const Key &) returned it: `s.append(1); s.append(1);` threw.
413 const int & first = sl.append(1);
414 EXPECT_EQ(&sl.append(1), &first); // repeated, as an rvalue
415
416 const int one = 1;
417 EXPECT_EQ(&sl.append(one), &first); // repeated, as an lvalue
418
419 EXPECT_EQ(sl.size(), 1u);
420 EXPECT_EQ(sl.append(2), 2);
421 EXPECT_EQ(sl.size(), 2u);
422}
423
424TEST_F(DynSkipListTest, FindOnConstantList)
425{
426 // The constant find() used to store the const Key * of search() in a
427 // Key *, which did not compile.
428 sl.insert(42);
429 const auto & csl = sl;
430
431 EXPECT_EQ(csl.find(42), 42);
432 EXPECT_THROW((void) csl.find(43), std::domain_error);
433}
434
435// ============================================================================
436// Remove Tests
437// ============================================================================
438
439TEST_F(DynSkipListTest, RemoveExisting)
440{
441 sl.insert(1);
442 sl.insert(2);
443 sl.insert(3);
444
445 size_t removed = sl.remove(2);
446
447 EXPECT_EQ(removed, 1); // 1 element was removed
448 EXPECT_EQ(sl.size(), 2);
449 EXPECT_FALSE(sl.has(2));
450 EXPECT_TRUE(sl.has(1));
451 EXPECT_TRUE(sl.has(3));
452}
453
454TEST_F(DynSkipListTest, RemoveNonExisting)
455{
456 sl.insert(1);
457 sl.insert(2);
458
459 size_t removed = sl.remove(99);
460
461 EXPECT_EQ(removed, 0); // Nothing was removed
462 EXPECT_EQ(sl.size(), 2);
463}
464
465TEST_F(DynSkipListTest, RemoveFirst)
466{
467 sl.insert(1);
468 sl.insert(2);
469 sl.insert(3);
470
471 sl.remove(1);
472
473 EXPECT_EQ(sl.min(), 2);
474}
475
476TEST_F(DynSkipListTest, RemoveLast)
477{
478 sl.insert(1);
479 sl.insert(2);
480 sl.insert(3);
481
482 sl.remove(3);
483
484 EXPECT_EQ(sl.max(), 2);
485}
486
487TEST_F(DynSkipListTest, RemoveAll)
488{
489 for (int i = 1; i <= 5; ++i)
490 sl.insert(i);
491
492 for (int i = 1; i <= 5; ++i)
493 sl.remove(i);
494
495 EXPECT_TRUE(sl.is_empty());
496}
497
498TEST_F(DynSkipListTest, Del)
499{
500 sl.insert(42);
501
502 int deleted = sl.del(42);
503
504 EXPECT_EQ(deleted, 42);
505 EXPECT_FALSE(sl.has(42));
506
507 EXPECT_THROW(sl.del(42), std::domain_error);
508}
509
510// ============================================================================
511// Min/Max Tests
512// ============================================================================
513
514TEST_F(DynSkipListTest, MinMax)
515{
516 sl.insert(5);
517 sl.insert(2);
518 sl.insert(8);
519 sl.insert(1);
520 sl.insert(9);
521
522 EXPECT_EQ(sl.min(), 1);
523 EXPECT_EQ(sl.get_first(), 1);
524 EXPECT_EQ(sl.max(), 9);
525 EXPECT_EQ(sl.get_last(), 9);
526}
527
528TEST_F(DynSkipListTest, MinMaxEmpty)
529{
530 EXPECT_THROW((void)sl.min(), std::domain_error);
531 EXPECT_THROW((void)sl.max(), std::domain_error);
532}
533
534// ============================================================================
535// Iterator Tests
536// ============================================================================
537
538TEST_F(DynSkipListTest, IteratorEmpty)
539{
541 EXPECT_FALSE(it.has_curr());
542}
543
544TEST_F(DynSkipListTest, IteratorTraverse)
545{
546 for (int i = 1; i <= 5; ++i)
547 sl.insert(i);
548
549 int expected = 1;
550 for (DynSkipList<int>::Iterator it(sl); it.has_curr(); it.next())
551 {
552 EXPECT_EQ(it.get_curr(), expected);
553 ++expected;
554 }
555 EXPECT_EQ(expected, 6);
556}
557
558TEST_F(DynSkipListTest, IteratorRangeBased)
559{
560 sl.insert(3);
561 sl.insert(1);
562 sl.insert(2);
563
564 std::vector<int> result;
565 for (const auto & key : sl)
566 result.push_back(key);
567
568 EXPECT_EQ(result.size(), 3);
569 EXPECT_EQ(result[0], 1);
570 EXPECT_EQ(result[1], 2);
571 EXPECT_EQ(result[2], 3);
572}
573
574TEST_F(DynSkipListTest, IteratorOperators)
575{
576 sl.insert(1);
577 sl.insert(2);
578 sl.insert(3);
579
580 auto it = sl.begin();
581 EXPECT_EQ(*it, 1);
582
583 ++it;
584 EXPECT_EQ(*it, 2);
585
586 it++;
587 EXPECT_EQ(*it, 3);
588
589 ++it;
590 EXPECT_EQ(it, sl.end());
591}
592
593// ============================================================================
594// Assignment Tests
595// ============================================================================
596
597TEST_F(DynSkipListTest, CopyAssignment)
598{
599 sl.insert(1);
600 sl.insert(2);
601
603 sl2.insert(99);
604
605 sl2 = sl;
606
607 EXPECT_EQ(sl2.size(), 2);
608 EXPECT_TRUE(sl2.has(1));
609 EXPECT_TRUE(sl2.has(2));
610 EXPECT_FALSE(sl2.has(99));
611}
612
613TEST_F(DynSkipListTest, MoveAssignment)
614{
615 sl.insert(1);
616 sl.insert(2);
617
619 sl2.insert(99);
620
621 sl2 = std::move(sl);
622
623 EXPECT_EQ(sl2.size(), 2);
624 EXPECT_TRUE(sl2.has(1));
625 EXPECT_TRUE(sl.is_empty());
626}
627
628TEST_F(DynSkipListTest, SelfAssignment)
629{
630 sl.insert(1);
631 sl.insert(2);
632
633 sl = sl;
634
635 EXPECT_EQ(sl.size(), 2);
636}
637
638// ============================================================================
639// Empty/Swap Tests
640// ============================================================================
641
642TEST_F(DynSkipListTest, Empty)
643{
644 sl.insert(1);
645 sl.insert(2);
646 sl.insert(3);
647
648 sl.empty();
649
650 EXPECT_TRUE(sl.is_empty());
651 EXPECT_EQ(sl.size(), 0);
652}
653
654TEST_F(DynSkipListTest, Swap)
655{
656 sl.insert(1);
657 sl.insert(2);
658
660 sl2.insert(10);
661 sl2.insert(20);
662 sl2.insert(30);
663
664 sl.swap(sl2);
665
666 EXPECT_EQ(sl.size(), 3);
667 EXPECT_TRUE(sl.has(10));
668
669 EXPECT_EQ(sl2.size(), 2);
670 EXPECT_TRUE(sl2.has(1));
671}
672
673// ============================================================================
674// Functional Tests
675// ============================================================================
676
677TEST_F(DynSkipListTest, ForEach)
678{
679 sl.insert(1);
680 sl.insert(2);
681 sl.insert(3);
682
683 int sum = 0;
684 sl.for_each([&sum](int x) { sum += x; });
685
686 EXPECT_EQ(sum, 6);
687}
688
689TEST_F(DynSkipListTest, All)
690{
691 sl.insert(2);
692 sl.insert(4);
693 sl.insert(6);
694
695 EXPECT_TRUE(sl.all([](int x) { return x % 2 == 0; }));
696
697 sl.insert(3);
698 EXPECT_FALSE(sl.all([](int x) { return x % 2 == 0; }));
699}
700
701TEST_F(DynSkipListTest, Exists)
702{
703 sl.insert(1);
704 sl.insert(2);
705 sl.insert(3);
706
707 EXPECT_TRUE(sl.exists([](int x) { return x > 2; }));
708 EXPECT_FALSE(sl.exists([](int x) { return x > 10; }));
709}
710
711TEST_F(DynSkipListTest, Traverse)
712{
713 sl.insert(1);
714 sl.insert(2);
715 sl.insert(3);
716 sl.insert(4);
717 sl.insert(5);
718
719 // Traverse until we find 3
720 int count = 0;
721 bool completed = sl.traverse([&count](int x) {
722 ++count;
723 return x != 3; // Stop when we find 3
724 });
725
726 EXPECT_FALSE(completed);
727 EXPECT_EQ(count, 3);
728}
729
730// ============================================================================
731// Large Scale Tests
732// ============================================================================
733
734TEST_F(DynSkipListTest, LargeScale)
735{
736 const int N = 1000;
737
738 for (int i = 0; i < N; ++i)
739 sl.insert(i);
740
741 EXPECT_EQ(sl.size(), N);
742
743 for (int i = 0; i < N; ++i)
744 EXPECT_TRUE(sl.has(i));
745
746 for (int i = 0; i < N; i += 2)
747 sl.remove(i);
748
749 EXPECT_EQ(sl.size(), N / 2);
750
751 for (int i = 0; i < N; ++i)
752 {
753 if (i % 2 == 0)
754 EXPECT_FALSE(sl.has(i));
755 else
756 EXPECT_TRUE(sl.has(i));
757 }
758}
759
760// ============================================================================
761// String Key Tests
762// ============================================================================
763
764TEST(DynSkipListStringTest, StringKeys)
765{
767
768 sl.insert("banana");
769 sl.insert("apple");
770 sl.insert("cherry");
771
772 EXPECT_EQ(sl.size(), 3);
773 EXPECT_EQ(sl.min(), "apple");
774 EXPECT_EQ(sl.max(), "cherry");
775
776 EXPECT_TRUE(sl.has("banana"));
777 EXPECT_FALSE(sl.has("date"));
778}
779
780// ============================================================================
781// SearchOrInsert Tests
782// ============================================================================
783
784TEST_F(DynSkipListTest, SearchOrInsertNew)
785{
786 int * result = sl.search_or_insert(42);
787
788 ASSERT_NE(result, nullptr);
789 EXPECT_EQ(*result, 42);
790 EXPECT_EQ(sl.size(), 1);
791}
792
793TEST_F(DynSkipListTest, SearchOrInsertExisting)
794{
795 sl.insert(42);
796
797 int * result = sl.search_or_insert(42);
798
799 ASSERT_NE(result, nullptr);
800 EXPECT_EQ(*result, 42);
801 EXPECT_EQ(sl.size(), 1); // No new insertion
802}
803
804} // anonymous namespace
805
806// The probability was not validated: with p >= 1 every node got the
807// maximum level and with p <= 0 level 1, both degrading to linear time.
808TEST(DynSkipListProbability, MustBeBetweenZeroAndOne)
809{
810 EXPECT_THROW(DynSkipList<int>(1, 0.0), std::domain_error);
811 EXPECT_THROW(DynSkipList<int>(1, 1.0), std::domain_error);
812 EXPECT_THROW(DynSkipList<int>(1, -0.5), std::domain_error);
813 EXPECT_THROW(DynSkipList<int>(1, 7.0), std::domain_error);
814 EXPECT_THROW(DynSkipList<int>(1, std::numeric_limits<double>::quiet_NaN()), std::domain_error);
815
816 // and so does the constructor without a seed, which checks it by itself
817 EXPECT_THROW(DynSkipList<int>(0.0), std::domain_error);
818 EXPECT_THROW(DynSkipList<int>(1.0), std::domain_error);
819 EXPECT_THROW(DynSkipList<int>(-0.5), std::domain_error);
820 EXPECT_THROW(DynSkipList<int>(7.0), std::domain_error);
821 // through a variable: with the call as its argument, the statement
822 // would declare a function
823 const double not_a_number = std::numeric_limits<double>::quiet_NaN();
824 EXPECT_THROW((void) DynSkipList<int>(not_a_number), std::domain_error);
825 EXPECT_NO_THROW(DynSkipList<int>(0.25));
826 EXPECT_EQ(DynSkipList<int>(0.25).random_source().engine(), Random_Source::Engine::SplitMix64);
827 EXPECT_THROW(DynSkipList<int>(1.5), std::domain_error);
828 EXPECT_NO_THROW(DynSkipList<int>(1, 0.25));
829 EXPECT_NO_THROW(DynSkipList<int>(0.75));
830}
831
832int main(int argc, char** argv)
833{
834 ::testing::InitGoogleTest(&argc, argv);
835 return RUN_ALL_TESTS();
836}
TEST_F(AdaptiveHuffmanWithoutMemory, ALostByteLeavesTheDecoderFailed)
The random number generators of Aleph: the one that gives the numbers of the gsl_rng_mt19937 of GSL,...
bool operator<(const Time &l, const Time &r)
Definition ah-time.H:143
int main()
size_t size_t int32_t value
Definition ca-c-api.h:116
Simple dynamic array with automatic resizing and functional operations.
Definition tpl_array.H:141
Forward iterator for DynSkipList.
bool has_curr() const noexcept
Dynamic ordered set implemented with a Skip List.
Key * search_or_insert(const Key &key)
Search and insert if not found.
const Key & min() const
Return the minimum element (first in sorted order)
Key * insert(const Key &key)
Insert an element into the set.
size_t size() const noexcept
Return the number of elements in the set.
bool has(const Key &key) const noexcept
Return true if the key exists in the set.
const Key & max() const
Return the maximum element (last in sorted order)
Number Theoretic Transform over Z / MOD Z.
Definition ntt.H:115
The source of random numbers of a randomized structure, which draws from one of two generators.
Definition ah-random.H:883
Minimal std::expected-style result type for C++20.
void for_each(Operation &operation) const
Traverse all the container and performs an operation on each element.
Definition ah-dry.H:1475
#define TEST(name)
#define N
Definition fib.C:294
Main namespace for Aleph-w library functions.
bool operator==(const DynList< T > &l1, const DynList< T > &l2)
Equality operator for DynList.
bool completed() const noexcept
Return true if all underlying iterators are finished.
Definition ah-zip.H:183
Itor2 copy(Itor1 sourceBeg, const Itor1 &sourceEnd, Itor2 destBeg)
Copy elements from one range to another.
Definition ahAlgo.H:584
Itor::difference_type count(const Itor &beg, const Itor &end, const T &value)
Count elements equal to a value.
Definition ahAlgo.H:127
T sum(const Container &container, const T &init=T{})
Compute sum of all elements.
int keys[]
static int * k
static mt19937 engine
Dynamic array container with automatic resizing.
Dynamic ordered set implemented with a Skip List.
DynList< int > l