1 #include <UnitTest++/UnitTest++.h>
9 #include "WalkerException.h"
13 using namespace WikiWalker
;
15 TEST(Article_GetCountLinks_Uninited_ThrowsException
)
18 CHECK_EQUAL(false, a
.analyzed());
19 CHECK_THROW(a
.countLinks(), WalkerException
);
22 TEST(Article_GetCountLinks_Inited_ReturnsNull
)
26 CHECK_EQUAL(true, a
.analyzed());
27 CHECK_EQUAL(0, a
.countLinks());
30 TEST(Article_AddLinks_OneLinkAdded
)
34 auto link
= std::make_shared
<Article
>("Barmiz");
37 CHECK_EQUAL(true, a
.analyzed());
38 CHECK_EQUAL(1, a
.countLinks());
41 TEST(Article_AddLinks_DuplicateInstance
)
45 auto arl
= std::make_shared
<Article
>("Barmiz");
46 CHECK(a
.addLink(arl
));
47 CHECK(!a
.addLink(arl
));
49 CHECK_EQUAL(true, a
.analyzed());
50 CHECK_EQUAL(1, a
.countLinks());
53 TEST(Article_AddLinks_WhenLinkExpiredToNulltpr
)
58 /* Checks for absence of bug with nullptr access when checking for
60 auto arl
= std::make_shared
<Article
>("Barmiz");
61 CHECK(a
.addLink(arl
));
64 auto arl2
= std::make_shared
<Article
>("Barmiz");
65 CHECK(a
.addLink(arl2
));
67 CHECK_EQUAL(a
.analyzed(), true);
68 /* this one's actually awkward and is counterintuitive. But since the
69 * shared_ptr went out of scope, it expired. I chose to simply ignore
70 * expired smart pointers / nullptrs inside the link collection for actual
71 * processing purposes. They're still counted, however. */
72 CHECK_EQUAL(2, a
.countLinks());
75 TEST(Article_Iterator_Test
)
79 std::vector
<std::string
> titles
{"Barmiz", "Kodopa", "Minting"};
80 // must keep them in scope
81 std::vector
<std::shared_ptr
<Article
>> articleLinks
;
83 std::transform(titles
.begin(),
85 std::back_inserter(articleLinks
),
86 [](std::string s
) { return std::make_shared
<Article
>(s
); });
88 for(const auto& s
: articleLinks
) {
92 CHECK_EQUAL(true, a
.analyzed());
93 CHECK_EQUAL(3, a
.countLinks());
96 for(auto x
= a
.linkBegin(); x
!= a
.linkEnd(); x
++) {
98 auto atitle
= x
->lock()->title();
99 auto findpos
= std::find(titles
.cbegin(), titles
.cend(), atitle
);
100 bool isFound
= (titles
.end() != findpos
);
104 CHECK_EQUAL(num
, titles
.size());
107 TEST(Article_Marked_State
)
110 CHECK_EQUAL(false, a
.marked());
112 CHECK_EQUAL(true, a
.marked());
114 CHECK_EQUAL(false, a
.marked());