Skip to content

Commit

Permalink
Fix logic error in Vector::ptr_eq
Browse files Browse the repository at this point in the history
I believe the intent of this code was to consider the last two
operations as a single OR. (I may be wrong)

- closes bodil#131
  • Loading branch information
cmyr committed May 13, 2020
1 parent c15fa7f commit edd5710
Showing 1 changed file with 29 additions and 2 deletions.
31 changes: 29 additions & 2 deletions src/vector/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -347,8 +347,8 @@ impl<A: Clone> Vector<A> {
&& cmp_chunk(&left.inner_f, &right.inner_f)
&& cmp_chunk(&left.inner_b, &right.inner_b)
&& cmp_chunk(&left.outer_b, &right.outer_b)
&& (left.middle.is_empty() && right.middle.is_empty())
|| Ref::ptr_eq(&left.middle, &right.middle)
&& ((left.middle.is_empty() && right.middle.is_empty())
|| Ref::ptr_eq(&left.middle, &right.middle))
}
_ => false,
}
Expand Down Expand Up @@ -2481,6 +2481,33 @@ mod test {
assert_eq!(vec.len(), rev_vec.len());
}

#[test]
fn issue_131() {
let smol = std::iter::repeat(42).take(64).collect::<Vector<_>>();
let mut smol2 = smol.clone();
assert!(smol.ptr_eq(&smol2));
smol2.set(63, 420);
assert!(!smol.ptr_eq(&smol2));

let huge = std::iter::repeat(42).take(65).collect::<Vector<_>>();
let mut huge2 = huge.clone();
assert!(huge.ptr_eq(&huge2));
huge2.set(63, 420);
assert!(!huge.ptr_eq(&huge2));
}

#[test]
fn ptr_eq() {
for len in 32..256 {
let input = std::iter::repeat(42).take(len).collect::<Vector<_>>();
let mut inp2 = input.clone();
assert!(input.ptr_eq(&inp2));
inp2.set(len-1, 98);
assert_ne!(inp2.get(len-1), input.get(len-1));
assert!(!input.ptr_eq(&inp2), len);
}
}

proptest! {
#[test]
fn iter(ref vec in vec(i32::ANY, 0..1000)) {
Expand Down

0 comments on commit edd5710

Please sign in to comment.