use super::*;
impl<E: Environment> ToField for Group<E> {
type Field = Field<E>;
fn to_field(&self) -> Result<Self::Field> {
Ok(self.to_x_coordinate())
}
}
#[cfg(test)]
mod tests {
use super::*;
use snarkvm_console_network_environment::Console;
type CurrentEnvironment = Console;
const ITERATIONS: u64 = 10_000;
#[test]
fn test_to_field() -> Result<()> {
let mut rng = TestRng::default();
for _ in 0..ITERATIONS {
let group: Group<CurrentEnvironment> = Uniform::rand(&mut rng);
let candidate = group.to_field()?;
let expected = group.to_bits_le();
for (index, candidate_bit) in candidate.to_bits_le().iter().enumerate() {
assert_eq!(expected[index], *candidate_bit);
}
}
Ok(())
}
}