[20877d2] | 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 | // result.c -- |
---|
| 8 | // |
---|
| 9 | // Author : Andrew Beach |
---|
| 10 | // Created On : Thr May 25 16:50:00 2017 |
---|
[91c389a] | 11 | // Last Modified By : Peter A. Buhr |
---|
| 12 | // Last Modified On : Thu Jul 20 15:24:12 2017 |
---|
| 13 | // Update Count : 1 |
---|
[20877d2] | 14 | // |
---|
| 15 | |
---|
[91c389a] | 16 | #include <assert.h> |
---|
[20877d2] | 17 | #include <containers/result> |
---|
| 18 | |
---|
| 19 | void checkPredicates() { |
---|
| 20 | result(int, char) pass = {1, 4}; |
---|
[0892b1b] | 21 | assert(pass); |
---|
[20877d2] | 22 | assert(has_value(&pass)); |
---|
| 23 | |
---|
| 24 | result(int, char) fail = {0, '!'}; |
---|
| 25 | assert((fail ? false : true)); |
---|
| 26 | assert(!has_value(&fail)); |
---|
| 27 | } |
---|
| 28 | |
---|
| 29 | /* Waiting for bug#11 to be fixed. |
---|
| 30 | void checkNamedConstructors() { |
---|
| 31 | result(int, char) = result_value(4); |
---|
| 32 | assert(has_value(&pass)); |
---|
| 33 | |
---|
| 34 | result(int, char) fail = result_error('!'); |
---|
| 35 | assert(!has_value(&fail)); |
---|
| 36 | } |
---|
| 37 | */ |
---|
| 38 | |
---|
| 39 | void checkGetters() { |
---|
| 40 | result(int, char) pass = {1, 4}; |
---|
| 41 | assert(4 == get(&pass)); |
---|
| 42 | |
---|
| 43 | result(int, char) fail = {0, '!'}; |
---|
| 44 | assert('!' == get_error(&fail)); |
---|
| 45 | } |
---|
| 46 | |
---|
| 47 | void checkSetters() { |
---|
| 48 | result(int, char) fee = {1, -7}; |
---|
| 49 | assert(-7 == get(&fee)); |
---|
| 50 | set(&fee, 42); |
---|
| 51 | assert(42 == get(&fee)); |
---|
| 52 | set_error(&fee, '@'); |
---|
| 53 | assert('@' == get_error(&fee)); |
---|
| 54 | |
---|
| 55 | result(int, char) fy = {1, -7}; |
---|
| 56 | fee = fy; |
---|
| 57 | assert(-7 == get(&fee)); |
---|
| 58 | result(int, char) foe = {0, '!'}; |
---|
| 59 | fee = foe; |
---|
| 60 | assert('!' == get_error(&fee)); |
---|
| 61 | } |
---|
| 62 | |
---|
| 63 | int main(int argc, char * argv[]) { |
---|
| 64 | checkPredicates(); |
---|
| 65 | //checkNamedConstructors(); |
---|
| 66 | checkGetters(); |
---|
| 67 | checkSetters(); |
---|
| 68 | } |
---|