1use super::*;
17
18impl<E: Environment> Cast<Address<E>> for Boolean<E> {
19 #[inline]
21 fn cast(&self) -> Address<E> {
22 self.cast_lossy()
23 }
24}
25
26impl<E: Environment> Cast<Boolean<E>> for Boolean<E> {
27 #[inline]
29 fn cast(&self) -> Boolean<E> {
30 self.cast_lossy()
31 }
32}
33
34impl<E: Environment> Cast<Field<E>> for Boolean<E> {
35 #[inline]
37 fn cast(&self) -> Field<E> {
38 self.cast_lossy()
39 }
40}
41
42impl<E: Environment> Cast<Group<E>> for Boolean<E> {
43 #[inline]
45 fn cast(&self) -> Group<E> {
46 self.cast_lossy()
47 }
48}
49
50impl<E: Environment, I: IntegerType> Cast<Integer<E, I>> for Boolean<E> {
51 #[inline]
53 fn cast(&self) -> Integer<E, I> {
54 self.cast_lossy()
55 }
56}
57
58impl<E: Environment> Cast<Scalar<E>> for Boolean<E> {
59 #[inline]
61 fn cast(&self) -> Scalar<E> {
62 self.cast_lossy()
63 }
64}
65
66impl<E: Environment> Cast<IdentifierLiteral<E>> for Boolean<E> {
67 #[inline]
74 fn cast(&self) -> IdentifierLiteral<E> {
75 let field: Field<E> = self.cast();
76 field.cast()
77 }
78}
79
80#[cfg(test)]
81mod tests {
82 use super::*;
83 use console::Cast as _;
84 use console_root::{network::MainnetV0, prelude::TestRng};
85 use snarkvm_circuit_types::environment::{Circuit, Eject, Inject, Mode, UpdatableCount, count_is};
86
87 use std::fmt::Debug;
88
89 const ITERATIONS: usize = 2;
90
91 fn sample_values(
92 i: usize,
93 mode: Mode,
94 _: &mut TestRng,
95 ) -> (console_root::types::Boolean<MainnetV0>, Boolean<Circuit>) {
96 (console_root::types::Boolean::new(i % 2 == 0), Boolean::new(mode, i % 2 == 0))
97 }
98
99 impl_check_cast!(cast, Boolean<Circuit>, console_root::types::Boolean::<MainnetV0>);
100
101 #[test]
102 fn test_boolean_to_address() {
103 check_cast::<Address<Circuit>, console_root::types::Address<MainnetV0>>(Mode::Constant, count_is!(10, 0, 0, 0));
104 check_cast::<Address<Circuit>, console_root::types::Address<MainnetV0>>(Mode::Public, count_is!(10, 0, 0, 0));
105 check_cast::<Address<Circuit>, console_root::types::Address<MainnetV0>>(Mode::Private, count_is!(10, 0, 0, 0));
106 }
107
108 #[test]
109 fn test_boolean_to_boolean() {
110 check_cast::<Boolean<Circuit>, console_root::types::Boolean<MainnetV0>>(Mode::Constant, count_is!(0, 0, 0, 0));
111 check_cast::<Boolean<Circuit>, console_root::types::Boolean<MainnetV0>>(Mode::Public, count_is!(0, 0, 0, 0));
112 check_cast::<Boolean<Circuit>, console_root::types::Boolean<MainnetV0>>(Mode::Private, count_is!(0, 0, 0, 0));
113 }
114
115 #[test]
116 fn test_boolean_to_field() {
117 check_cast::<Field<Circuit>, console_root::types::Field<MainnetV0>>(Mode::Constant, count_is!(0, 0, 0, 0));
118 check_cast::<Field<Circuit>, console_root::types::Field<MainnetV0>>(Mode::Public, count_is!(0, 0, 0, 0));
119 check_cast::<Field<Circuit>, console_root::types::Field<MainnetV0>>(Mode::Private, count_is!(0, 0, 0, 0));
120 }
121
122 #[test]
123 fn test_boolean_to_group() {
124 check_cast::<Group<Circuit>, console_root::types::Group<MainnetV0>>(Mode::Constant, count_is!(10, 0, 0, 0));
125 check_cast::<Group<Circuit>, console_root::types::Group<MainnetV0>>(Mode::Public, count_is!(10, 0, 0, 0));
126 check_cast::<Group<Circuit>, console_root::types::Group<MainnetV0>>(Mode::Private, count_is!(10, 0, 0, 0));
127 }
128
129 #[test]
130 fn test_boolean_to_i8() {
131 check_cast::<I8<Circuit>, console_root::types::I8<MainnetV0>>(Mode::Constant, count_is!(16, 0, 0, 0));
132 check_cast::<I8<Circuit>, console_root::types::I8<MainnetV0>>(Mode::Public, count_is!(16, 0, 0, 0));
133 check_cast::<I8<Circuit>, console_root::types::I8<MainnetV0>>(Mode::Private, count_is!(16, 0, 0, 0));
134 }
135
136 #[test]
137 fn test_boolean_to_i16() {
138 check_cast::<I16<Circuit>, console_root::types::I16<MainnetV0>>(Mode::Constant, count_is!(32, 0, 0, 0));
139 check_cast::<I16<Circuit>, console_root::types::I16<MainnetV0>>(Mode::Public, count_is!(32, 0, 0, 0));
140 check_cast::<I16<Circuit>, console_root::types::I16<MainnetV0>>(Mode::Private, count_is!(32, 0, 0, 0));
141 }
142
143 #[test]
144 fn test_boolean_to_i32() {
145 check_cast::<I32<Circuit>, console_root::types::I32<MainnetV0>>(Mode::Constant, count_is!(64, 0, 0, 0));
146 check_cast::<I32<Circuit>, console_root::types::I32<MainnetV0>>(Mode::Public, count_is!(64, 0, 0, 0));
147 check_cast::<I32<Circuit>, console_root::types::I32<MainnetV0>>(Mode::Private, count_is!(64, 0, 0, 0));
148 }
149
150 #[test]
151 fn test_boolean_to_i64() {
152 check_cast::<I64<Circuit>, console_root::types::I64<MainnetV0>>(Mode::Constant, count_is!(128, 0, 0, 0));
153 check_cast::<I64<Circuit>, console_root::types::I64<MainnetV0>>(Mode::Public, count_is!(128, 0, 0, 0));
154 check_cast::<I64<Circuit>, console_root::types::I64<MainnetV0>>(Mode::Private, count_is!(128, 0, 0, 0));
155 }
156
157 #[test]
158 fn test_boolean_to_i128() {
159 check_cast::<I128<Circuit>, console_root::types::I128<MainnetV0>>(Mode::Constant, count_is!(256, 0, 0, 0));
160 check_cast::<I128<Circuit>, console_root::types::I128<MainnetV0>>(Mode::Public, count_is!(256, 0, 0, 0));
161 check_cast::<I128<Circuit>, console_root::types::I128<MainnetV0>>(Mode::Private, count_is!(256, 0, 0, 0));
162 }
163
164 #[test]
165 fn test_boolean_to_scalar() {
166 check_cast::<Scalar<Circuit>, console_root::types::Scalar<MainnetV0>>(Mode::Constant, count_is!(2, 0, 0, 0));
167 check_cast::<Scalar<Circuit>, console_root::types::Scalar<MainnetV0>>(Mode::Public, count_is!(2, 0, 0, 0));
168 check_cast::<Scalar<Circuit>, console_root::types::Scalar<MainnetV0>>(Mode::Private, count_is!(2, 0, 0, 0));
169 }
170
171 #[test]
172 fn test_boolean_to_u8() {
173 check_cast::<U8<Circuit>, console_root::types::U8<MainnetV0>>(Mode::Constant, count_is!(16, 0, 0, 0));
174 check_cast::<U8<Circuit>, console_root::types::U8<MainnetV0>>(Mode::Public, count_is!(16, 0, 0, 0));
175 check_cast::<U8<Circuit>, console_root::types::U8<MainnetV0>>(Mode::Private, count_is!(16, 0, 0, 0));
176 }
177
178 #[test]
179 fn test_boolean_to_u16() {
180 check_cast::<U16<Circuit>, console_root::types::U16<MainnetV0>>(Mode::Constant, count_is!(32, 0, 0, 0));
181 check_cast::<U16<Circuit>, console_root::types::U16<MainnetV0>>(Mode::Public, count_is!(32, 0, 0, 0));
182 check_cast::<U16<Circuit>, console_root::types::U16<MainnetV0>>(Mode::Private, count_is!(32, 0, 0, 0));
183 }
184
185 #[test]
186 fn test_boolean_to_u32() {
187 check_cast::<U32<Circuit>, console_root::types::U32<MainnetV0>>(Mode::Constant, count_is!(64, 0, 0, 0));
188 check_cast::<U32<Circuit>, console_root::types::U32<MainnetV0>>(Mode::Public, count_is!(64, 0, 0, 0));
189 check_cast::<U32<Circuit>, console_root::types::U32<MainnetV0>>(Mode::Private, count_is!(64, 0, 0, 0));
190 }
191
192 #[test]
193 fn test_boolean_to_u64() {
194 check_cast::<U64<Circuit>, console_root::types::U64<MainnetV0>>(Mode::Constant, count_is!(128, 0, 0, 0));
195 check_cast::<U64<Circuit>, console_root::types::U64<MainnetV0>>(Mode::Public, count_is!(128, 0, 0, 0));
196 check_cast::<U64<Circuit>, console_root::types::U64<MainnetV0>>(Mode::Private, count_is!(128, 0, 0, 0));
197 }
198
199 #[test]
200 fn test_boolean_to_u128() {
201 check_cast::<U128<Circuit>, console_root::types::U128<MainnetV0>>(Mode::Constant, count_is!(256, 0, 0, 0));
202 check_cast::<U128<Circuit>, console_root::types::U128<MainnetV0>>(Mode::Public, count_is!(256, 0, 0, 0));
203 check_cast::<U128<Circuit>, console_root::types::U128<MainnetV0>>(Mode::Private, count_is!(256, 0, 0, 0));
204 }
205}