blob: 40a00eb8fea9aa42323fff43db8d40ab4342ec5c [file] [log] [blame]
Alexei Frolovc10c8122019-11-01 16:31:19 -07001// Copyright 2019 The Pigweed Authors
2//
3// Licensed under the Apache License, Version 2.0 (the "License"); you may not
Wyatt Hepler1a960942019-11-26 14:13:38 -08004// use this file except in compliance with the License. You may obtain a copy of
5// the License at
Alexei Frolovc10c8122019-11-01 16:31:19 -07006//
7// https://www.apache.org/licenses/LICENSE-2.0
8//
9// Unless required by applicable law or agreed to in writing, software
10// distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
11// WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
Wyatt Hepler1a960942019-11-26 14:13:38 -080012// License for the specific language governing permissions and limitations under
13// the License.
Alexei Frolovc10c8122019-11-01 16:31:19 -070014//
15// All of these tests are static asserts. If the test compiles, it has already
16// passed. The TEST functions are used for organization only.
17#include "pw_preprocessor/boolean.h"
18
19#include "pw_unit_test/framework.h"
20
21namespace pw {
22namespace {
23
24#define ONE 1
25#define ZERO() 0
26
27TEST(BooleanMacros, And) {
28 static_assert(PW_AND(ZERO(), 0) == 0);
29 static_assert(PW_AND(ZERO(), ONE) == 0);
30 static_assert(PW_AND(1, 0) == 0);
31 static_assert(PW_AND(ONE, PW_NOT(ZERO())) == 1);
32}
33
34TEST(BooleanMacros, Or) {
35 static_assert(PW_OR(ZERO(), 0) == 0);
36 static_assert(PW_OR(ZERO(), ONE) == 1);
37 static_assert(PW_OR(1, 0) == 1);
38 static_assert(PW_OR(ONE, PW_NOT(ZERO())) == 1);
39}
40
41TEST(BooleanMacros, Not) {
42 static_assert(PW_NOT(0) == 1);
43 static_assert(PW_NOT(1) == 0);
44 static_assert(PW_NOT(ONE) == 0);
45 static_assert(PW_NOT(ZERO()) == 1);
46}
47
48TEST(BooleanMacros, Xor) {
49 static_assert(PW_XOR(ZERO(), 0) == 0);
50 static_assert(PW_XOR(ZERO(), ONE) == 1);
51 static_assert(PW_XOR(1, 0) == 1);
52 static_assert(PW_XOR(ONE, PW_NOT(ZERO())) == 0);
53}
54
55TEST(BooleanMacros, Nand) {
56 static_assert(PW_NAND(ZERO(), 0) == 1);
57 static_assert(PW_NAND(ZERO(), ONE) == 1);
58 static_assert(PW_NAND(1, 0) == 1);
59 static_assert(PW_NAND(ONE, PW_NOT(ZERO())) == 0);
60}
61
62TEST(BooleanMacros, Nor) {
63 static_assert(PW_NOR(ZERO(), 0) == 1);
64 static_assert(PW_NOR(ZERO(), ONE) == 0);
65 static_assert(PW_NOR(1, 0) == 0);
66 static_assert(PW_NOR(ONE, PW_NOT(ZERO())) == 0);
67}
68
69TEST(BooleanMacros, Xnor) {
70 static_assert(PW_XNOR(ZERO(), 0) == 1);
71 static_assert(PW_XNOR(ZERO(), ONE) == 0);
72 static_assert(PW_XNOR(1, 0) == 0);
73 static_assert(PW_XNOR(ONE, PW_NOT(ZERO())) == 1);
74}
75
76TEST(BooleanMacros, Nested) {
77 static_assert(PW_AND(1, PW_AND(PW_OR(ZERO(), ONE), PW_XOR(ONE, 0))) == 1);
78}
79
80} // namespace
81} // namespace pw