open-match.dev/open-match@v1.8.1/examples/functions/golang/soloduel/mmf/matchfunction_test.go (about)

     1  // Copyright 2019 Google LLC
     2  //
     3  // Licensed under the Apache License, Version 2.0 (the "License");
     4  // you may not use this file except in compliance with the License.
     5  // You may obtain a copy of the License at
     6  //
     7  //     http://www.apache.org/licenses/LICENSE-2.0
     8  //
     9  // Unless required by applicable law or agreed to in writing, software
    10  // distributed under the License is distributed on an "AS IS" BASIS,
    11  // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    12  // See the License for the specific language governing permissions and
    13  // limitations under the License.
    14  
    15  package mmf
    16  
    17  import (
    18  	"testing"
    19  
    20  	"open-match.dev/open-match/pkg/pb"
    21  
    22  	"github.com/stretchr/testify/require"
    23  )
    24  
    25  func TestMakeMatchesDeduplicate(t *testing.T) {
    26  	require := require.New(t)
    27  
    28  	poolNameToTickets := map[string][]*pb.Ticket{
    29  		"pool1": {{Id: "1"}},
    30  		"pool2": {{Id: "1"}},
    31  	}
    32  
    33  	matches, err := makeMatches(poolNameToTickets)
    34  	require.Nil(err)
    35  	require.Equal(len(matches), 0)
    36  }
    37  
    38  func TestMakeMatches(t *testing.T) {
    39  	require := require.New(t)
    40  
    41  	poolNameToTickets := map[string][]*pb.Ticket{
    42  		"pool1": {{Id: "1"}, {Id: "2"}, {Id: "3"}},
    43  		"pool2": {{Id: "4"}},
    44  		"pool3": {{Id: "5"}, {Id: "6"}, {Id: "7"}},
    45  	}
    46  
    47  	matches, err := makeMatches(poolNameToTickets)
    48  	require.Nil(err)
    49  	require.Equal(len(matches), 3)
    50  
    51  	for _, match := range matches {
    52  		require.Equal(2, len(match.Tickets))
    53  		require.Equal(matchName, match.MatchFunction)
    54  	}
    55  }