-
Notifications
You must be signed in to change notification settings - Fork 275
Expand file tree
/
Copy pathcollections.cpp
More file actions
57 lines (49 loc) · 1.22 KB
/
collections.cpp
File metadata and controls
57 lines (49 loc) · 1.22 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
#include "pch.h"
import winrt.Windows.Foundation;
using namespace winrt;
using namespace Windows::Foundation::Collections;
TEST_CASE("module_vector")
{
auto vec = single_threaded_vector<int>();
vec.Append(10);
vec.Append(20);
vec.Append(30);
REQUIRE(vec.Size() == 3);
REQUIRE(vec.GetAt(0) == 10);
REQUIRE(vec.GetAt(2) == 30);
vec.RemoveAtEnd();
REQUIRE(vec.Size() == 2);
}
TEST_CASE("module_map")
{
auto map = single_threaded_map<hstring, hstring>();
map.Insert(L"key1", L"value1");
map.Insert(L"key2", L"value2");
REQUIRE(map.Size() == 2);
REQUIRE(map.Lookup(L"key1") == L"value1");
REQUIRE(map.HasKey(L"key2"));
REQUIRE(!map.HasKey(L"key3"));
}
TEST_CASE("module_observable_vector")
{
auto vec = single_threaded_observable_vector<int>();
int change_count = 0;
auto token = vec.VectorChanged([&](auto&&, auto&&) { ++change_count; });
vec.Append(1);
vec.Append(2);
REQUIRE(change_count == 2);
vec.VectorChanged(token);
}
TEST_CASE("module_iterable")
{
auto vec = single_threaded_vector<int>();
vec.Append(1);
vec.Append(2);
vec.Append(3);
int sum = 0;
for (auto v : vec)
{
sum += v;
}
REQUIRE(sum == 6);
}