1 /*******************************************************************************
2 
3     Copyright:
4         Copyright (c) 2017 dunnhumby Germany GmbH.
5         All rights reserved.
6 
7     License:
8         Boost Software License Version 1.0. See LICENSE_BOOST.txt for details.
9         Alternatively, this file may be distributed under the terms of the Tango
10         3-Clause BSD License (see LICENSE_BSD.txt for details).
11 
12 *******************************************************************************/
13 
14 module ocean.meta.types.ReduceType_test;
15 
16 import ocean.transition;
17 import ocean.meta.traits.Basic;
18 import ocean.meta.types.ReduceType;
19 
20 struct ExampleReducer
21 {
22     alias int Result;
23     enum seed = 0;
24 
25     Result accumulate ( Result accum, Result next )
26     {
27         return accum + next;
28     }
29 
30     Result visit ( T ) ( )
31     {
32         if (isIntegerType!(T))
33             return 1;
34         else
35             return 0;
36     }
37 }
38 
39 unittest
40 {
41     static assert (ReduceType!(int, ExampleReducer) == 1);
42     static assert (ReduceType!(int[int], ExampleReducer) == 2);
43 }
44 
45 
46 struct CountSubTypes
47 {
48     alias int Result;
49     enum seed = 0;
50 
51     Result accumulate ( Result accum, Result next )
52     {
53         return accum + next;
54     }
55 
56     Result visit ( T ) ( )
57     {
58         return 1;
59     }
60 }
61 
62 unittest
63 {
64     static struct Sample
65     {
66         static struct Nested
67         {
68             mixin(Typedef!(int, "SomeInt"));
69             SomeInt field;
70         }
71 
72         Nested[3][] arr;
73     }
74 
75     // root struct + dynamic array field + static array element + nested struct
76     // element + nested struct field (typedef) + int
77     static assert (ReduceType!(Sample, CountSubTypes) == 6);
78 }