Skip to content

Commit

Permalink
Don’t assert in ops
Browse files Browse the repository at this point in the history
  • Loading branch information
elijahr committed Sep 28, 2024
1 parent 6f76feb commit c1f06bf
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 205 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ jobs:
matrix:
include:
- runs-on: macos-latest
nim-version: '2.0.8'
nim-version: 'ref:version-2-0'
sanitize-threads: 'yes'
timeout-minutes: 20

Expand Down Expand Up @@ -76,7 +76,7 @@ jobs:
matrix:
include:
- arch: aarch64
nim-version: '2.0.8'
nim-version: 'ref:version-2-0'

steps:
# Optimization: re-use cached Nim->C compilation
Expand Down
9 changes: 6 additions & 3 deletions src/lockfreequeues/ops.nim
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,9 @@ proc used*(
{.inline.} =
## Determine how many slots are taken in storage given `head`, `tail`, and
## `capacity` values.
assert validateHeadAndTail(head, tail, capacity)
# assert validateHeadAndTail(head, tail, capacity)
assert validateHeadOrTail(head, capacity)
assert validateHeadOrTail(tail, capacity)
result = tail - head
if result < 0:
# Case when front in [Capacity, 2*Capacity)
Expand All @@ -69,7 +71,6 @@ proc used*(
result += 2 * capacity



proc available*(
head: int,
tail: int,
Expand Down Expand Up @@ -128,6 +129,8 @@ proc empty*(
): bool
{.inline.} =
## Determine if storage is empty given `head` and `tail` values.
assert validateHeadAndTail(head, tail, capacity)
# assert validateHeadAndTail(head, tail, capacity)
assert validateHeadOrTail(head, capacity)
assert validateHeadOrTail(tail, capacity)
return head == tail

200 changes: 0 additions & 200 deletions tests/t_ops.nim
Original file line number Diff line number Diff line change
Expand Up @@ -249,56 +249,6 @@ suite "used(head, tail, 4)":
check(used(7, 3, 4) == 4)
check(used(7, 7, 4) == 0)

test "invalid":
expect(AssertionDefect):
discard used(0, 5, 4)
expect(AssertionDefect):
discard used(0, 6, 4)
expect(AssertionDefect):
discard used(0, 7, 4)
expect(AssertionDefect):
discard used(1, 0, 4)
expect(AssertionDefect):
discard used(1, 6, 4)
expect(AssertionDefect):
discard used(1, 7, 4)
expect(AssertionDefect):
discard used(2, 0, 4)
expect(AssertionDefect):
discard used(2, 1, 4)
expect(AssertionDefect):
discard used(2, 7, 4)
expect(AssertionDefect):
discard used(3, 0, 4)
expect(AssertionDefect):
discard used(3, 1, 4)
expect(AssertionDefect):
discard used(3, 2, 4)
expect(AssertionDefect):
discard used(4, 1, 4)
expect(AssertionDefect):
discard used(4, 2, 4)
expect(AssertionDefect):
discard used(4, 3, 4)
expect(AssertionDefect):
discard used(5, 2, 4)
expect(AssertionDefect):
discard used(5, 3, 4)
expect(AssertionDefect):
discard used(5, 4, 4)
expect(AssertionDefect):
discard used(6, 3, 4)
expect(AssertionDefect):
discard used(6, 4, 4)
expect(AssertionDefect):
discard used(6, 5, 4)
expect(AssertionDefect):
discard used(7, 4, 4)
expect(AssertionDefect):
discard used(7, 5, 4)
expect(AssertionDefect):
discard used(7, 6, 4)

suite "available(head, tail, 4)":
test "valid":
check(available(0, 0, 4) == 4)
Expand Down Expand Up @@ -342,56 +292,6 @@ suite "available(head, tail, 4)":
check(available(7, 3, 4) == 0)
check(available(7, 7, 4) == 4)

test "invalid":
expect(AssertionDefect):
discard available(0, 5, 4)
expect(AssertionDefect):
discard available(0, 6, 4)
expect(AssertionDefect):
discard available(0, 7, 4)
expect(AssertionDefect):
discard available(1, 0, 4)
expect(AssertionDefect):
discard available(1, 6, 4)
expect(AssertionDefect):
discard available(1, 7, 4)
expect(AssertionDefect):
discard available(2, 0, 4)
expect(AssertionDefect):
discard available(2, 1, 4)
expect(AssertionDefect):
discard available(2, 7, 4)
expect(AssertionDefect):
discard available(3, 0, 4)
expect(AssertionDefect):
discard available(3, 1, 4)
expect(AssertionDefect):
discard available(3, 2, 4)
expect(AssertionDefect):
discard available(4, 1, 4)
expect(AssertionDefect):
discard available(4, 2, 4)
expect(AssertionDefect):
discard available(4, 3, 4)
expect(AssertionDefect):
discard available(5, 2, 4)
expect(AssertionDefect):
discard available(5, 3, 4)
expect(AssertionDefect):
discard available(5, 4, 4)
expect(AssertionDefect):
discard available(6, 3, 4)
expect(AssertionDefect):
discard available(6, 4, 4)
expect(AssertionDefect):
discard available(6, 5, 4)
expect(AssertionDefect):
discard available(7, 4, 4)
expect(AssertionDefect):
discard available(7, 5, 4)
expect(AssertionDefect):
discard available(7, 6, 4)

suite "full(head, tail, 4)":
test "valid":
check(full(0, 0, 4) == false)
Expand Down Expand Up @@ -435,56 +335,6 @@ suite "full(head, tail, 4)":
check(full(7, 3, 4) == true)
check(full(7, 7, 4) == false)

test "invalid":
expect(AssertionDefect):
discard full(0, 5, 4)
expect(AssertionDefect):
discard full(0, 6, 4)
expect(AssertionDefect):
discard full(0, 7, 4)
expect(AssertionDefect):
discard full(1, 0, 4)
expect(AssertionDefect):
discard full(1, 6, 4)
expect(AssertionDefect):
discard full(1, 7, 4)
expect(AssertionDefect):
discard full(2, 0, 4)
expect(AssertionDefect):
discard full(2, 1, 4)
expect(AssertionDefect):
discard full(2, 7, 4)
expect(AssertionDefect):
discard full(3, 0, 4)
expect(AssertionDefect):
discard full(3, 1, 4)
expect(AssertionDefect):
discard full(3, 2, 4)
expect(AssertionDefect):
discard full(4, 1, 4)
expect(AssertionDefect):
discard full(4, 2, 4)
expect(AssertionDefect):
discard full(4, 3, 4)
expect(AssertionDefect):
discard full(5, 2, 4)
expect(AssertionDefect):
discard full(5, 3, 4)
expect(AssertionDefect):
discard full(5, 4, 4)
expect(AssertionDefect):
discard full(6, 3, 4)
expect(AssertionDefect):
discard full(6, 4, 4)
expect(AssertionDefect):
discard full(6, 5, 4)
expect(AssertionDefect):
discard full(7, 4, 4)
expect(AssertionDefect):
discard full(7, 5, 4)
expect(AssertionDefect):
discard full(7, 6, 4)

suite "empty(head, tail, 4)":
test "valid":
check(empty(0, 0, 4) == true)
Expand Down Expand Up @@ -527,53 +377,3 @@ suite "empty(head, tail, 4)":
check(empty(7, 2, 4) == false)
check(empty(7, 3, 4) == false)
check(empty(7, 7, 4) == true)

test "invalid":
expect(AssertionDefect):
discard empty(0, 5, 4)
expect(AssertionDefect):
discard empty(0, 6, 4)
expect(AssertionDefect):
discard empty(0, 7, 4)
expect(AssertionDefect):
discard empty(1, 0, 4)
expect(AssertionDefect):
discard empty(1, 6, 4)
expect(AssertionDefect):
discard empty(1, 7, 4)
expect(AssertionDefect):
discard empty(2, 0, 4)
expect(AssertionDefect):
discard empty(2, 1, 4)
expect(AssertionDefect):
discard empty(2, 7, 4)
expect(AssertionDefect):
discard empty(3, 0, 4)
expect(AssertionDefect):
discard empty(3, 1, 4)
expect(AssertionDefect):
discard empty(3, 2, 4)
expect(AssertionDefect):
discard empty(4, 1, 4)
expect(AssertionDefect):
discard empty(4, 2, 4)
expect(AssertionDefect):
discard empty(4, 3, 4)
expect(AssertionDefect):
discard empty(5, 2, 4)
expect(AssertionDefect):
discard empty(5, 3, 4)
expect(AssertionDefect):
discard empty(5, 4, 4)
expect(AssertionDefect):
discard empty(6, 3, 4)
expect(AssertionDefect):
discard empty(6, 4, 4)
expect(AssertionDefect):
discard empty(6, 5, 4)
expect(AssertionDefect):
discard empty(7, 4, 4)
expect(AssertionDefect):
discard empty(7, 5, 4)
expect(AssertionDefect):
discard empty(7, 6, 4)

0 comments on commit c1f06bf

Please sign in to comment.