Skip to content

Commit

Permalink
ExamplePanicked: More fun table test
Browse files Browse the repository at this point in the history
  • Loading branch information
earthboundkid committed Jan 13, 2025
1 parent d19f180 commit 954a757
Showing 1 changed file with 13 additions and 5 deletions.
18 changes: 13 additions & 5 deletions panic_example_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,21 @@ func ExamplePanicked() {
// Because a panic fails a test by default,
// testing that an operation does not panic is less necessary,
// but may be helpful in a table test.
for _, denom := range []int{-1, 0, 1, 1_000} {
shouldPanic := denom == 0
for _, testcase := range []struct {
num, denom, want int
shouldPanic bool
}{
{0, 1, 0, false},
{1, 1, 1, false},
{1, 0, 0xbadc0ffee, true},
{0, 0, 0xbadc0ffee, true},
} {
got := 0xbadc0ffee
panicVal := be.Panicked(func() {
divide(1, denom)
got = divide(testcase.num, testcase.denom)
})
be.Equal(t, shouldPanic, panicVal != nil)
be.Equal(t, testcase.want, got)
be.Equal(t, testcase.shouldPanic, panicVal != nil)
}

// Output:
}

0 comments on commit 954a757

Please sign in to comment.