Commit b803cfd2 authored by Andreas Bigger's avatar Andreas Bigger

dynamic assertions

parent 59c14665
package batcher_test package batcher_test
import ( import (
"math"
"testing" "testing"
"github.com/ethereum-optimism/optimism/op-batcher/batcher" "github.com/ethereum-optimism/optimism/op-batcher/batcher"
...@@ -16,8 +17,8 @@ func TestInputThreshold(t *testing.T) { ...@@ -16,8 +17,8 @@ func TestInputThreshold(t *testing.T) {
ApproxComprRatio float64 ApproxComprRatio float64
} }
type test struct { type test struct {
input testInput input testInput
want uint64 assertion func(uint64)
} }
// Construct test cases that test the boundary conditions // Construct test cases that test the boundary conditions
...@@ -28,7 +29,9 @@ func TestInputThreshold(t *testing.T) { ...@@ -28,7 +29,9 @@ func TestInputThreshold(t *testing.T) {
TargetNumFrames: 1, TargetNumFrames: 1,
ApproxComprRatio: 0.4, ApproxComprRatio: 0.4,
}, },
want: 2, assertion: func(output uint64) {
require.Equal(t, uint64(2), output)
},
}, },
{ {
input: testInput{ input: testInput{
...@@ -36,7 +39,9 @@ func TestInputThreshold(t *testing.T) { ...@@ -36,7 +39,9 @@ func TestInputThreshold(t *testing.T) {
TargetNumFrames: 1, TargetNumFrames: 1,
ApproxComprRatio: 1, ApproxComprRatio: 1,
}, },
want: 1, assertion: func(output uint64) {
require.Equal(t, uint64(1), output)
},
}, },
{ {
input: testInput{ input: testInput{
...@@ -44,7 +49,9 @@ func TestInputThreshold(t *testing.T) { ...@@ -44,7 +49,9 @@ func TestInputThreshold(t *testing.T) {
TargetNumFrames: 1, TargetNumFrames: 1,
ApproxComprRatio: 2, ApproxComprRatio: 2,
}, },
want: 0, assertion: func(output uint64) {
require.Equal(t, uint64(0), output)
},
}, },
{ {
input: testInput{ input: testInput{
...@@ -52,7 +59,9 @@ func TestInputThreshold(t *testing.T) { ...@@ -52,7 +59,9 @@ func TestInputThreshold(t *testing.T) {
TargetNumFrames: 1, TargetNumFrames: 1,
ApproxComprRatio: 0.4, ApproxComprRatio: 0.4,
}, },
want: 250_000, assertion: func(output uint64) {
require.Equal(t, uint64(250_000), output)
},
}, },
{ {
input: testInput{ input: testInput{
...@@ -60,7 +69,9 @@ func TestInputThreshold(t *testing.T) { ...@@ -60,7 +69,9 @@ func TestInputThreshold(t *testing.T) {
TargetNumFrames: 100000, TargetNumFrames: 100000,
ApproxComprRatio: 0.4, ApproxComprRatio: 0.4,
}, },
want: 250_000, assertion: func(output uint64) {
require.Equal(t, uint64(250_000), output)
},
}, },
{ {
input: testInput{ input: testInput{
...@@ -68,7 +79,9 @@ func TestInputThreshold(t *testing.T) { ...@@ -68,7 +79,9 @@ func TestInputThreshold(t *testing.T) {
TargetNumFrames: 100000, TargetNumFrames: 100000,
ApproxComprRatio: 0.4, ApproxComprRatio: 0.4,
}, },
want: 25_000_000_000, assertion: func(output uint64) {
require.Equal(t, uint64(25_000_000_000), output)
},
}, },
{ {
input: testInput{ input: testInput{
...@@ -76,7 +89,9 @@ func TestInputThreshold(t *testing.T) { ...@@ -76,7 +89,9 @@ func TestInputThreshold(t *testing.T) {
TargetNumFrames: 1, TargetNumFrames: 1,
ApproxComprRatio: 0.000001, ApproxComprRatio: 0.000001,
}, },
want: 1_000_000, assertion: func(output uint64) {
require.Equal(t, uint64(1_000_000), output)
},
}, },
{ {
input: testInput{ input: testInput{
...@@ -84,7 +99,10 @@ func TestInputThreshold(t *testing.T) { ...@@ -84,7 +99,10 @@ func TestInputThreshold(t *testing.T) {
TargetNumFrames: 0, TargetNumFrames: 0,
ApproxComprRatio: 0, ApproxComprRatio: 0,
}, },
want: 0, assertion: func(output uint64) {
// Need to allow for NaN depending on the machine architecture
require.True(t, output == uint64(0) || output == uint64(math.NaN()))
},
}, },
} }
...@@ -96,6 +114,6 @@ func TestInputThreshold(t *testing.T) { ...@@ -96,6 +114,6 @@ func TestInputThreshold(t *testing.T) {
ApproxComprRatio: tt.input.ApproxComprRatio, ApproxComprRatio: tt.input.ApproxComprRatio,
} }
got := config.InputThreshold() got := config.InputThreshold()
require.Equal(t, tt.want, got) tt.assertion(got)
} }
} }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment