github.com/LanderTome/numerologyCalculator@v1.0.2/numerology/calculateNames_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  	"fmt"
    15  	"github.com/olekukonko/tablewriter"
    16  	"log"
    17  	"os"
    18  	"path/filepath"
    19  	"reflect"
    20  	"runtime"
    21  	"testing"
    22  )
    23  
    24  func init() {
    25  	// Change working directory because testing messes it up.
    26  	_, b, _, _ := runtime.Caller(0)
    27  	if err := os.Chdir(filepath.Join(filepath.Dir(b), "..")); err != nil {
    28  		panic(err)
    29  	}
    30  }
    31  
    32  func TestName(t *testing.T) {
    33  	type args struct {
    34  		name          string
    35  		numberSystem  NumberSystem
    36  		masterNumbers []int
    37  		reduceWords   bool
    38  	}
    39  	tests := []struct {
    40  		name       string
    41  		args       args
    42  		wantResult NameNumerology
    43  	}{
    44  		{"Arthur Von Black", args{"Arthur Von Black", Pythagorean, []int{11, 22, 33}, true},
    45  			NameNumerology{
    46  				Name: "Arthur Von Black",
    47  				NameOpts: &NameOpts{
    48  					NumberSystem:  Pythagorean,
    49  					MasterNumbers: []int{11, 22, 33},
    50  					ReduceWords:   true,
    51  				},
    52  				NameSearchOpts: nil,
    53  				mask:           nil,
    54  				counts:         nil,
    55  				unknowns:       nil,
    56  			},
    57  		}}
    58  	for _, tt := range tests {
    59  		t.Run(tt.name, func(t *testing.T) {
    60  			if gotResult := Name(tt.args.name, tt.args.numberSystem, tt.args.masterNumbers, tt.args.reduceWords); !reflect.DeepEqual(gotResult, tt.wantResult) {
    61  				t.Errorf("Name() = %v, want %v", gotResult, tt.wantResult)
    62  			}
    63  		})
    64  	}
    65  }
    66  
    67  func TestNames(t *testing.T) {
    68  	type args struct {
    69  		names         []string
    70  		numberSystem  NumberSystem
    71  		masterNumbers []int
    72  		reduceWords   bool
    73  	}
    74  	tests := []struct {
    75  		name        string
    76  		args        args
    77  		wantResults []NameNumerology
    78  	}{
    79  		{"Name 1, Name 2, Name 3", args{[]string{"Name 1", "Name 2", "Name 3"}, Pythagorean, []int{11, 22, 33}, true},
    80  			[]NameNumerology{
    81  				{
    82  					Name: "Name 1",
    83  					NameOpts: &NameOpts{
    84  						NumberSystem:  Pythagorean,
    85  						MasterNumbers: []int{11, 22, 33},
    86  						ReduceWords:   true,
    87  					},
    88  					NameSearchOpts: nil,
    89  					mask:           nil,
    90  					counts:         nil,
    91  					unknowns:       nil,
    92  				},
    93  				{
    94  					Name: "Name 2",
    95  					NameOpts: &NameOpts{
    96  						NumberSystem:  Pythagorean,
    97  						MasterNumbers: []int{11, 22, 33},
    98  						ReduceWords:   true,
    99  					},
   100  					NameSearchOpts: nil,
   101  					mask:           nil,
   102  					counts:         nil,
   103  					unknowns:       nil,
   104  				},
   105  				{
   106  					Name: "Name 3",
   107  					NameOpts: &NameOpts{
   108  						NumberSystem:  Pythagorean,
   109  						MasterNumbers: []int{11, 22, 33},
   110  						ReduceWords:   true,
   111  					},
   112  					NameSearchOpts: nil,
   113  					mask:           nil,
   114  					counts:         nil,
   115  					unknowns:       nil,
   116  				},
   117  			},
   118  		},
   119  	}
   120  	for _, tt := range tests {
   121  		t.Run(tt.name, func(t *testing.T) {
   122  			if gotResults := Names(tt.args.names, tt.args.numberSystem, tt.args.masterNumbers, tt.args.reduceWords); !reflect.DeepEqual(gotResults, tt.wantResults) {
   123  				t.Errorf("Names() = %v, want %v", gotResults, tt.wantResults)
   124  			}
   125  		})
   126  	}
   127  }
   128  
   129  func ExampleNameNumerology_Full() {
   130  	result := Name("Kevin Norwood Bacon", Pythagorean, []int{11, 22, 33}, true)
   131  	fmt.Print(result.Full().Debug())
   132  	// Output:
   133  	// K e v i n
   134  	// 2 5 4 9 5 = 25 = 7
   135  	// N o r w o o d
   136  	// 5 6 9 5 6 6 4 = 41 = 5
   137  	// B a c o n
   138  	// 2 1 3 6 5 = 17 = 8
   139  	// Reduce: 20 = 2
   140  }
   141  
   142  func ExampleNameNumerology_Destiny() {
   143  	result := Name("Kevin Norwood Bacon", Pythagorean, []int{11, 22, 33}, true)
   144  	fmt.Print(result.Destiny().Debug())
   145  	// Output:
   146  	// K e v i n
   147  	// 2 5 4 9 5 = 25 = 7
   148  	// N o r w o o d
   149  	// 5 6 9 5 6 6 4 = 41 = 5
   150  	// B a c o n
   151  	// 2 1 3 6 5 = 17 = 8
   152  	// Reduce: 20 = 2
   153  }
   154  
   155  func ExampleNameNumerology_Expression() {
   156  	result := Name("Kevin Norwood Bacon", Pythagorean, []int{11, 22, 33}, true)
   157  	fmt.Print(result.Expression().Debug())
   158  	// Output:
   159  	// K e v i n
   160  	// 2 5 4 9 5 = 25 = 7
   161  	// N o r w o o d
   162  	// 5 6 9 5 6 6 4 = 41 = 5
   163  	// B a c o n
   164  	// 2 1 3 6 5 = 17 = 8
   165  	// Reduce: 20 = 2
   166  }
   167  
   168  func ExampleNameNumerology_Vowels() {
   169  	result := Name("Kevin Norwood Bacon", Pythagorean, []int{11, 22, 33}, true)
   170  	fmt.Print(result.Vowels().Debug())
   171  	// Output:
   172  	// K e v i n
   173  	// · 5 · 9 · = 14 = 5
   174  	// N o r w o o d
   175  	// · 6 · · 6 6 · = 18 = 9
   176  	// B a c o n
   177  	// · 1 · 6 · = 7
   178  	// Reduce: 21 = 3
   179  }
   180  
   181  func ExampleNameNumerology_SoulsUrge() {
   182  	result := Name("Kevin Norwood Bacon", Pythagorean, []int{11, 22, 33}, true)
   183  	fmt.Print(result.SoulsUrge().Debug())
   184  	// Output:
   185  	// K e v i n
   186  	// · 5 · 9 · = 14 = 5
   187  	// N o r w o o d
   188  	// · 6 · · 6 6 · = 18 = 9
   189  	// B a c o n
   190  	// · 1 · 6 · = 7
   191  	// Reduce: 21 = 3
   192  }
   193  
   194  func ExampleNameNumerology_HeartsDesire() {
   195  	result := Name("Kevin Norwood Bacon", Pythagorean, []int{11, 22, 33}, true)
   196  	fmt.Print(result.HeartsDesire().Debug())
   197  	// Output:
   198  	// K e v i n
   199  	// · 5 · 9 · = 14 = 5
   200  	// N o r w o o d
   201  	// · 6 · · 6 6 · = 18 = 9
   202  	// B a c o n
   203  	// · 1 · 6 · = 7
   204  	// Reduce: 21 = 3
   205  }
   206  
   207  func ExampleNameNumerology_Consonants() {
   208  	result := Name("Kevin Norwood Bacon", Pythagorean, []int{11, 22, 33}, true)
   209  	fmt.Print(result.Consonants().Debug())
   210  	// Output:
   211  	// K e v i n
   212  	// 2 · 4 · 5 = 11
   213  	// N o r w o o d
   214  	// 5 · 9 5 · · 4 = 23 = 5
   215  	// B a c o n
   216  	// 2 · 3 · 5 = 10 = 1
   217  	// Reduce: 17 = 8
   218  }
   219  
   220  func ExampleNameNumerology_Personality() {
   221  	result := Name("Kevin Norwood Bacon", Pythagorean, []int{11, 22, 33}, true)
   222  	fmt.Print(result.Personality().Debug())
   223  	// Output:
   224  	// K e v i n
   225  	// 2 · 4 · 5 = 11
   226  	// N o r w o o d
   227  	// 5 · 9 5 · · 4 = 23 = 5
   228  	// B a c o n
   229  	// 2 · 3 · 5 = 10 = 1
   230  	// Reduce: 17 = 8
   231  }
   232  
   233  func ExampleNameNumerology_HiddenPassions() {
   234  	result := Name("Kevin Norwood Bacon", Pythagorean, []int{11, 22, 33}, false)
   235  	fmt.Printf("%v (%v)", result.Name, result.HiddenPassions().Numbers)
   236  	// Output: Kevin Norwood Bacon ([5])
   237  }
   238  
   239  func ExampleNameNumerology_KarmicLessons() {
   240  	result := Name("Kevin Norwood Bacon", Pythagorean, []int{11, 22, 33}, false)
   241  	fmt.Printf("%v (%v)", result.Name, result.KarmicLessons().Numbers)
   242  	// Output: Kevin Norwood Bacon ([7 8])
   243  }
   244  
   245  func ExampleNameNumerology_Search() {
   246  	opts := NameSearchOpts{
   247  		Count:      10,
   248  		Dictionary: "usa_census",
   249  		Gender:     'M',
   250  		Sort:       "common",
   251  		Full:       []int{3, 5, 8},
   252  		Database:   "sqlite://file::memory:?cache=shared",
   253  	}
   254  	results, _, err := Name("Abraham ? Lincoln", Chaldean, []int{11, 22, 33}, true).Search(opts)
   255  	if err != nil {
   256  		log.Fatal(err)
   257  	}
   258  	table := tablewriter.NewWriter(os.Stdout)
   259  	table.SetHeader([]string{"", "Name", "#"})
   260  	for i, result := range results {
   261  		table.Append([]string{fmt.Sprintf("%v", i+1), result.Name, fmt.Sprintf("%v", result.Full().Value)})
   262  	}
   263  	table.Render()
   264  	// Output:
   265  	// +----+-------------------------+---+
   266  	// |    |          NAME           | # |
   267  	// +----+-------------------------+---+
   268  	// |  1 | Abraham James Lincoln   | 3 |
   269  	// |  2 | Abraham David Lincoln   | 5 |
   270  	// |  3 | Abraham William Lincoln | 8 |
   271  	// |  4 | Abraham Daniel Lincoln  | 8 |
   272  	// |  5 | Abraham Joshua Lincoln  | 3 |
   273  	// |  6 | Abraham Anthony Lincoln | 8 |
   274  	// |  7 | Abraham Andrew Lincoln  | 3 |
   275  	// |  8 | Abraham Kevin Lincoln   | 8 |
   276  	// |  9 | Abraham Steven Lincoln  | 8 |
   277  	// | 10 | Abraham Jacob Lincoln   | 3 |
   278  	// +----+-------------------------+---+
   279  }
   280  
   281  func TestNameNumerology_Search(t *testing.T) {
   282  	type fields struct {
   283  		Name           string
   284  		NameOpts       *NameOpts
   285  		NameSearchOpts *NameSearchOpts
   286  		mask           *maskStruct
   287  	}
   288  	type args struct {
   289  		opts NameSearchOpts
   290  	}
   291  	tests := []struct {
   292  		name        string
   293  		fields      fields
   294  		args        args
   295  		wantResults int
   296  		wantOffset  int64
   297  		wantErr     bool
   298  	}{
   299  		{"John ? Doe", fields{
   300  			Name: "John ? Doe",
   301  			NameOpts: &NameOpts{
   302  				NumberSystem:  Pythagorean,
   303  				MasterNumbers: []int{11},
   304  				ReduceWords:   false,
   305  			},
   306  		}, args{NameSearchOpts{
   307  			Count:          0,
   308  			Offset:         5001,
   309  			Seed:           0,
   310  			Dictionary:     "usa_census",
   311  			Gender:         'M',
   312  			Sort:           "uncommon",
   313  			Full:           []int{4},
   314  			Vowels:         nil,
   315  			Consonants:     nil,
   316  			HiddenPassions: []int{7, -3},
   317  			KarmicLessons:  []int{-6},
   318  			Database:       "sqlite://file::memory:?cache=shared",
   319  		}}, 3, 0, false},
   320  		{"HiddenPassionsSearch", fields{
   321  			Name: "John ? Doe",
   322  			NameOpts: &NameOpts{
   323  				NumberSystem:  Pythagorean,
   324  				MasterNumbers: []int{11},
   325  				ReduceWords:   false,
   326  			},
   327  		}, args{NameSearchOpts{
   328  			Count:          25,
   329  			Offset:         0,
   330  			Seed:           0,
   331  			Dictionary:     "usa_census",
   332  			Gender:         'M',
   333  			Sort:           "random",
   334  			Full:           nil,
   335  			Vowels:         nil,
   336  			Consonants:     nil,
   337  			HiddenPassions: []int{-3},
   338  			KarmicLessons:  []int{},
   339  			Database:       "sqlite://file::memory:?cache=shared",
   340  		}}, 25, 25, false},
   341  		{"MultipleHiddenPassionsSearch", fields{
   342  			Name: "John ? Doe",
   343  			NameOpts: &NameOpts{
   344  				NumberSystem:  Pythagorean,
   345  				MasterNumbers: []int{11},
   346  				ReduceWords:   false,
   347  			},
   348  		}, args{NameSearchOpts{
   349  			Count:          25,
   350  			Offset:         0,
   351  			Seed:           0,
   352  			Dictionary:     "usa_census",
   353  			Gender:         'M',
   354  			Sort:           "random",
   355  			Full:           nil,
   356  			Vowels:         nil,
   357  			Consonants:     nil,
   358  			HiddenPassions: []int{1, 3},
   359  			KarmicLessons:  []int{},
   360  			Database:       "sqlite://file::memory:?cache=shared",
   361  		}}, 25, 25, false},
   362  		{"KarmicLessonsSearch", fields{
   363  			Name: "John M? Doe",
   364  			NameOpts: &NameOpts{
   365  				NumberSystem:  Pythagorean,
   366  				MasterNumbers: []int{11},
   367  				ReduceWords:   true,
   368  			},
   369  		}, args{NameSearchOpts{
   370  			Count:          25,
   371  			Offset:         1,
   372  			Seed:           0,
   373  			Dictionary:     "usa_census",
   374  			Gender:         'M',
   375  			Sort:           "common",
   376  			Full:           nil,
   377  			Vowels:         nil,
   378  			Consonants:     nil,
   379  			HiddenPassions: []int{4},
   380  			KarmicLessons:  []int{7, -3},
   381  			Database:       "sqlite://file::memory:?cache=shared",
   382  		}}, 25, 10108, false},
   383  		{"Error John Doe", fields{
   384  			Name: "John Doe",
   385  			NameOpts: &NameOpts{
   386  				NumberSystem:  Pythagorean,
   387  				MasterNumbers: []int{11},
   388  				ReduceWords:   false,
   389  			},
   390  		}, args{NameSearchOpts{
   391  			Count:          0,
   392  			Offset:         5001,
   393  			Seed:           0,
   394  			Dictionary:     "usa_census",
   395  			Gender:         'M',
   396  			Sort:           "uncommon",
   397  			Full:           []int{4},
   398  			Vowels:         nil,
   399  			Consonants:     nil,
   400  			HiddenPassions: []int{7, -3},
   401  			KarmicLessons:  []int{-6},
   402  			Database:       "sqlite://file::memory:?cache=shared",
   403  		}}, 0, 0, true},
   404  		{"Error John ?? Doe", fields{
   405  			Name: "John ?? Doe",
   406  			NameOpts: &NameOpts{
   407  				NumberSystem:  Pythagorean,
   408  				MasterNumbers: []int{11},
   409  				ReduceWords:   false,
   410  			},
   411  		}, args{NameSearchOpts{
   412  			Count:          0,
   413  			Offset:         5001,
   414  			Seed:           0,
   415  			Dictionary:     "usa_census",
   416  			Gender:         'M',
   417  			Sort:           "uncommon",
   418  			Full:           []int{4},
   419  			Vowels:         nil,
   420  			Consonants:     nil,
   421  			HiddenPassions: []int{7, -3},
   422  			KarmicLessons:  []int{-6},
   423  			Database:       "sqlite://file::memory:?cache=shared",
   424  		}}, 0, 0, true},
   425  	}
   426  	for _, tt := range tests {
   427  		DB = nil
   428  		t.Run(tt.name, func(t *testing.T) {
   429  			n := NameNumerology{
   430  				Name:           tt.fields.Name,
   431  				NameOpts:       tt.fields.NameOpts,
   432  				NameSearchOpts: tt.fields.NameSearchOpts,
   433  				mask:           tt.fields.mask,
   434  			}
   435  			gotResults, gotOffset, err := n.Search(tt.args.opts)
   436  			if (err != nil) != tt.wantErr {
   437  				t.Errorf("Search() error = %v, wantErr %v", err, tt.wantErr)
   438  				return
   439  			}
   440  			if !reflect.DeepEqual(len(gotResults), tt.wantResults) {
   441  				t.Errorf("Search() gotResults = %v, want %v", gotResults, tt.wantResults)
   442  			}
   443  			if gotOffset != tt.wantOffset {
   444  				t.Errorf("Search() gotOffset = %v, want %v", gotOffset, tt.wantOffset)
   445  			}
   446  		})
   447  	}
   448  	DB = nil
   449  }
   450  
   451  func TestNameNumerology_Full(t *testing.T) {
   452  	type fields struct {
   453  		Name           string
   454  		NameOpts       *NameOpts
   455  		NameSearchOpts *NameSearchOpts
   456  		mask           *maskStruct
   457  	}
   458  	tests := []struct {
   459  		name       string
   460  		fields     fields
   461  		wantResult int
   462  	}{
   463  		{"Jane Doe", fields{"Jane Doe", &NameOpts{Chaldean, []int{11}, true}, nil, nil},
   464  			1},
   465  		{"Lightning McQueen", fields{"Lightning McQueen", &NameOpts{Chaldean, []int{11}, true}, nil, nil},
   466  			5},
   467  	}
   468  	for _, tt := range tests {
   469  		t.Run(tt.name, func(t *testing.T) {
   470  			n := NameNumerology{
   471  				Name:           tt.fields.Name,
   472  				NameOpts:       tt.fields.NameOpts,
   473  				NameSearchOpts: tt.fields.NameSearchOpts,
   474  				mask:           tt.fields.mask,
   475  			}
   476  			if gotResult := n.Full(); !reflect.DeepEqual(gotResult.Value, tt.wantResult) {
   477  				t.Errorf("Full() = %v, want %v", gotResult, tt.wantResult)
   478  			}
   479  		})
   480  	}
   481  }
   482  
   483  func TestCalculateNames(t *testing.T) {
   484  	type args struct {
   485  		names         []string
   486  		numberSystem  NumberSystem
   487  		masterNumbers []int
   488  		reduceWords   bool
   489  	}
   490  	tests := []struct {
   491  		name        string
   492  		args        args
   493  		wantResults int
   494  	}{
   495  		{"CheckNames", args{
   496  			names:         []string{"Jane Doe", "Lightning McQueen"},
   497  			numberSystem:  Chaldean,
   498  			masterNumbers: []int{11},
   499  			reduceWords:   true,
   500  		}, 2},
   501  	}
   502  	for _, tt := range tests {
   503  		t.Run(tt.name, func(t *testing.T) {
   504  			if gotResults := Names(tt.args.names, tt.args.numberSystem, tt.args.masterNumbers, tt.args.reduceWords); !reflect.DeepEqual(len(gotResults), tt.wantResults) {
   505  				t.Errorf("Names() = %v, want %v", gotResults, tt.wantResults)
   506  			}
   507  		})
   508  	}
   509  }
   510  
   511  func TestNameNumerology_UnknownCharacters(t *testing.T) {
   512  	type fields struct {
   513  		Name           string
   514  		NameOpts       *NameOpts
   515  		NameSearchOpts *NameSearchOpts
   516  		mask           *maskStruct
   517  		counts         *map[int32]int
   518  		unknowns       *unknownCharacters
   519  	}
   520  	tests := []struct {
   521  		name   string
   522  		fields fields
   523  		want   []string
   524  	}{
   525  		{"UnknownCharacters1", fields{Name: "Pr*blem Name", NameOpts: &NameOpts{
   526  			NumberSystem:  Pythagorean,
   527  			MasterNumbers: []int{11, 22, 33},
   528  			ReduceWords:   true,
   529  		}}, []string{"*"}},
   530  		{"UnknownCharacters2", fields{Name: "Problem N@me", NameOpts: &NameOpts{
   531  			NumberSystem:  Pythagorean,
   532  			MasterNumbers: []int{11, 22, 33},
   533  			ReduceWords:   true,
   534  		}}, []string{"@"}},
   535  	}
   536  	for _, tt := range tests {
   537  		t.Run(tt.name, func(t *testing.T) {
   538  			n := &NameNumerology{
   539  				Name:           tt.fields.Name,
   540  				NameOpts:       tt.fields.NameOpts,
   541  				NameSearchOpts: tt.fields.NameSearchOpts,
   542  				mask:           tt.fields.mask,
   543  				counts:         tt.fields.counts,
   544  				unknowns:       tt.fields.unknowns,
   545  			}
   546  			if got := n.UnknownCharacters(); !reflect.DeepEqual(got, tt.want) {
   547  				t.Errorf("UnknownCharacters() = %v, want %v", got, tt.want)
   548  			}
   549  		})
   550  	}
   551  }
   552  
   553  func ExampleNumerologicalResult_Debug() {
   554  	result := Name("George Washington", Pythagorean, []int{11, 22, 33}, true)
   555  	fmt.Print(result.HeartsDesire().Debug())
   556  	// Output:
   557  	// G e o r g e
   558  	// · 5 6 · · 5 = 16 = 7
   559  	// W a s h i n g t o n
   560  	// · 1 · · 9 · · · 6 · = 16 = 7
   561  	// Reduce: 14 = 5
   562  }