github.com/LanderTome/numerologyCalculator@v1.0.2/numerology/calculateDates_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  
    12  package numerology
    13  
    14  import (
    15  	"fmt"
    16  	"github.com/olekukonko/tablewriter"
    17  	"os"
    18  	"reflect"
    19  	"testing"
    20  	"time"
    21  )
    22  
    23  func TestCalculateDate(t *testing.T) {
    24  	type args struct {
    25  		date          time.Time
    26  		masterNumbers []int
    27  	}
    28  	tests := []struct {
    29  		name       string
    30  		args       args
    31  		wantResult DateNumerology
    32  	}{
    33  		{"DateNumerology", args{NewDate(2021, 1, 1), []int{11, 22, 33}},
    34  			DateNumerology{NewDate(2021, 1, 1), &DateOpts{[]int{11, 22, 33}}, nil},
    35  		},
    36  	}
    37  	for _, tt := range tests {
    38  		t.Run(tt.name, func(t *testing.T) {
    39  			if gotResult := Date(tt.args.date, tt.args.masterNumbers); !reflect.DeepEqual(gotResult, tt.wantResult) {
    40  				t.Errorf("Date() = %v, want %v", gotResult, tt.wantResult)
    41  			}
    42  		})
    43  	}
    44  }
    45  
    46  func TestCalculateDates(t *testing.T) {
    47  	type args struct {
    48  		dates         []time.Time
    49  		masterNumbers []int
    50  	}
    51  	tests := []struct {
    52  		name        string
    53  		args        args
    54  		wantResults []DateNumerology
    55  	}{
    56  		{"DatesNumerology", args{[]time.Time{NewDate(2021, 2, 1)}, []int{11, 22}},
    57  			[]DateNumerology{{NewDate(2021, 2, 1), &DateOpts{[]int{11, 22}}, nil}},
    58  		},
    59  	}
    60  	for _, tt := range tests {
    61  		t.Run(tt.name, func(t *testing.T) {
    62  			if gotResults := Dates(tt.args.dates, tt.args.masterNumbers); !reflect.DeepEqual(gotResults, tt.wantResults) {
    63  				t.Errorf("Dates() = %v, want %v", gotResults, tt.wantResults)
    64  			}
    65  		})
    66  	}
    67  }
    68  
    69  func TestDateNumerology_Event(t *testing.T) {
    70  	type fields struct {
    71  		Date           time.Time
    72  		DateOpts       *DateOpts
    73  		DateSearchOpts *DateSearchOpts
    74  	}
    75  	tests := []struct {
    76  		name       string
    77  		fields     fields
    78  		wantResult int
    79  	}{
    80  		{"1970-01-01", fields{NewDate(1970, 1, 1), &DateOpts{[]int{11, 22, 33}}, nil},
    81  			1},
    82  		{"1970-01-02", fields{NewDate(1970, 1, 2), &DateOpts{[]int{11, 22, 33}}, nil},
    83  			2},
    84  	}
    85  	for _, tt := range tests {
    86  		t.Run(tt.name, func(t *testing.T) {
    87  			d := DateNumerology{
    88  				Date:           tt.fields.Date,
    89  				DateOpts:       tt.fields.DateOpts,
    90  				DateSearchOpts: tt.fields.DateSearchOpts,
    91  			}
    92  			if gotResult := d.Event().Value; !reflect.DeepEqual(gotResult, tt.wantResult) {
    93  				t.Errorf("Event() = %v, want %v", gotResult, tt.wantResult)
    94  			}
    95  		})
    96  	}
    97  }
    98  
    99  func TestDateNumerology_LifePath(t *testing.T) {
   100  	type fields struct {
   101  		Date           time.Time
   102  		DateOpts       *DateOpts
   103  		DateSearchOpts *DateSearchOpts
   104  	}
   105  	tests := []struct {
   106  		name       string
   107  		fields     fields
   108  		wantResult int
   109  	}{
   110  		{"2010-05-04", fields{NewDate(2010, 5, 4), &DateOpts{[]int{11, 22, 33}}, nil},
   111  			3},
   112  		{"1970-01-02", fields{NewDate(1970, 1, 2), &DateOpts{[]int{11, 22, 33}}, nil},
   113  			11},
   114  		{"1993-11-11", fields{NewDate(1993, 11, 11), &DateOpts{[]int{11, 22, 33, 44}}, nil},
   115  			44},
   116  	}
   117  	for _, tt := range tests {
   118  		t.Run(tt.name, func(t *testing.T) {
   119  			d := DateNumerology{
   120  				Date:           tt.fields.Date,
   121  				DateOpts:       tt.fields.DateOpts,
   122  				DateSearchOpts: tt.fields.DateSearchOpts,
   123  			}
   124  			if gotResult := d.LifePath().Value; !reflect.DeepEqual(gotResult, tt.wantResult) {
   125  				t.Errorf("LifePath() = %v, want %v", gotResult, tt.wantResult)
   126  			}
   127  		})
   128  	}
   129  }
   130  
   131  func TestDateNumerology_Search(t *testing.T) {
   132  	type fields struct {
   133  		Date           time.Time
   134  		DateOpts       *DateOpts
   135  		DateSearchOpts *DateSearchOpts
   136  	}
   137  	type args struct {
   138  		opts DateSearchOpts
   139  	}
   140  	tests := []struct {
   141  		name       string
   142  		fields     fields
   143  		args       args
   144  		wantResult int
   145  		wantOffset int64
   146  	}{
   147  		{"1970-01-02",
   148  			fields{NewDate(1970, 1, 1), &DateOpts{[]int{11, 22, 33}}, nil},
   149  			args{DateSearchOpts{
   150  				Count:         100,
   151  				Offset:        0,
   152  				Match:         []int{11},
   153  				MonthsForward: 48,
   154  				Dow:           []int{0, 5, 6},
   155  				LifePath:      true,
   156  			}},
   157  			39, 0},
   158  	}
   159  	for _, tt := range tests {
   160  		t.Run(tt.name, func(t *testing.T) {
   161  			d := DateNumerology{
   162  				Date:           tt.fields.Date,
   163  				DateOpts:       tt.fields.DateOpts,
   164  				DateSearchOpts: tt.fields.DateSearchOpts,
   165  			}
   166  			gotResult, gotOffset := d.Search(tt.args.opts)
   167  			if !reflect.DeepEqual(len(gotResult), tt.wantResult) {
   168  				t.Errorf("Search() gotResult = %v, want %v", len(gotResult), tt.wantResult)
   169  			}
   170  			if gotOffset != tt.wantOffset {
   171  				t.Errorf("Search() gotOffset = %v, want %v", gotOffset, tt.wantOffset)
   172  			}
   173  		})
   174  	}
   175  }
   176  
   177  func TestNewDate(t *testing.T) {
   178  	type args struct {
   179  		year  int
   180  		month int
   181  		day   int
   182  	}
   183  	tests := []struct {
   184  		name string
   185  		args args
   186  		want time.Time
   187  	}{
   188  		{"2010-09-18", args{2010, 9, 18}, time.Date(2010, 9, 18, 12, 0, 0, 0, time.UTC)},
   189  		{"1934-04-29", args{1934, 4, 29}, time.Date(1934, 4, 29, 12, 0, 0, 0, time.UTC)},
   190  		{"2145-12-08", args{2145, 12, 8}, time.Date(2145, 12, 8, 12, 0, 0, 0, time.UTC)},
   191  	}
   192  	for _, tt := range tests {
   193  		t.Run(tt.name, func(t *testing.T) {
   194  			if got := NewDate(tt.args.year, tt.args.month, tt.args.day); !reflect.DeepEqual(got, tt.want) {
   195  				t.Errorf("NewDate() = %v, want %v", got, tt.want)
   196  			}
   197  		})
   198  	}
   199  }
   200  
   201  func Test_letterValuesFromNumber(t *testing.T) {
   202  	type args struct {
   203  		n             int
   204  		masterNumbers []int
   205  	}
   206  	tests := []struct {
   207  		name string
   208  		args args
   209  		want []letterValue
   210  	}{
   211  		{"MasterNumberTest", args{11, []int{11, 22, 33}},
   212  			[]letterValue{{"11", 11}},
   213  		},
   214  	}
   215  	for _, tt := range tests {
   216  		t.Run(tt.name, func(t *testing.T) {
   217  			if got := letterValuesFromNumber(tt.args.n, tt.args.masterNumbers); !reflect.DeepEqual(got, tt.want) {
   218  				t.Errorf("letterValuesFromNumber() = %v, want %v", got, tt.want)
   219  			}
   220  		})
   221  	}
   222  }
   223  
   224  func ExampleDateNumerology_Event() {
   225  	date := NewDate(2021, 1, 5)
   226  	result := Date(date, []int{11, 22, 33}).Event()
   227  	fmt.Printf("%v - %v", date.Format("Monday, January 2, 2006"), result.Value)
   228  	// Output: Tuesday, January 5, 2021 - 2
   229  }
   230  
   231  func ExampleDateNumerology_LifePath() {
   232  	date := NewDate(2021, 1, 5)
   233  	result := Date(date, []int{11, 22, 33}).LifePath()
   234  	fmt.Printf("%v - %v", date.Format("Monday, January 2, 2006"), result.Value)
   235  	//  Output: Tuesday, January 5, 2021 - 11
   236  }
   237  
   238  func ExampleDateNumerology_Search() {
   239  	opts := DateSearchOpts{
   240  		Count:         5,
   241  		Match:         []int{1},
   242  		MonthsForward: 12,
   243  		Dow:           []int{int(time.Monday), int(time.Friday), int(time.Saturday)},
   244  		LifePath:      false,
   245  	}
   246  	date := NewDate(2021, 1, 1)
   247  	results, _ := Date(date, []int{11, 22, 33}).Search(opts)
   248  
   249  	table := tablewriter.NewWriter(os.Stdout)
   250  	table.SetHeader([]string{"", "Date", "#"})
   251  	for i, result := range results {
   252  		table.Append([]string{fmt.Sprintf("%v", i+1), result.Date.Format("Monday, January 2, 2006"), fmt.Sprintf("%v", result.Event().Value)})
   253  	}
   254  	table.Render()
   255  	// Output:
   256  	// +---+---------------------------+---+
   257  	// |   |           DATE            | # |
   258  	// +---+---------------------------+---+
   259  	// | 1 | Monday, January 4, 2021   | 1 |
   260  	// | 2 | Friday, January 22, 2021  | 1 |
   261  	// | 3 | Friday, February 12, 2021 | 1 |
   262  	// | 4 | Saturday, March 20, 2021  | 1 |
   263  	// | 5 | Monday, March 29, 2021    | 1 |
   264  	// +---+---------------------------+---+
   265  }