ADT
aaron-thesis
arm-eh
ast-experimental
cleanup-dtors
deferred_resn
demangler
enum
forall-pointer-decay
jacob/cs343-translation
jenkins-sandbox
new-ast
new-ast-unique-expr
new-env
no_list
persistent-indexer
pthread-emulation
qualifiedEnum
resolv-new
with_gc
Last change
on this file since 16988e8 was 91c389a, checked in by Peter A. Buhr <pabuhr@…>, 8 years ago |
change usages of assert to assert.h
|
-
Property mode
set to
100644
|
File size:
1.3 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 : Thu Jul 20 15:24:07 2017
|
---|
13 | // Update Count : 1
|
---|
14 | //
|
---|
15 |
|
---|
16 | #include <assert.h>
|
---|
17 | #include <containers/maybe>
|
---|
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 | }
|
---|
Note:
See
TracBrowser
for help on using the repository browser.