Skip to content

Commit

Permalink
deque: op_get wrapping around test
Browse files Browse the repository at this point in the history
  • Loading branch information
yj-qin authored and bobzhang committed Apr 3, 2024
1 parent 2922198 commit dc28ec9
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions deque/deque.mbt
Original file line number Diff line number Diff line change
Expand Up @@ -310,7 +310,7 @@ pub fn op_get[T](self : Deque[T], index : Int) -> T {
if self.head + index < self.buf.length() {
self.buf[self.head + index]
} else {
self.buf[index - self.head + 1]
self.buf[(self.head + index) % self.buf.length()]
}
}

Expand All @@ -321,8 +321,9 @@ test "op_get" {
@assertion.assert_eq(dq[2], 3)?
@assertion.assert_eq(dq[3], 4)?
@assertion.assert_eq(dq[4], 5)?
let _ = dq.pop_front()
dq.push_back(1)
@assertion.assert_eq(dq[5], 1)?
@assertion.assert_eq(dq[4], 1)?
dq.push_front(2)
@assertion.assert_eq(dq[0], 2)?
}
Expand Down

0 comments on commit dc28ec9

Please sign in to comment.