github.com/go-maxhub/gremlins@v1.0.1-0.20231227222204-b03a6a1e3e09/core/mutator/mutator_test.go (about)

     1  /*
     2   * Copyright 2022 The Gremlins Authors
     3   *
     4   *    Licensed under the Apache License, Version 2.0 (the "License");
     5   *    you may not use this file except in compliance with the License.
     6   *    You may obtain a copy of the License at
     7   *
     8   *        http://www.apache.org/licenses/LICENSE-2.0
     9   *
    10   *    Unless required by applicable law or agreed to in writing, software
    11   *    distributed under the License is distributed on an "AS IS" BASIS,
    12   *    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    13   *    See the License for the specific language governing permissions and
    14   *    limitations under the License.
    15   */
    16  
    17  package mutator_test
    18  
    19  import (
    20  	"testing"
    21  
    22  	"github.com/google/go-cmp/cmp"
    23  
    24  	"github.com/go-maxhub/gremlins/core/mutator"
    25  )
    26  
    27  func TestStatusString(t *testing.T) {
    28  	testCases := []struct {
    29  		name           string
    30  		expected       string
    31  		mutationStatus mutator.Status
    32  	}{
    33  		{
    34  			name:           "NotCovered",
    35  			expected:       "NOT COVERED",
    36  			mutationStatus: mutator.NotCovered,
    37  		},
    38  		{
    39  			name:           "Runnable",
    40  			expected:       "RUNNABLE",
    41  			mutationStatus: mutator.Runnable,
    42  		},
    43  		{
    44  			name:           "Lived",
    45  			expected:       "LIVED",
    46  			mutationStatus: mutator.Lived,
    47  		},
    48  		{
    49  			name:           "Killed",
    50  			expected:       "KILLED",
    51  			mutationStatus: mutator.Killed,
    52  		},
    53  		{
    54  			name:           "NotViable",
    55  			expected:       "NOT VIABLE",
    56  			mutationStatus: mutator.NotViable,
    57  		},
    58  		{
    59  			name:           "TimedOut",
    60  			expected:       "TIMED OUT",
    61  			mutationStatus: mutator.TimedOut,
    62  		},
    63  	}
    64  	for _, tc := range testCases {
    65  		tc := tc
    66  		t.Run(tc.name, func(t *testing.T) {
    67  			if tc.mutationStatus.String() != tc.expected {
    68  				t.Errorf(cmp.Diff(tc.mutationStatus.String(), tc.expected))
    69  			}
    70  		})
    71  	}
    72  }
    73  
    74  func TestTypeString(t *testing.T) {
    75  	testCases := []struct {
    76  		name       string
    77  		expected   string
    78  		mutantType mutator.Type
    79  	}{
    80  		{
    81  			name:       "CONDITIONALS_BOUNDARY",
    82  			expected:   "CONDITIONALS_BOUNDARY",
    83  			mutantType: mutator.ConditionalsBoundary,
    84  		},
    85  		{
    86  			name:       "CONDITIONALS_NEGATION",
    87  			expected:   "CONDITIONALS_NEGATION",
    88  			mutantType: mutator.ConditionalsNegation,
    89  		},
    90  		{
    91  			name:       "INCREMENT_DECREMENT",
    92  			expected:   "INCREMENT_DECREMENT",
    93  			mutantType: mutator.IncrementDecrement,
    94  		},
    95  		{
    96  			name:       "INVERT_LOGICAL",
    97  			expected:   "INVERT_LOGICAL",
    98  			mutantType: mutator.InvertLogical,
    99  		},
   100  		{
   101  			name:       "INVERT_NEGATIVES",
   102  			expected:   "INVERT_NEGATIVES",
   103  			mutantType: mutator.InvertNegatives,
   104  		},
   105  		{
   106  			name:       "ARITHMETIC_BASE",
   107  			expected:   "ARITHMETIC_BASE",
   108  			mutantType: mutator.ArithmeticBase,
   109  		},
   110  		{
   111  			name:       "INVERT_LOOPCTRL",
   112  			expected:   "INVERT_LOOPCTRL",
   113  			mutantType: mutator.InvertLoopCtrl,
   114  		},
   115  		{
   116  			name:       "INVERT_ASSIGNMENTS",
   117  			expected:   "INVERT_ASSIGNMENTS",
   118  			mutantType: mutator.InvertAssignments,
   119  		},
   120  		{
   121  			name:       "INVERT_BITWISE",
   122  			expected:   "INVERT_BITWISE",
   123  			mutantType: mutator.InvertBitwise,
   124  		},
   125  		{
   126  			name:       "INVERT_BWASSIGN",
   127  			expected:   "INVERT_BWASSIGN",
   128  			mutantType: mutator.InvertBitwiseAssignments,
   129  		},
   130  		{
   131  			name:       "REMOVE_SELF_ASSIGNMENTS",
   132  			expected:   "REMOVE_SELF_ASSIGNMENTS",
   133  			mutantType: mutator.RemoveSelfAssignments,
   134  		},
   135  	}
   136  	for _, tc := range testCases {
   137  		tc := tc
   138  		t.Run(tc.name, func(t *testing.T) {
   139  			if tc.mutantType.String() != tc.expected {
   140  				t.Errorf(cmp.Diff(tc.mutantType.String(), tc.expected))
   141  			}
   142  		})
   143  	}
   144  }