...

Source file src/github.com/chaos-mesh/chaos-mesh/pkg/selector/generic/mode_test.go

Documentation: github.com/chaos-mesh/chaos-mesh/pkg/selector/generic

     1  // Copyright 2021 Chaos Mesh Authors.
     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  
    16  package generic
    17  
    18  import (
    19  	"testing"
    20  
    21  	. "github.com/onsi/gomega"
    22  )
    23  
    24  func TestRandomFixedIndexes(t *testing.T) {
    25  	g := NewGomegaWithT(t)
    26  
    27  	type TestCase struct {
    28  		name              string
    29  		start             uint
    30  		end               uint
    31  		count             uint
    32  		expectedOutputLen int
    33  	}
    34  
    35  	tcs := []TestCase{
    36  		{
    37  			name:              "start 0, end 10, count 3",
    38  			start:             0,
    39  			end:               10,
    40  			count:             3,
    41  			expectedOutputLen: 3,
    42  		},
    43  		{
    44  			name:              "start 0, end 10, count 12",
    45  			start:             0,
    46  			end:               10,
    47  			count:             12,
    48  			expectedOutputLen: 10,
    49  		},
    50  		{
    51  			name:              "start 5, end 10, count 3",
    52  			start:             5,
    53  			end:               10,
    54  			count:             3,
    55  			expectedOutputLen: 3,
    56  		},
    57  	}
    58  
    59  	for _, tc := range tcs {
    60  		values := RandomFixedIndexes(tc.start, tc.end, tc.count)
    61  		g.Expect(len(values)).To(Equal(tc.expectedOutputLen), tc.name)
    62  
    63  		for _, v := range values {
    64  			g.Expect(v).Should(BeNumerically(">=", tc.start), tc.name)
    65  			g.Expect(v).Should(BeNumerically("<", tc.end), tc.name)
    66  		}
    67  	}
    68  }
    69