source: tests/maybe.cfa @ 0766399

Last change on this file since 0766399 was 55b060d, checked in by Peter A. Buhr <pabuhr@…>, 15 months ago

rename directories containers to collections

  • 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 : Wed Aug 30 21:45:27 2023
13// Update Count     : 3
14//
15
16#include <assert.h>
17#include <collections/maybe.hfa>
18
19void 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
29void checkGetter() {
30        maybe(int) a = 94;
31        assert(94 == get(&a));
32}
33
34/* Waiting on bug#11 to be fixed.
35void 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
45void 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
62int 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.