github.com/LanderTome/numerologyCalculator@v1.0.2/numerology/nameSearch_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  	"testing"
    16  )
    17  
    18  func Test_nameSearchRandomCheck(t *testing.T) {
    19  	first, offset, _ := nameSearch("Random ? Test", Pythagorean, []int{11, 22, 33}, true, NameSearchOpts{
    20  		Count:      5,
    21  		Offset:     0,
    22  		Seed:       3384983,
    23  		Dictionary: "usa_census",
    24  		Gender:     Gender('M'),
    25  		Sort:       "random",
    26  		Database:   "sqlite://file::memory:?cache=shared",
    27  	})
    28  	second, _, _ := nameSearch("Random ? Test", Pythagorean, []int{11, 22, 33}, true, NameSearchOpts{
    29  		Count:      5,
    30  		Offset:     int(offset - 1),
    31  		Seed:       3384983,
    32  		Dictionary: "usa_census",
    33  		Gender:     Gender('M'),
    34  		Sort:       "random",
    35  		Database:   "sqlite://file::memory:?cache=shared",
    36  	})
    37  	if first[4].Name != second[0].Name {
    38  		t.Error("Random offset in name search is producing bad results.")
    39  	}
    40  }
    41  
    42  func Test_nameSearchOffsetCheck(t *testing.T) {
    43  	names, offset, _ := nameSearch("Ath? Doe", Pythagorean, []int{11, 22, 33}, true, NameSearchOpts{
    44  		Count:      50,
    45  		Offset:     0,
    46  		Seed:       3384983,
    47  		Dictionary: "usa_census",
    48  		Gender:     Gender('F'),
    49  		Sort:       "random",
    50  		Database:   "sqlite://file::memory:?cache=shared",
    51  	})
    52  	if len(names) > 0 && offset > 0 {
    53  		t.Error("Offset error.")
    54  	}
    55  }
    56  
    57  func Test_nameSearchDupCheck(t *testing.T) {
    58  	names, _, _ := nameSearch("John ? Doe", Pythagorean, []int{11, 22, 33, 44, 55, 66, 77, 88, 99}, true, NameSearchOpts{
    59  		Count:      50000,
    60  		Offset:     0,
    61  		Seed:       3384983,
    62  		Full:       []int{6},
    63  		Dictionary: "usa_census",
    64  		Gender:     Gender('M'),
    65  		Sort:       "common",
    66  		Database:   "sqlite://file::memory:?cache=shared",
    67  	})
    68  	for i := range names {
    69  		_ = names[i].Full()
    70  		for j := range names {
    71  			if i != j && names[i] == names[j] {
    72  				t.Error("Duplicate name found when there shouldn't be any.")
    73  			}
    74  		}
    75  	}
    76  	DB = nil
    77  }
    78  
    79  func Test_KarmicDebtSearch(t *testing.T) {
    80  	type args struct {
    81  		n             string
    82  		numberSystem  NumberSystem
    83  		masterNumbers []int
    84  		reduceWords   bool
    85  		opts          NameSearchOpts
    86  	}
    87  	tests := []struct {
    88  		name        string
    89  		args        args
    90  		wantResults []NameNumerology
    91  		wantOffset  int64
    92  		wantErr     bool
    93  	}{
    94  		{"KarmicDebtSearch", args{"John ? Doe", Pythagorean, []int{11, 22, 33}, true, NameSearchOpts{
    95  			Count:          200,
    96  			Offset:         0,
    97  			Seed:           0,
    98  			Dictionary:     "usa_census",
    99  			Gender:         Gender('M'),
   100  			Sort:           "common",
   101  			Full:           []int{-13, -14, -16, -19},
   102  			Vowels:         []int{-13, -14, -16, -19},
   103  			Consonants:     []int{-13, -14, -16, -19},
   104  			HiddenPassions: nil,
   105  			KarmicLessons:  nil,
   106  			Database:       "sqlite://file::memory:?cache=shared",
   107  		}}, []NameNumerology{}, 0, false},
   108  	}
   109  	for _, tt := range tests {
   110  		t.Run(tt.name, func(t *testing.T) {
   111  			gotResults, _, _ := nameSearch(tt.args.n, tt.args.numberSystem, tt.args.masterNumbers, tt.args.reduceWords, tt.args.opts)
   112  			set := mapset.NewSet()
   113  			for _, result := range gotResults {
   114  				for _, i := range append(append(result.Full().ReduceSteps, result.Vowels().ReduceSteps...), result.Consonants().ReduceSteps...) {
   115  					set.Add(i)
   116  				}
   117  			}
   118  			for _, kd := range []int{13, 14, 16, 19} {
   119  				for _, value := range set.ToSlice() {
   120  					if value.(int) == kd {
   121  						t.Errorf("nameSearch() gotResults = %v, did not want %v", value, kd)
   122  					}
   123  				}
   124  			}
   125  		})
   126  	}
   127  	DB = nil
   128  }
   129  
   130  func Test_nameSearch(t *testing.T) {
   131  	baseSearch := NameSearchOpts{
   132  		Count:          500,
   133  		Offset:         0,
   134  		Seed:           0,
   135  		Dictionary:     "usa_census",
   136  		Gender:         Gender('B'),
   137  		Sort:           "random",
   138  		Full:           nil,
   139  		Vowels:         nil,
   140  		Consonants:     nil,
   141  		HiddenPassions: nil,
   142  		KarmicLessons:  nil,
   143  		Database:       "sqlite://file::memory:?cache=shared",
   144  	}
   145  	tests := [][]int{
   146  		{1, 4},
   147  		{2, 7, 9},
   148  		{3, -1, 2},
   149  		{11, 8, -9},
   150  		{3, -13, -14, 6},
   151  		{22},
   152  		{3, 8, 9},
   153  	}
   154  	// Full test
   155  	for _, test := range tests {
   156  		search := NameSearchOpts{
   157  			Count:      baseSearch.Count,
   158  			Offset:     baseSearch.Offset,
   159  			Seed:       0,
   160  			Dictionary: baseSearch.Dictionary,
   161  			Gender:     baseSearch.Gender,
   162  			Sort:       baseSearch.Sort,
   163  			Full:       test,
   164  			Database:   baseSearch.Database,
   165  		}
   166  		results, _, _ := Name("?", Pythagorean, []int{11, 22, 33}, true).Search(search)
   167  		if len(results) == 0 {
   168  			t.Errorf("No results when results expected. %v", search)
   169  		}
   170  		for _, r := range results {
   171  			var ok bool
   172  			for _, n := range r.Full().ReduceSteps {
   173  				if inIntSlice(n, test) {
   174  					ok = true
   175  					break
   176  				}
   177  				if inIntSlice(-n, test) {
   178  					ok = false
   179  					break
   180  				}
   181  			}
   182  			if !ok {
   183  				t.Errorf("Unexpected result. reduced: %v | test: %v", r.Full().ReduceSteps, test)
   184  			}
   185  		}
   186  	}
   187  	// Vowels test
   188  	for _, test := range tests {
   189  		search := NameSearchOpts{
   190  			Count:      baseSearch.Count,
   191  			Offset:     baseSearch.Offset,
   192  			Seed:       1,
   193  			Dictionary: baseSearch.Dictionary,
   194  			Gender:     baseSearch.Gender,
   195  			Sort:       baseSearch.Sort,
   196  			Vowels:     test,
   197  			Database:   baseSearch.Database,
   198  		}
   199  		results, _, _ := Name("?", Pythagorean, []int{11, 22, 33}, true).Search(search)
   200  		if len(results) == 0 {
   201  			t.Errorf("No results when results expected. %v", search)
   202  		}
   203  		for _, r := range results {
   204  			var ok bool
   205  			for _, n := range r.Vowels().ReduceSteps {
   206  				if inIntSlice(n, test) {
   207  					ok = true
   208  					break
   209  				}
   210  				if inIntSlice(-n, test) {
   211  					ok = false
   212  					break
   213  				}
   214  			}
   215  			if !ok {
   216  				t.Errorf("Unexpected result. reduced: %v | test: %v", r.Vowels().ReduceSteps, test)
   217  			}
   218  		}
   219  	}
   220  	// Consonants test
   221  	for _, test := range tests {
   222  		search := NameSearchOpts{
   223  			Count:      baseSearch.Count,
   224  			Offset:     baseSearch.Offset,
   225  			Seed:       2,
   226  			Dictionary: baseSearch.Dictionary,
   227  			Gender:     baseSearch.Gender,
   228  			Sort:       baseSearch.Sort,
   229  			Consonants: test,
   230  			Database:   baseSearch.Database,
   231  		}
   232  		results, _, _ := Name("?", Pythagorean, []int{11, 22, 33}, true).Search(search)
   233  		if len(results) == 0 {
   234  			t.Errorf("No results when results expected. %v", search)
   235  		}
   236  		for _, r := range results {
   237  			var ok bool
   238  			for _, n := range r.Consonants().ReduceSteps {
   239  				if inIntSlice(n, test) {
   240  					ok = true
   241  					break
   242  				}
   243  				if inIntSlice(-n, test) {
   244  					ok = false
   245  					break
   246  				}
   247  			}
   248  			if !ok {
   249  				t.Errorf("Unexpected result. reduced: %v | test: %v", r.Consonants().ReduceSteps, test)
   250  			}
   251  		}
   252  	}
   253  	DB = nil
   254  }