go.charczuk.com@v0.0.0-20240327042549-bc490516bd1a/experiments/matchmaker/pkg/sim/simple_mm_test.go (about) 1 /* 2 3 Copyright (c) 2024 - Present. Will Charczuk. All rights reserved. 4 Use of this source code is governed by a MIT license that can be found in the LICENSE file at the root of the repository. 5 6 */ 7 8 package sim 9 10 import ( 11 "testing" 12 13 "go.charczuk.com/sdk/assert" 14 "go.charczuk.com/sdk/uuid" 15 ) 16 17 func Test_SimpleMatchmaker_skips_short(t *testing.T) { 18 smm := new(SimpleMatchmaker) 19 smm.Init(nil) 20 ret := smm.FormGames(MatchmakerConfig{TeamSize: 6, MaxGames: 3}) 21 assert.ItsEmpty(t, ret) 22 } 23 24 func Test_SimpleMatchmaker_QueueLen_unset(t *testing.T) { 25 smm := new(SimpleMatchmaker) 26 smm.Init(nil) 27 assert.ItsEqual(t, 0, smm.QueueLen()) 28 } 29 30 func Test_SimpleMatchmaker_skips_noGames(t *testing.T) { 31 smm := new(SimpleMatchmaker) 32 smm.Init(nil) 33 for x := 0; x < 100; x++ { 34 smm.Queue(&Player{ID: uuid.V4()}) 35 } 36 ret := smm.FormGames(MatchmakerConfig{TeamSize: 6, MaxGames: 0}) 37 assert.ItsEmpty(t, ret) 38 } 39 40 func Test_SimpleMatchmaker_makesGames(t *testing.T) { 41 smm := new(SimpleMatchmaker) 42 smm.Init(nil) 43 for x := 0; x < 100; x++ { 44 smm.Queue(&Player{ID: uuid.V4()}) 45 } 46 ret := smm.FormGames(MatchmakerConfig{TeamSize: 6, MaxGames: 3}) 47 assert.ItsLen(t, ret, 3) 48 49 assert.ItsAll(t, ret, func(g MatchmakerGame) bool { 50 return len(g.TeamA) == 6 && len(g.TeamB) == 6 51 }) 52 assert.ItsEqual(t, 100-36, smm.QueueLen()) 53 }