reifydb_type/value/boolean/
compare.rs

1// Copyright (c) reifydb.com 2025
2// This file is licensed under the MIT, see license.md file
3
4#[inline]
5pub fn is_equal(l: bool, r: bool) -> bool {
6	l == r
7}
8
9#[inline]
10pub fn is_not_equal(l: bool, r: bool) -> bool {
11	l != r
12}
13
14#[inline]
15pub fn is_greater_than(l: bool, r: bool) -> bool {
16	l > r
17}
18
19#[inline]
20pub fn is_greater_than_equal(l: bool, r: bool) -> bool {
21	l >= r
22}
23
24#[inline]
25pub fn is_less_than(l: bool, r: bool) -> bool {
26	l < r
27}
28
29#[inline]
30pub fn is_less_than_equal(l: bool, r: bool) -> bool {
31	l <= r
32}
33
34#[inline]
35pub fn logical_and(l: bool, r: bool) -> bool {
36	l && r
37}
38
39#[inline]
40pub fn logical_or(l: bool, r: bool) -> bool {
41	l || r
42}
43
44#[inline]
45pub fn logical_not(b: bool) -> bool {
46	!b
47}
48
49#[inline]
50pub fn logical_xor(l: bool, r: bool) -> bool {
51	l ^ r
52}
53
54#[cfg(test)]
55mod tests {
56	use super::*;
57
58	#[test]
59	fn test_is_equal() {
60		assert!(is_equal(true, true));
61		assert!(is_equal(false, false));
62		assert!(!is_equal(true, false));
63		assert!(!is_equal(false, true));
64	}
65
66	#[test]
67	fn test_is_not_equal() {
68		assert!(!is_not_equal(true, true));
69		assert!(!is_not_equal(false, false));
70		assert!(is_not_equal(true, false));
71		assert!(is_not_equal(false, true));
72	}
73
74	#[test]
75	fn test_is_greater_than() {
76		assert!(is_greater_than(true, false));
77		assert!(!is_greater_than(false, true));
78		assert!(!is_greater_than(true, true));
79		assert!(!is_greater_than(false, false));
80	}
81
82	#[test]
83	fn test_is_greater_than_equal() {
84		assert!(is_greater_than_equal(true, false));
85		assert!(!is_greater_than_equal(false, true));
86		assert!(is_greater_than_equal(true, true));
87		assert!(is_greater_than_equal(false, false));
88	}
89
90	#[test]
91	fn test_is_less_than() {
92		assert!(!is_less_than(true, false));
93		assert!(is_less_than(false, true));
94		assert!(!is_less_than(true, true));
95		assert!(!is_less_than(false, false));
96	}
97
98	#[test]
99	fn test_is_less_than_equal() {
100		assert!(!is_less_than_equal(true, false));
101		assert!(is_less_than_equal(false, true));
102		assert!(is_less_than_equal(true, true));
103		assert!(is_less_than_equal(false, false));
104	}
105
106	#[test]
107	fn test_logical_and() {
108		assert!(logical_and(true, true));
109		assert!(!logical_and(true, false));
110		assert!(!logical_and(false, true));
111		assert!(!logical_and(false, false));
112	}
113
114	#[test]
115	fn test_logical_or() {
116		assert!(logical_or(true, true));
117		assert!(logical_or(true, false));
118		assert!(logical_or(false, true));
119		assert!(!logical_or(false, false));
120	}
121
122	#[test]
123	fn test_logical_not() {
124		assert!(!logical_not(true));
125		assert!(logical_not(false));
126	}
127
128	#[test]
129	fn test_logical_xor() {
130		assert!(!logical_xor(true, true));
131		assert!(logical_xor(true, false));
132		assert!(logical_xor(false, true));
133		assert!(!logical_xor(false, false));
134	}
135}