1 | // |
---|---|
2 | // immer: immutable data structures for C++ |
3 | // Copyright (C) 2016, 2017, 2018 Juan Pedro Bolivar Puente |
4 | // |
5 | // This software is distributed under the Boost Software License, Version 1.0. |
6 | // See accompanying file LICENSE or copy at http://boost.org/LICENSE_1_0.txt |
7 | // |
8 | |
9 | #ifndef ATOM_T |
10 | #error "define the box template to use in ATOM_T" |
11 | #endif |
12 | |
13 | #include <catch.hpp> |
14 | |
15 | template <typename T> |
16 | using BOX_T = typename ATOM_T<T>::box_type; |
17 | |
18 | TEST_CASE("construction") |
19 | { |
20 | ATOM_T<int> x; |
21 | } |
22 | |
23 | TEST_CASE("store, load, exchange") |
24 | { |
25 | ATOM_T<int> x; |
26 | CHECK(x.load() == BOX_T<int>{0}); |
27 | x.store(42); |
28 | CHECK(x.load() == BOX_T<int>{42}); |
29 | auto old = x.exchange(12); |
30 | CHECK(old == 42); |
31 | CHECK(x.load() == BOX_T<int>{12}); |
32 | } |
33 | |
34 | TEST_CASE("box conversion") |
35 | { |
36 | ATOM_T<int> x; |
37 | auto v1 = BOX_T<int>{42}; |
38 | x = v1; |
39 | auto v2 = BOX_T<int>{x}; |
40 | CHECK(v1 == v2); |
41 | } |
42 | |
43 | TEST_CASE("value conversion") |
44 | { |
45 | ATOM_T<int> x; |
46 | x = 42; |
47 | auto v = int{x}; |
48 | CHECK(v == 42); |
49 | } |
50 | |
51 | TEST_CASE("update") |
52 | { |
53 | ATOM_T<int> x{42}; |
54 | x.update([] (auto x) { return x + 2; }); |
55 | CHECK(x.load() == 44); |
56 | } |
57 |