github.com/LanderTome/numerologyCalculator@v1.0.2/numerology/coreNumbers_test.go (about)

     1  // Copyright 2021 Robert D. Wukmir
     2  // This file is subject to the terms and conditions defined in
     3  // the LICENSE file, which is part of this source code package.
     4  //
     5  // Unless required by applicable law or agreed to in writing,
     6  // software distributed under the License is distributed on an
     7  // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
     8  // either express or implied. See the License for the specific
     9  // language governing permissions and limitations under the
    10  // License.
    11  package numerology
    12  
    13  import (
    14  	mapset "github.com/deckarep/golang-set"
    15  	"reflect"
    16  	"testing"
    17  )
    18  
    19  func Test_maskConstructor(t *testing.T) {
    20  	type args struct {
    21  		s string
    22  	}
    23  	tests := []struct {
    24  		name string
    25  		args args
    26  		want letterMask
    27  	}{
    28  		{"One letter Y", args{"Y"}, letterMask{true}},
    29  	}
    30  	for _, tt := range tests {
    31  		t.Run(tt.name, func(t *testing.T) {
    32  			if got := maskConstructor(tt.args.s); !reflect.DeepEqual(got.Vowels(), tt.want) {
    33  				t.Errorf("maskConstructor() = %v, want %v", got.Vowels(), tt.want)
    34  			}
    35  		})
    36  	}
    37  }
    38  
    39  func TestUnknownCharacters_MarshalJSON(t *testing.T) {
    40  	type fields struct {
    41  		Set mapset.Set
    42  	}
    43  	tests := []struct {
    44  		name    string
    45  		fields  fields
    46  		want    []byte
    47  		wantErr bool
    48  	}{
    49  		{"Marshal", fields{mapset.NewSetFromSlice([]interface{}{'-', '!'})},
    50  			[]byte(`["!"]`), false,
    51  		},
    52  	}
    53  	for _, tt := range tests {
    54  		t.Run(tt.name, func(t *testing.T) {
    55  			ec := unknownCharacters{
    56  				Set: tt.fields.Set,
    57  			}
    58  			got, err := ec.MarshalJSON()
    59  			if (err != nil) != tt.wantErr {
    60  				t.Errorf("MarshalJSON() error = %v, wantErr %v", err, tt.wantErr)
    61  				return
    62  			}
    63  			if !reflect.DeepEqual(got, tt.want) {
    64  				t.Errorf("MarshalJSON() got = %v, want %v", string(got), string(tt.want))
    65  			}
    66  		})
    67  	}
    68  }
    69  
    70  func Test_unknownCharacters_Unacceptable(t *testing.T) {
    71  	type fields struct {
    72  		Set mapset.Set
    73  	}
    74  	tests := []struct {
    75  		name         string
    76  		fields       fields
    77  		wantUnknowns unknownCharacters
    78  	}{
    79  		{"Unknown Characters", fields{mapset.NewSetWith(
    80  			interface{}(' '), interface{}('.'), interface{}('-'), interface{}('$'), interface{}('😜')),
    81  		}, unknownCharacters{mapset.NewSetWith(interface{}('$'), interface{}('😜'))}},
    82  	}
    83  	for _, tt := range tests {
    84  		t.Run(tt.name, func(t *testing.T) {
    85  			ec := unknownCharacters{
    86  				Set: tt.fields.Set,
    87  			}
    88  			if gotUnknowns := ec.Unacceptable(); !reflect.DeepEqual(gotUnknowns, tt.wantUnknowns) {
    89  				t.Errorf("Unacceptable() = %v, want %v", gotUnknowns, tt.wantUnknowns)
    90  			}
    91  		})
    92  	}
    93  }
    94  
    95  func Test_reduceNumbers(t *testing.T) {
    96  	type args struct {
    97  		n             int
    98  		masterNumbers []int
    99  		steps         []int
   100  	}
   101  	tests := []struct {
   102  		name            string
   103  		args            args
   104  		wantReduceSteps []int
   105  	}{
   106  		{"59338273", args{59338273, []int{11, 22, 33}, []int{}},
   107  			[]int{59338273, 40, 4},
   108  		},
   109  		{"337432", args{337432, []int{11, 22, 33}, []int{}},
   110  			[]int{337432, 22},
   111  		},
   112  	}
   113  	for _, tt := range tests {
   114  		t.Run(tt.name, func(t *testing.T) {
   115  			if gotReduceSteps := reduceNumbers(tt.args.n, tt.args.masterNumbers, tt.args.steps); !reflect.DeepEqual(gotReduceSteps, tt.wantReduceSteps) {
   116  				t.Errorf("reduceNumbers() = %v, want %v", gotReduceSteps, tt.wantReduceSteps)
   117  			}
   118  		})
   119  	}
   120  }