Skip to content

Commit

Permalink
Change boolean debug representation (#964)
Browse files Browse the repository at this point in the history
* Change boolean debug representation

The default one is too verbose.

Before:

```
(StdArray([BA32(BitArray<u8, bitvec::order::Lsb0> { addr: 0x12b842774, head: 000, bits: 32 } [1, 1, 0, 1, 0, 1, 1, 1, 0, 1, 1, 0, 0, 1, 0, 1, 0, 1, 1, 0, 0, 0, 1, 1, 1, 1, 0, 1, 1, 1, 1, 1])]), StdArray([BA32(BitArray<u8, bitvec::order::Lsb0> { addr: 0x12b842778, head: 000, bits: 32 } [0, 0, 1, 0, 1, 1, 1, 1, 1, 1, 1, 1, 0, 1, 0, 0, 0, 0, 1, 1, 0, 1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0])]))
```

after

```
(StdArray([BA32([1, 1, 0, 1, 0, 1, 1, 1, 0, 1, 1, 0, 0, 1, 0, 1, 0, 1, 1, 0, 0, 0, 1, 1, 1, 1, 0, 1, 1, 1, 1, 1])]), StdArray([BA32([0, 0, 1, 0, 1, 1, 1, 1, 1, 1, 1, 1, 0, 1, 0, 0, 0, 0, 1, 1, 0, 1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0])]))
```

* Add a test and fix a bug

It is always about not having the tests
  • Loading branch information
akoshelev authored Mar 9, 2024
1 parent f3e138b commit 6690fb0
Showing 1 changed file with 17 additions and 1 deletion.
18 changes: 17 additions & 1 deletion ipa-core/src/ff/boolean_array.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
use std::fmt::{Debug, Formatter};

use bitvec::{
prelude::{BitArr, Lsb0},
slice::Iter,
Expand Down Expand Up @@ -254,9 +256,16 @@ macro_rules! boolean_array_impl {
type Store = BitArr!(for $bits, in u8, Lsb0);

/// A Boolean array with $bits bits.
#[derive(Clone, Copy, PartialEq, Eq, Debug)]
#[derive(Clone, Copy, PartialEq, Eq)]
pub struct $name(pub(super) Store);

impl Debug for $name {
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
f.write_str(stringify!($name))?;
self.0.data.fmt(f)
}
}

impl $name {
#[cfg(all(test, unit_test))]
const STORE_LEN: usize = bitvec::mem::elts::<u8>($bits);
Expand Down Expand Up @@ -697,6 +706,13 @@ macro_rules! boolean_array_impl {
"Failed to deserialize a valid value: {ba:?}"
);
}

#[test]
fn debug() {
let expected = format!("{}{:?}", stringify!($name), $name::ZERO.0.data);
let actual = format!("{:?}", $name::ZERO);
assert_eq!(expected, actual);
}
}
}

Expand Down

0 comments on commit 6690fb0

Please sign in to comment.