aboutsummaryrefslogtreecommitdiff
path: root/pw_preprocessor/boolean_test.cc
blob: 40a00eb8fea9aa42323fff43db8d40ab4342ec5c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
// Copyright 2019 The Pigweed Authors
//
// Licensed under the Apache License, Version 2.0 (the "License"); you may not
// use this file except in compliance with the License. You may obtain a copy of
// the License at
//
//     https://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
// WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
// License for the specific language governing permissions and limitations under
// the License.
//
// All of these tests are static asserts. If the test compiles, it has already
// passed. The TEST functions are used for organization only.
#include "pw_preprocessor/boolean.h"

#include "pw_unit_test/framework.h"

namespace pw {
namespace {

#define ONE 1
#define ZERO() 0

TEST(BooleanMacros, And) {
  static_assert(PW_AND(ZERO(), 0) == 0);
  static_assert(PW_AND(ZERO(), ONE) == 0);
  static_assert(PW_AND(1, 0) == 0);
  static_assert(PW_AND(ONE, PW_NOT(ZERO())) == 1);
}

TEST(BooleanMacros, Or) {
  static_assert(PW_OR(ZERO(), 0) == 0);
  static_assert(PW_OR(ZERO(), ONE) == 1);
  static_assert(PW_OR(1, 0) == 1);
  static_assert(PW_OR(ONE, PW_NOT(ZERO())) == 1);
}

TEST(BooleanMacros, Not) {
  static_assert(PW_NOT(0) == 1);
  static_assert(PW_NOT(1) == 0);
  static_assert(PW_NOT(ONE) == 0);
  static_assert(PW_NOT(ZERO()) == 1);
}

TEST(BooleanMacros, Xor) {
  static_assert(PW_XOR(ZERO(), 0) == 0);
  static_assert(PW_XOR(ZERO(), ONE) == 1);
  static_assert(PW_XOR(1, 0) == 1);
  static_assert(PW_XOR(ONE, PW_NOT(ZERO())) == 0);
}

TEST(BooleanMacros, Nand) {
  static_assert(PW_NAND(ZERO(), 0) == 1);
  static_assert(PW_NAND(ZERO(), ONE) == 1);
  static_assert(PW_NAND(1, 0) == 1);
  static_assert(PW_NAND(ONE, PW_NOT(ZERO())) == 0);
}

TEST(BooleanMacros, Nor) {
  static_assert(PW_NOR(ZERO(), 0) == 1);
  static_assert(PW_NOR(ZERO(), ONE) == 0);
  static_assert(PW_NOR(1, 0) == 0);
  static_assert(PW_NOR(ONE, PW_NOT(ZERO())) == 0);
}

TEST(BooleanMacros, Xnor) {
  static_assert(PW_XNOR(ZERO(), 0) == 1);
  static_assert(PW_XNOR(ZERO(), ONE) == 0);
  static_assert(PW_XNOR(1, 0) == 0);
  static_assert(PW_XNOR(ONE, PW_NOT(ZERO())) == 1);
}

TEST(BooleanMacros, Nested) {
  static_assert(PW_AND(1, PW_AND(PW_OR(ZERO(), ONE), PW_XOR(ONE, 0))) == 1);
}

}  // namespace
}  // namespace pw