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 | #include <immer/array.hpp> |
10 | #include <immer/array_transient.hpp> |
11 | |
12 | #include <immer/heap/gc_heap.hpp> |
13 | #include <immer/refcount/no_refcount_policy.hpp> |
14 | |
15 | using gc_memory = immer::memory_policy< |
16 | immer::heap_policy<immer::gc_heap>, |
17 | immer::no_refcount_policy, |
18 | immer::gc_transience_policy, |
19 | false>; |
20 | |
21 | template <typename T> |
22 | using test_array_t = immer::array<T, gc_memory>; |
23 | |
24 | template <typename T> |
25 | using test_array_transient_t = immer::array_transient<T, gc_memory>; |
26 | |
27 | #define VECTOR_T test_array_t |
28 | #define VECTOR_TRANSIENT_T test_array_transient_t |
29 | |
30 | #include "../vector_transient/generic.ipp" |
31 | |
32 | // |
33 | TEST_CASE("array provides mutable data" ) |
34 | { |
35 | auto arr = immer::array<int, gc_memory>(10, 0); |
36 | CHECK(arr.size() == 10); |
37 | auto tr = arr.transient(); |
38 | CHECK(tr.data() == arr.data()); |
39 | |
40 | auto d = tr.data_mut(); |
41 | CHECK(tr.data_mut() != arr.data()); |
42 | CHECK(tr.data() == tr.data_mut()); |
43 | CHECK(arr.data() != tr.data_mut()); |
44 | |
45 | arr = tr.persistent(); |
46 | CHECK(arr.data() == d); |
47 | CHECK(arr.data() == tr.data()); |
48 | |
49 | CHECK(tr.data_mut() != arr.data()); |
50 | CHECK(tr.data() == tr.data_mut()); |
51 | CHECK(arr.data() != tr.data_mut()); |
52 | } |
53 | |