1package main
23import(4"regexp"5"testing"6)78funcMatchPasswordString(password string)bool{9// must be equal or longer than 8 characters10iflen(password)<8{11returnfalse12}13// must contain at least each one uppercase, lowercase and number14 reg :=[]*regexp.Regexp{15 regexp.MustCompile(`[a-z]`), regexp.MustCompile(`[A-Z]`),16 regexp.MustCompile(`\d`),17}18for_, r :=range reg {19if r.FindString(password)==""{20returnfalse21}22}23returntrue24}2526funcTestMatchPasswordString(t *testing.T){27 cases :=[]struct{28 input string29 want bool30}{31{"Ftk3bg1aCW",true},32{"1aZ",false},// less than 8 characters33{"zJmsZJiKeS",false},// uppercase and lowercase letters34{"v0x51aip1t",false},// lowercase letters and numbers35{"WZO257AV6Z",false},// uppercase letters and numbers36{"_%+1&a!*Z@",true},// other characters37}3839for i, p :=range cases {40 got :=MatchPasswordString(p.input)41if got != p.want {42 t.Errorf("unexpected ExcelColumn result, case=%d, input=%s, got=%v, want=%v",43 i+1, p.input, got, p.want)44}45}46}
sh
1$ go test match_password_string_test.go
2ok command-line-arguments 0.001s
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2022/01/11 12:52