github.com/LanderTome/numerologyCalculator@v1.0.2/numerology/utils_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 "reflect" 16 "testing" 17 ) 18 19 func Test_inIntSlice(t *testing.T) { 20 type args struct { 21 v int 22 slice []int 23 } 24 tests := []struct { 25 name string 26 args args 27 want bool 28 }{ 29 {"Found", args{16, []int{3, 14, 7, 16, 0}}, true}, 30 {"Not Found", args{16, []int{3, 14, 7, 0}}, false}, 31 } 32 for _, tt := range tests { 33 t.Run(tt.name, func(t *testing.T) { 34 if got := inIntSlice(tt.args.v, tt.args.slice); got != tt.want { 35 t.Errorf("inIntSlice() = %v, want %v", got, tt.want) 36 } 37 }) 38 } 39 } 40 41 func Test_isMasterNumber(t *testing.T) { 42 type args struct { 43 v int 44 masterNumbers []int 45 } 46 tests := []struct { 47 name string 48 args args 49 want bool 50 }{ 51 {"Master Number", args{33, []int{11, 22, 33}}, true}, 52 {"Not Master Number", args{4, []int{11, 22, 33}}, false}, 53 {"Empty Master Number List", args{1, []int{}}, false}, 54 } 55 for _, tt := range tests { 56 t.Run(tt.name, func(t *testing.T) { 57 if got := isMasterNumber(tt.args.v, tt.args.masterNumbers); got != tt.want { 58 t.Errorf("isMasterNumber() = %v, want %v", got, tt.want) 59 } 60 }) 61 } 62 } 63 64 func Test_numberOfQuestionMarks(t *testing.T) { 65 type args struct { 66 s string 67 } 68 tests := []struct { 69 name string 70 args args 71 want int 72 }{ 73 {"3", args{"Bla? Bl?h B?ah"}, 3}, 74 {"0", args{"No question marks."}, 0}, 75 } 76 for _, tt := range tests { 77 t.Run(tt.name, func(t *testing.T) { 78 if got := numberOfQuestionMarks(tt.args.s); got != tt.want { 79 t.Errorf("numberOfQuestionMarks() = %v, want %v", got, tt.want) 80 } 81 }) 82 } 83 } 84 85 func Test_removeDupicateSpaces(t *testing.T) { 86 type args struct { 87 s string 88 } 89 tests := []struct { 90 name string 91 args args 92 want string 93 }{ 94 {"Remove spaces", args{"Too much space"}, "Too much space"}, 95 {"No removal", args{"Too much space"}, "Too much space"}, 96 } 97 for _, tt := range tests { 98 t.Run(tt.name, func(t *testing.T) { 99 if got := removeDuplicateSpaces(tt.args.s); got != tt.want { 100 t.Errorf("removeDuplicateSpaces() = %v, want %v", got, tt.want) 101 } 102 }) 103 } 104 } 105 106 func Test_splitStringOfNumbers(t *testing.T) { 107 type args struct { 108 n uint64 109 } 110 tests := []struct { 111 name string 112 args args 113 want []int 114 }{ 115 {"473809", args{473809}, []int{4, 7, 3, 8, 0, 9}}, 116 {"1", args{1}, []int{1}}, 117 {"201", args{201}, []int{2, 0, 1}}, 118 } 119 for _, tt := range tests { 120 t.Run(tt.name, func(t *testing.T) { 121 if got := splitNumber(tt.args.n); !reflect.DeepEqual(got, tt.want) { 122 t.Errorf("splitNumber() = %v, want %v", got, tt.want) 123 } 124 }) 125 } 126 } 127 128 func TestGetNumberSystem(t *testing.T) { 129 type args struct { 130 s string 131 } 132 tests := []struct { 133 name string 134 args args 135 want NumberSystem 136 }{ 137 {"Chaldean", args{"chaldeAn"}, Chaldean}, 138 {"Pythagorean", args{"PythaGorean"}, Pythagorean}, 139 {"Default", args{"BJeilsd"}, NumberSystem{}}, 140 } 141 for _, tt := range tests { 142 t.Run(tt.name, func(t *testing.T) { 143 if got, _ := GetNumberSystem(tt.args.s); !reflect.DeepEqual(got, tt.want) { 144 t.Errorf("GetNumberSystem() = %v, want %v", got, tt.want) 145 } 146 }) 147 } 148 } 149 150 func TestGetCountNumbers(t *testing.T) { 151 type args struct { 152 name string 153 numberSystem NumberSystem 154 } 155 tests := []struct { 156 name string 157 args args 158 want map[int32]int 159 want1 int 160 }{ 161 {"Digits", args{"11233344567778990", Pythagorean}, 162 map[int32]int{1: 2, 2: 1, 3: 3, 4: 2, 5: 1, 6: 1, 7: 3, 8: 1, 9: 2}, 3}, 163 {"DigitsWithSomeMissing", args{"1123335677780", Pythagorean}, 164 map[int32]int{1: 2, 2: 1, 3: 3, 4: 0, 5: 1, 6: 1, 7: 3, 8: 1, 9: 0}, 3}, 165 } 166 for _, tt := range tests { 167 t.Run(tt.name, func(t *testing.T) { 168 got, got1, _ := countNumerologicalNumbers(tt.args.name, tt.args.numberSystem) 169 if !reflect.DeepEqual(got, tt.want) { 170 t.Errorf("countNumerologicalNumbers() got = %v, want %v", got, tt.want) 171 } 172 if got1 != tt.want1 { 173 t.Errorf("countNumerologicalNumbers() got1 = %v, want %v", got1, tt.want1) 174 } 175 }) 176 } 177 } 178 179 func TestToAscii(t *testing.T) { 180 type args struct { 181 s string 182 } 183 tests := []struct { 184 name string 185 args args 186 want string 187 }{ 188 {"AsciiTest1", args{" 北亰 "}, "Bei Jing"}, 189 {"AsciiTest2", args{"\tétude "}, "etude"}, 190 {"AsciiTest3", args{"Hello world"}, "Hello world"}, 191 } 192 for _, tt := range tests { 193 t.Run(tt.name, func(t *testing.T) { 194 if got := ToAscii(tt.args.s); got != tt.want { 195 t.Errorf("ToAscii() = %v, want %v", got, tt.want) 196 } 197 }) 198 } 199 }