go.temporal.io/server@v1.23.0/common/predicates/universal_test.go (about)

     1  // The MIT License
     2  //
     3  // Copyright (c) 2020 Temporal Technologies Inc.  All rights reserved.
     4  //
     5  // Copyright (c) 2020 Uber Technologies, Inc.
     6  //
     7  // Permission is hereby granted, free of charge, to any person obtaining a copy
     8  // of this software and associated documentation files (the "Software"), to deal
     9  // in the Software without restriction, including without limitation the rights
    10  // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
    11  // copies of the Software, and to permit persons to whom the Software is
    12  // furnished to do so, subject to the following conditions:
    13  //
    14  // The above copyright notice and this permission notice shall be included in
    15  // all copies or substantial portions of the Software.
    16  //
    17  // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
    18  // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
    19  // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
    20  // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
    21  // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
    22  // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
    23  // THE SOFTWARE.
    24  
    25  package predicates
    26  
    27  import (
    28  	"math/rand"
    29  	"testing"
    30  
    31  	"github.com/stretchr/testify/require"
    32  	"github.com/stretchr/testify/suite"
    33  )
    34  
    35  type (
    36  	universalSuite struct {
    37  		suite.Suite
    38  		*require.Assertions
    39  
    40  		universal Predicate[int]
    41  	}
    42  )
    43  
    44  func TestUniversalSuite(t *testing.T) {
    45  	s := new(universalSuite)
    46  	suite.Run(t, s)
    47  }
    48  
    49  func (s *universalSuite) SetupTest() {
    50  	s.Assertions = require.New(s.T())
    51  
    52  	s.universal = Universal[int]()
    53  }
    54  
    55  func (s *universalSuite) TestUniversal_Test() {
    56  	for i := 0; i != 10; i++ {
    57  		s.True(s.universal.Test(rand.Int()))
    58  	}
    59  }
    60  
    61  func (s *universalSuite) TestUniversal_Equals() {
    62  	s.True(s.universal.Equals(s.universal))
    63  	s.True(s.universal.Equals(Universal[int]()))
    64  
    65  	s.False(s.universal.Equals(newTestPredicate(1, 2, 3)))
    66  	s.False(s.universal.Equals(And[int](
    67  		newTestPredicate(1, 2, 3),
    68  		newTestPredicate(2, 3, 4),
    69  	)))
    70  	s.False(s.universal.Equals(Or[int](
    71  		newTestPredicate(1, 2, 3),
    72  		newTestPredicate(4, 5, 6),
    73  	)))
    74  	s.False(s.universal.Equals(Not[int](newTestPredicate(1, 2, 3))))
    75  	s.False(s.universal.Equals(Empty[int]()))
    76  }