Commit 1316762f authored by refcell's avatar refcell Committed by GitHub

feat(op-dispute-mon): Move types into their own package (#9542)

parent aa3b147c
...@@ -5,6 +5,7 @@ import ( ...@@ -5,6 +5,7 @@ import (
"fmt" "fmt"
"github.com/ethereum-optimism/optimism/op-challenger/game/types" "github.com/ethereum-optimism/optimism/op-challenger/game/types"
monTypes "github.com/ethereum-optimism/optimism/op-dispute-mon/mon/types"
"github.com/ethereum/go-ethereum/common" "github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/log" "github.com/ethereum/go-ethereum/log"
...@@ -40,8 +41,8 @@ func newDetector(logger log.Logger, metrics DetectorMetrics, creator GameCallerC ...@@ -40,8 +41,8 @@ func newDetector(logger log.Logger, metrics DetectorMetrics, creator GameCallerC
} }
func (d *detector) Detect(ctx context.Context, games []types.GameMetadata) { func (d *detector) Detect(ctx context.Context, games []types.GameMetadata) {
statBatch := statusBatch{} statBatch := monTypes.StatusBatch{}
detectBatch := detectionBatch{} detectBatch := monTypes.DetectionBatch{}
for _, game := range games { for _, game := range games {
// Fetch the game metadata to ensure the game status is recorded // Fetch the game metadata to ensure the game status is recorded
// regardless of whether the game agreement is checked. // regardless of whether the game agreement is checked.
...@@ -58,17 +59,17 @@ func (d *detector) Detect(ctx context.Context, games []types.GameMetadata) { ...@@ -58,17 +59,17 @@ func (d *detector) Detect(ctx context.Context, games []types.GameMetadata) {
} }
detectBatch.Merge(processed) detectBatch.Merge(processed)
} }
d.metrics.RecordGamesStatus(statBatch.inProgress, statBatch.defenderWon, statBatch.challengerWon) d.metrics.RecordGamesStatus(statBatch.InProgress, statBatch.DefenderWon, statBatch.ChallengerWon)
d.recordBatch(detectBatch) d.recordBatch(detectBatch)
d.logger.Info("Completed updating games", "count", len(games)) d.logger.Info("Completed updating games", "count", len(games))
} }
func (d *detector) recordBatch(batch detectionBatch) { func (d *detector) recordBatch(batch monTypes.DetectionBatch) {
d.metrics.RecordGameAgreement("in_progress", batch.inProgress) d.metrics.RecordGameAgreement("in_progress", batch.InProgress)
d.metrics.RecordGameAgreement("agree_defender_wins", batch.agreeDefenderWins) d.metrics.RecordGameAgreement("agree_defender_wins", batch.AgreeDefenderWins)
d.metrics.RecordGameAgreement("disagree_defender_wins", batch.disagreeDefenderWins) d.metrics.RecordGameAgreement("disagree_defender_wins", batch.DisagreeDefenderWins)
d.metrics.RecordGameAgreement("agree_challenger_wins", batch.agreeChallengerWins) d.metrics.RecordGameAgreement("agree_challenger_wins", batch.AgreeChallengerWins)
d.metrics.RecordGameAgreement("disagree_challenger_wins", batch.disagreeChallengerWins) d.metrics.RecordGameAgreement("disagree_challenger_wins", batch.DisagreeChallengerWins)
} }
func (d *detector) fetchGameMetadata(ctx context.Context, game types.GameMetadata) (uint64, common.Hash, types.GameStatus, error) { func (d *detector) fetchGameMetadata(ctx context.Context, game types.GameMetadata) (uint64, common.Hash, types.GameStatus, error) {
...@@ -83,12 +84,12 @@ func (d *detector) fetchGameMetadata(ctx context.Context, game types.GameMetadat ...@@ -83,12 +84,12 @@ func (d *detector) fetchGameMetadata(ctx context.Context, game types.GameMetadat
return blockNum, rootClaim, status, nil return blockNum, rootClaim, status, nil
} }
func (d *detector) checkAgreement(ctx context.Context, addr common.Address, blockNum uint64, rootClaim common.Hash, status types.GameStatus) (detectionBatch, error) { func (d *detector) checkAgreement(ctx context.Context, addr common.Address, blockNum uint64, rootClaim common.Hash, status types.GameStatus) (monTypes.DetectionBatch, error) {
agree, expectedClaim, err := d.validator.CheckRootAgreement(ctx, blockNum, rootClaim) agree, expectedClaim, err := d.validator.CheckRootAgreement(ctx, blockNum, rootClaim)
if err != nil { if err != nil {
return detectionBatch{}, err return monTypes.DetectionBatch{}, err
} }
batch := detectionBatch{} batch := monTypes.DetectionBatch{}
batch.Update(status, agree) batch.Update(status, agree)
if status != types.GameStatusInProgress { if status != types.GameStatusInProgress {
expectedResult := types.GameStatusDefenderWon expectedResult := types.GameStatusDefenderWon
......
...@@ -7,6 +7,7 @@ import ( ...@@ -7,6 +7,7 @@ import (
faultTypes "github.com/ethereum-optimism/optimism/op-challenger/game/fault/types" faultTypes "github.com/ethereum-optimism/optimism/op-challenger/game/fault/types"
"github.com/ethereum-optimism/optimism/op-challenger/game/types" "github.com/ethereum-optimism/optimism/op-challenger/game/types"
monTypes "github.com/ethereum-optimism/optimism/op-dispute-mon/mon/types"
"github.com/ethereum-optimism/optimism/op-service/testlog" "github.com/ethereum-optimism/optimism/op-service/testlog"
"github.com/ethereum/go-ethereum/common" "github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/log" "github.com/ethereum/go-ethereum/log"
...@@ -67,45 +68,45 @@ func TestDetector_Detect(t *testing.T) { ...@@ -67,45 +68,45 @@ func TestDetector_Detect(t *testing.T) {
func TestDetector_RecordBatch(t *testing.T) { func TestDetector_RecordBatch(t *testing.T) {
tests := []struct { tests := []struct {
name string name string
batch detectionBatch batch monTypes.DetectionBatch
expect func(*testing.T, *mockDetectorMetricer) expect func(*testing.T, *mockDetectorMetricer)
}{ }{
{ {
name: "no games", name: "no games",
batch: detectionBatch{}, batch: monTypes.DetectionBatch{},
expect: func(t *testing.T, metrics *mockDetectorMetricer) {}, expect: func(t *testing.T, metrics *mockDetectorMetricer) {},
}, },
{ {
name: "in_progress", name: "in_progress",
batch: detectionBatch{inProgress: 1}, batch: monTypes.DetectionBatch{InProgress: 1},
expect: func(t *testing.T, metrics *mockDetectorMetricer) { expect: func(t *testing.T, metrics *mockDetectorMetricer) {
require.Equal(t, 1, metrics.gameAgreement["in_progress"]) require.Equal(t, 1, metrics.gameAgreement["in_progress"])
}, },
}, },
{ {
name: "agree_defender_wins", name: "agree_defender_wins",
batch: detectionBatch{agreeDefenderWins: 1}, batch: monTypes.DetectionBatch{AgreeDefenderWins: 1},
expect: func(t *testing.T, metrics *mockDetectorMetricer) { expect: func(t *testing.T, metrics *mockDetectorMetricer) {
require.Equal(t, 1, metrics.gameAgreement["agree_defender_wins"]) require.Equal(t, 1, metrics.gameAgreement["agree_defender_wins"])
}, },
}, },
{ {
name: "disagree_defender_wins", name: "disagree_defender_wins",
batch: detectionBatch{disagreeDefenderWins: 1}, batch: monTypes.DetectionBatch{DisagreeDefenderWins: 1},
expect: func(t *testing.T, metrics *mockDetectorMetricer) { expect: func(t *testing.T, metrics *mockDetectorMetricer) {
require.Equal(t, 1, metrics.gameAgreement["disagree_defender_wins"]) require.Equal(t, 1, metrics.gameAgreement["disagree_defender_wins"])
}, },
}, },
{ {
name: "agree_challenger_wins", name: "agree_challenger_wins",
batch: detectionBatch{agreeChallengerWins: 1}, batch: monTypes.DetectionBatch{AgreeChallengerWins: 1},
expect: func(t *testing.T, metrics *mockDetectorMetricer) { expect: func(t *testing.T, metrics *mockDetectorMetricer) {
require.Equal(t, 1, metrics.gameAgreement["agree_challenger_wins"]) require.Equal(t, 1, metrics.gameAgreement["agree_challenger_wins"])
}, },
}, },
{ {
name: "disagree_challenger_wins", name: "disagree_challenger_wins",
batch: detectionBatch{disagreeChallengerWins: 1}, batch: monTypes.DetectionBatch{DisagreeChallengerWins: 1},
expect: func(t *testing.T, metrics *mockDetectorMetricer) { expect: func(t *testing.T, metrics *mockDetectorMetricer) {
require.Equal(t, 1, metrics.gameAgreement["disagree_challenger_wins"]) require.Equal(t, 1, metrics.gameAgreement["disagree_challenger_wins"])
}, },
...@@ -163,15 +164,15 @@ func TestDetector_CheckAgreement_Succeeds(t *testing.T) { ...@@ -163,15 +164,15 @@ func TestDetector_CheckAgreement_Succeeds(t *testing.T) {
name string name string
rootClaim common.Hash rootClaim common.Hash
status types.GameStatus status types.GameStatus
expectBatch func(*detectionBatch) expectBatch func(*monTypes.DetectionBatch)
expectErrorLog bool expectErrorLog bool
expectStatus types.GameStatus expectStatus types.GameStatus
err error err error
}{ }{
{ {
name: "in_progress", name: "in_progress",
expectBatch: func(batch *detectionBatch) { expectBatch: func(batch *monTypes.DetectionBatch) {
require.Equal(t, 1, batch.inProgress) require.Equal(t, 1, batch.InProgress)
}, },
}, },
{ {
...@@ -179,16 +180,16 @@ func TestDetector_CheckAgreement_Succeeds(t *testing.T) { ...@@ -179,16 +180,16 @@ func TestDetector_CheckAgreement_Succeeds(t *testing.T) {
rootClaim: mockRootClaim, rootClaim: mockRootClaim,
status: types.GameStatusDefenderWon, status: types.GameStatusDefenderWon,
expectStatus: types.GameStatusDefenderWon, expectStatus: types.GameStatusDefenderWon,
expectBatch: func(batch *detectionBatch) { expectBatch: func(batch *monTypes.DetectionBatch) {
require.Equal(t, 1, batch.agreeDefenderWins) require.Equal(t, 1, batch.AgreeDefenderWins)
}, },
}, },
{ {
name: "disagree_defender_wins", name: "disagree_defender_wins",
status: types.GameStatusDefenderWon, status: types.GameStatusDefenderWon,
expectStatus: types.GameStatusChallengerWon, expectStatus: types.GameStatusChallengerWon,
expectBatch: func(batch *detectionBatch) { expectBatch: func(batch *monTypes.DetectionBatch) {
require.Equal(t, 1, batch.disagreeDefenderWins) require.Equal(t, 1, batch.DisagreeDefenderWins)
}, },
expectErrorLog: true, expectErrorLog: true,
}, },
...@@ -197,8 +198,8 @@ func TestDetector_CheckAgreement_Succeeds(t *testing.T) { ...@@ -197,8 +198,8 @@ func TestDetector_CheckAgreement_Succeeds(t *testing.T) {
rootClaim: mockRootClaim, rootClaim: mockRootClaim,
status: types.GameStatusChallengerWon, status: types.GameStatusChallengerWon,
expectStatus: types.GameStatusDefenderWon, expectStatus: types.GameStatusDefenderWon,
expectBatch: func(batch *detectionBatch) { expectBatch: func(batch *monTypes.DetectionBatch) {
require.Equal(t, 1, batch.agreeChallengerWins) require.Equal(t, 1, batch.AgreeChallengerWins)
}, },
expectErrorLog: true, expectErrorLog: true,
}, },
...@@ -206,8 +207,8 @@ func TestDetector_CheckAgreement_Succeeds(t *testing.T) { ...@@ -206,8 +207,8 @@ func TestDetector_CheckAgreement_Succeeds(t *testing.T) {
name: "disagree_challenger_wins", name: "disagree_challenger_wins",
status: types.GameStatusChallengerWon, status: types.GameStatusChallengerWon,
expectStatus: types.GameStatusChallengerWon, expectStatus: types.GameStatusChallengerWon,
expectBatch: func(batch *detectionBatch) { expectBatch: func(batch *monTypes.DetectionBatch) {
require.Equal(t, 1, batch.disagreeChallengerWins) require.Equal(t, 1, batch.DisagreeChallengerWins)
}, },
}, },
} }
......
...@@ -6,6 +6,7 @@ import ( ...@@ -6,6 +6,7 @@ import (
"fmt" "fmt"
"github.com/ethereum-optimism/optimism/op-challenger/game/types" "github.com/ethereum-optimism/optimism/op-challenger/game/types"
monTypes "github.com/ethereum-optimism/optimism/op-dispute-mon/mon/types"
"github.com/ethereum/go-ethereum/log" "github.com/ethereum/go-ethereum/log"
) )
...@@ -39,7 +40,7 @@ func newForecast(logger log.Logger, metrics ForecastMetrics, creator GameCallerC ...@@ -39,7 +40,7 @@ func newForecast(logger log.Logger, metrics ForecastMetrics, creator GameCallerC
} }
func (f *forecast) Forecast(ctx context.Context, games []types.GameMetadata) { func (f *forecast) Forecast(ctx context.Context, games []types.GameMetadata) {
batch := forecastBatch{} batch := monTypes.ForecastBatch{}
for _, game := range games { for _, game := range games {
if err := f.forecastGame(ctx, game, &batch); err != nil { if err := f.forecastGame(ctx, game, &batch); err != nil {
f.logger.Error("Failed to forecast game", "err", err) f.logger.Error("Failed to forecast game", "err", err)
...@@ -48,14 +49,14 @@ func (f *forecast) Forecast(ctx context.Context, games []types.GameMetadata) { ...@@ -48,14 +49,14 @@ func (f *forecast) Forecast(ctx context.Context, games []types.GameMetadata) {
f.recordBatch(batch) f.recordBatch(batch)
} }
func (f *forecast) recordBatch(batch forecastBatch) { func (f *forecast) recordBatch(batch monTypes.ForecastBatch) {
f.metrics.RecordGameAgreement("agree_challenger_ahead", batch.AgreeChallengerAhead) f.metrics.RecordGameAgreement("agree_challenger_ahead", batch.AgreeChallengerAhead)
f.metrics.RecordGameAgreement("disagree_challenger_ahead", batch.DisagreeChallengerAhead) f.metrics.RecordGameAgreement("disagree_challenger_ahead", batch.DisagreeChallengerAhead)
f.metrics.RecordGameAgreement("agree_defender_ahead", batch.AgreeDefenderAhead) f.metrics.RecordGameAgreement("agree_defender_ahead", batch.AgreeDefenderAhead)
f.metrics.RecordGameAgreement("disagree_defender_ahead", batch.DisagreeDefenderAhead) f.metrics.RecordGameAgreement("disagree_defender_ahead", batch.DisagreeDefenderAhead)
} }
func (f *forecast) forecastGame(ctx context.Context, game types.GameMetadata, metrics *forecastBatch) error { func (f *forecast) forecastGame(ctx context.Context, game types.GameMetadata, metrics *monTypes.ForecastBatch) error {
loader, err := f.creator.CreateContract(game) loader, err := f.creator.CreateContract(game)
if err != nil { if err != nil {
return fmt.Errorf("%w: %w", ErrContractCreation, err) return fmt.Errorf("%w: %w", ErrContractCreation, err)
......
package mon package types
import ( import (
"github.com/ethereum-optimism/optimism/op-challenger/game/types" "github.com/ethereum-optimism/optimism/op-challenger/game/types"
) )
type statusBatch struct { type StatusBatch struct {
inProgress, defenderWon, challengerWon int InProgress int
DefenderWon int
ChallengerWon int
} }
func (s *statusBatch) Add(status types.GameStatus) { func (s *StatusBatch) Add(status types.GameStatus) {
switch status { switch status {
case types.GameStatusInProgress: case types.GameStatusInProgress:
s.inProgress++ s.InProgress++
case types.GameStatusDefenderWon: case types.GameStatusDefenderWon:
s.defenderWon++ s.DefenderWon++
case types.GameStatusChallengerWon: case types.GameStatusChallengerWon:
s.challengerWon++ s.ChallengerWon++
} }
} }
type forecastBatch struct { type ForecastBatch struct {
AgreeDefenderAhead int AgreeDefenderAhead int
DisagreeDefenderAhead int DisagreeDefenderAhead int
AgreeChallengerAhead int AgreeChallengerAhead int
DisagreeChallengerAhead int DisagreeChallengerAhead int
} }
type detectionBatch struct { type DetectionBatch struct {
inProgress int InProgress int
agreeDefenderWins int AgreeDefenderWins int
disagreeDefenderWins int DisagreeDefenderWins int
agreeChallengerWins int AgreeChallengerWins int
disagreeChallengerWins int DisagreeChallengerWins int
} }
func (d *detectionBatch) Update(status types.GameStatus, agree bool) { func (d *DetectionBatch) Update(status types.GameStatus, agree bool) {
switch status { switch status {
case types.GameStatusInProgress: case types.GameStatusInProgress:
d.inProgress++ d.InProgress++
case types.GameStatusDefenderWon: case types.GameStatusDefenderWon:
if agree { if agree {
d.agreeDefenderWins++ d.AgreeDefenderWins++
} else { } else {
d.disagreeDefenderWins++ d.DisagreeDefenderWins++
} }
case types.GameStatusChallengerWon: case types.GameStatusChallengerWon:
if agree { if agree {
d.agreeChallengerWins++ d.AgreeChallengerWins++
} else { } else {
d.disagreeChallengerWins++ d.DisagreeChallengerWins++
} }
} }
} }
func (d *detectionBatch) Merge(other detectionBatch) { func (d *DetectionBatch) Merge(other DetectionBatch) {
d.inProgress += other.inProgress d.InProgress += other.InProgress
d.agreeDefenderWins += other.agreeDefenderWins d.AgreeDefenderWins += other.AgreeDefenderWins
d.disagreeDefenderWins += other.disagreeDefenderWins d.DisagreeDefenderWins += other.DisagreeDefenderWins
d.agreeChallengerWins += other.agreeChallengerWins d.AgreeChallengerWins += other.AgreeChallengerWins
d.disagreeChallengerWins += other.disagreeChallengerWins d.DisagreeChallengerWins += other.DisagreeChallengerWins
} }
package mon package types
import ( import (
"fmt" "fmt"
...@@ -11,24 +11,24 @@ import ( ...@@ -11,24 +11,24 @@ import (
func TestStatusBatch_Add(t *testing.T) { func TestStatusBatch_Add(t *testing.T) {
statusExpectations := []struct { statusExpectations := []struct {
status types.GameStatus status types.GameStatus
create func(int) statusBatch create func(int) StatusBatch
}{ }{
{ {
status: types.GameStatusInProgress, status: types.GameStatusInProgress,
create: func(inProgress int) statusBatch { create: func(inProgress int) StatusBatch {
return statusBatch{inProgress, 0, 0} return StatusBatch{inProgress, 0, 0}
}, },
}, },
{ {
status: types.GameStatusDefenderWon, status: types.GameStatusDefenderWon,
create: func(defenderWon int) statusBatch { create: func(defenderWon int) StatusBatch {
return statusBatch{0, defenderWon, 0} return StatusBatch{0, defenderWon, 0}
}, },
}, },
{ {
status: types.GameStatusChallengerWon, status: types.GameStatusChallengerWon,
create: func(challengerWon int) statusBatch { create: func(challengerWon int) StatusBatch {
return statusBatch{0, 0, challengerWon} return StatusBatch{0, 0, challengerWon}
}, },
}, },
} }
...@@ -37,7 +37,7 @@ func TestStatusBatch_Add(t *testing.T) { ...@@ -37,7 +37,7 @@ func TestStatusBatch_Add(t *testing.T) {
name string name string
status types.GameStatus status types.GameStatus
invocations int invocations int
expected statusBatch expected StatusBatch
} }
var tests []test var tests []test
...@@ -55,7 +55,7 @@ func TestStatusBatch_Add(t *testing.T) { ...@@ -55,7 +55,7 @@ func TestStatusBatch_Add(t *testing.T) {
for _, test := range tests { for _, test := range tests {
test := test test := test
t.Run(test.name, func(t *testing.T) { t.Run(test.name, func(t *testing.T) {
s := statusBatch{} s := StatusBatch{}
for i := 0; i < test.invocations; i++ { for i := 0; i < test.invocations; i++ {
s.Add(test.status) s.Add(test.status)
} }
...@@ -67,30 +67,30 @@ func TestStatusBatch_Add(t *testing.T) { ...@@ -67,30 +67,30 @@ func TestStatusBatch_Add(t *testing.T) {
func TestDetectionBatch_Update(t *testing.T) { func TestDetectionBatch_Update(t *testing.T) {
statusExpectations := []struct { statusExpectations := []struct {
status types.GameStatus status types.GameStatus
create func(int, bool) detectionBatch create func(int, bool) DetectionBatch
}{ }{
{ {
status: types.GameStatusInProgress, status: types.GameStatusInProgress,
create: func(inProgress int, _ bool) detectionBatch { create: func(inProgress int, _ bool) DetectionBatch {
return detectionBatch{inProgress, 0, 0, 0, 0} return DetectionBatch{inProgress, 0, 0, 0, 0}
}, },
}, },
{ {
status: types.GameStatusDefenderWon, status: types.GameStatusDefenderWon,
create: func(defenderWon int, agree bool) detectionBatch { create: func(defenderWon int, agree bool) DetectionBatch {
if agree { if agree {
return detectionBatch{0, defenderWon, 0, 0, 0} return DetectionBatch{0, defenderWon, 0, 0, 0}
} }
return detectionBatch{0, 0, defenderWon, 0, 0} return DetectionBatch{0, 0, defenderWon, 0, 0}
}, },
}, },
{ {
status: types.GameStatusChallengerWon, status: types.GameStatusChallengerWon,
create: func(challengerWon int, agree bool) detectionBatch { create: func(challengerWon int, agree bool) DetectionBatch {
if agree { if agree {
return detectionBatch{0, 0, 0, challengerWon, 0} return DetectionBatch{0, 0, 0, challengerWon, 0}
} }
return detectionBatch{0, 0, 0, 0, challengerWon} return DetectionBatch{0, 0, 0, 0, challengerWon}
}, },
}, },
} }
...@@ -100,7 +100,7 @@ func TestDetectionBatch_Update(t *testing.T) { ...@@ -100,7 +100,7 @@ func TestDetectionBatch_Update(t *testing.T) {
status types.GameStatus status types.GameStatus
agree bool agree bool
invocations int invocations int
expected detectionBatch expected DetectionBatch
} }
var tests []test var tests []test
...@@ -120,7 +120,7 @@ func TestDetectionBatch_Update(t *testing.T) { ...@@ -120,7 +120,7 @@ func TestDetectionBatch_Update(t *testing.T) {
for _, test := range tests { for _, test := range tests {
test := test test := test
t.Run(test.name, func(t *testing.T) { t.Run(test.name, func(t *testing.T) {
d := detectionBatch{} d := DetectionBatch{}
for i := 0; i < test.invocations; i++ { for i := 0; i < test.invocations; i++ {
d.Update(test.status, test.agree) d.Update(test.status, test.agree)
} }
...@@ -132,52 +132,52 @@ func TestDetectionBatch_Update(t *testing.T) { ...@@ -132,52 +132,52 @@ func TestDetectionBatch_Update(t *testing.T) {
func TestDetectionBatch_Merge(t *testing.T) { func TestDetectionBatch_Merge(t *testing.T) {
type test struct { type test struct {
name string name string
merge detectionBatch merge DetectionBatch
expected detectionBatch expected DetectionBatch
} }
tests := []test{ tests := []test{
{ {
name: "Empty", name: "Empty",
merge: detectionBatch{}, merge: DetectionBatch{},
expected: detectionBatch{}, expected: DetectionBatch{},
}, },
{ {
name: "InProgress", name: "InProgress",
merge: detectionBatch{1, 0, 0, 0, 0}, merge: DetectionBatch{1, 0, 0, 0, 0},
expected: detectionBatch{1, 0, 0, 0, 0}, expected: DetectionBatch{1, 0, 0, 0, 0},
}, },
{ {
name: "AgreeDefenderWins", name: "AgreeDefenderWins",
merge: detectionBatch{0, 1, 0, 0, 0}, merge: DetectionBatch{0, 1, 0, 0, 0},
expected: detectionBatch{0, 1, 0, 0, 0}, expected: DetectionBatch{0, 1, 0, 0, 0},
}, },
{ {
name: "DisagreeDefenderWins", name: "DisagreeDefenderWins",
merge: detectionBatch{0, 0, 1, 0, 0}, merge: DetectionBatch{0, 0, 1, 0, 0},
expected: detectionBatch{0, 0, 1, 0, 0}, expected: DetectionBatch{0, 0, 1, 0, 0},
}, },
{ {
name: "AgreeChallengerWins", name: "AgreeChallengerWins",
merge: detectionBatch{0, 0, 0, 1, 0}, merge: DetectionBatch{0, 0, 0, 1, 0},
expected: detectionBatch{0, 0, 0, 1, 0}, expected: DetectionBatch{0, 0, 0, 1, 0},
}, },
{ {
name: "DisagreeChallengerWins", name: "DisagreeChallengerWins",
merge: detectionBatch{0, 0, 0, 0, 1}, merge: DetectionBatch{0, 0, 0, 0, 1},
expected: detectionBatch{0, 0, 0, 0, 1}, expected: DetectionBatch{0, 0, 0, 0, 1},
}, },
{ {
name: "All", name: "All",
merge: detectionBatch{1, 1, 1, 1, 1}, merge: DetectionBatch{1, 1, 1, 1, 1},
expected: detectionBatch{1, 1, 1, 1, 1}, expected: DetectionBatch{1, 1, 1, 1, 1},
}, },
} }
for _, test := range tests { for _, test := range tests {
test := test test := test
t.Run(test.name, func(t *testing.T) { t.Run(test.name, func(t *testing.T) {
d := detectionBatch{} d := DetectionBatch{}
d.Merge(test.merge) d.Merge(test.merge)
require.Equal(t, test.expected, d) require.Equal(t, test.expected, d)
}) })
......
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