ADTast-experimental
Last change
on this file since be1d00c was
66812dd,
checked in by Peter A. Buhr <pabuhr@…>, 4 years ago
|
convert tests to always print output (no empty .expect files)
|
-
Property mode set to
100644
|
File size:
1.4 KB
|
Line | |
---|
1 | // |
---|
2 | // Cforall Version 1.0.0 Copyright (C) 2015 University of Waterloo |
---|
3 | // |
---|
4 | // The contents of this file are covered under the licence agreement in the |
---|
5 | // file "LICENCE" distributed with Cforall. |
---|
6 | // |
---|
7 | // maybe.c -- |
---|
8 | // |
---|
9 | // Author : Andrew Beach |
---|
10 | // Created On : Thr May 25 16:02:00 2017 |
---|
11 | // Last Modified By : Peter A. Buhr |
---|
12 | // Last Modified On : Fri Sep 25 15:13:28 2020 |
---|
13 | // Update Count : 2 |
---|
14 | // |
---|
15 | |
---|
16 | #include <assert.h> |
---|
17 | #include <containers/maybe.hfa> |
---|
18 | |
---|
19 | void checkPredicates() { |
---|
20 | maybe(int) filled = 4; |
---|
21 | assert(filled); |
---|
22 | assert(has_value(&filled)); |
---|
23 | |
---|
24 | maybe(int) empty = {}; |
---|
25 | assert(empty ? false : true); |
---|
26 | assert(!has_value(&empty)); |
---|
27 | } |
---|
28 | |
---|
29 | void checkGetter() { |
---|
30 | maybe(int) a = 94; |
---|
31 | assert(94 == get(&a)); |
---|
32 | } |
---|
33 | |
---|
34 | /* Waiting on bug#11 to be fixed. |
---|
35 | void checkNamedConstructors() { |
---|
36 | maybe(char) letter = maybe_value('a'); |
---|
37 | assert(has_value(&letter)); |
---|
38 | assert('a' == get(&letter)); |
---|
39 | |
---|
40 | maybe(char) rune = maybe_none(); |
---|
41 | assert(!has_value(&rune)); |
---|
42 | } |
---|
43 | */ |
---|
44 | |
---|
45 | void checkSetters() { |
---|
46 | maybe(int) fee = 3; |
---|
47 | assert(3 == get(&fee)); |
---|
48 | set(&fee, 7); |
---|
49 | assert(7 == get(&fee)); |
---|
50 | set_none(&fee); |
---|
51 | assert(!has_value(&fee)); |
---|
52 | |
---|
53 | maybe(int) fy = 4; |
---|
54 | maybe(int) foe = 8; |
---|
55 | maybe(int) fum = {}; |
---|
56 | fy = foe; |
---|
57 | assert(8 == get(&fy)); |
---|
58 | fy = fum; |
---|
59 | assert(!has_value(&fy)); |
---|
60 | } |
---|
61 | |
---|
62 | int main(int argc, char * argv[]) { |
---|
63 | checkPredicates(); |
---|
64 | checkGetter(); |
---|
65 | //checkNamedConstructors(); |
---|
66 | checkSetters(); |
---|
67 | printf( "done\n" ); // non-empty .expect file |
---|
68 | } |
---|
Note: See
TracBrowser
for help on using the repository browser.