Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[2_1] Improve << of hashset<string> #220

Merged
merged 1 commit into from
Nov 22, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions Kernel/Containers/hashset.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
#ifndef HASHSET_H
#define HASHSET_H
#include "list.hpp"
#include "string.hpp"

template <class T> class hashset;
template <class T> class hashset_iterator_rep;
Expand Down Expand Up @@ -138,6 +139,11 @@ template <class T> bool operator< (hashset<T> h1, hashset<T> h2);
*/
template <class T> hashset<T>& operator<< (hashset<T>& h, T x);

inline hashset<string>&
operator<< (hashset<string>& a, char* x) {
return a << string (x);
}

#include "hashset.ipp"

#endif // defined HASHSET_H
24 changes: 17 additions & 7 deletions tests/Kernel/Containers/hashset_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@ TEST_CASE ("test contains") {

TEST_CASE ("test init") {
auto set= hashset<string> ();
set << string ("hello") << string ("world");
set << "hello"
<< "world";
CHECK_EQ (set->contains ("hello"), true);
CHECK_EQ (set->contains ("world"), true);
CHECK_EQ (N (set), 2);
Expand All @@ -21,33 +22,42 @@ TEST_CASE ("test remove") {
auto set1= hashset<string> ();
auto set2= hashset<string> ();
CHECK_EQ (N (set1), N (set2));
set1 << string ("aaa") << string ("bbb");
set1 << "aaa"
<< "bbb";
CHECK_EQ (N (set1), N (set2) + 2);
set2 << string ("aaa") << string ("bbb") << string ("ccc");
set2 << "aaa"
<< "bbb"
<< "ccc";
set2->remove (string ("bbb"));
CHECK_EQ (N (set1), N (set2));
}

TEST_CASE ("test operator <=") {
auto out= tm_ostream ();
auto set= hashset<string> ();
set << string ("aaa") << string ("bbb");
set << "aaa"
<< "bbb";
auto set1= hashset<string> ();
set1 << string ("aaa") << string ("bbb") << string ("ccc");
set1 << "aaa"
<< "bbb"
<< "ccc";
auto out1= tm_ostream ();
CHECK_EQ (set <= set1, true);
}

TEST_CASE ("test copy") {
auto set1= hashset<string> (), set2= hashset<string> ();
set1 << string ("a") << string ("b") << string ("c");
set1 << "a"
<< "b"
<< "c";
set2= copy (set1);
CHECK_EQ (set2->contains (string ("a")), true);
CHECK_EQ (set2->contains (string ("b")), true);
CHECK_EQ (set2->contains (string ("c")), true);
CHECK_EQ (N (set1) == N (set2), true);
// Test utf-8 for Chinese
set1 << string ("你好") << string ("世界");
set1 << "你好"
<< "世界";
set2= copy (set1);
CHECK_EQ (set2->contains (string ("你好")), true);
CHECK_EQ (set2->contains (string ("世界")), true);
Expand Down
Loading