This repository has been archived by the owner on Dec 11, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
3151c07
commit f465bc7
Showing
3 changed files
with
65 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
package validation | ||
|
||
import "strings" | ||
|
||
type NoRepetedStrategy struct {} | ||
|
||
func (nr *NoRepetedStrategy) IsValid(password string, _ int) bool { | ||
compressedPasswordSb := &strings.Builder{} | ||
var previous rune | ||
for _, r := range password { | ||
if r != previous { | ||
compressedPasswordSb.WriteRune(r) | ||
previous = r | ||
} | ||
} | ||
return compressedPasswordSb.String() == password | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
package validation_test | ||
|
||
import ( | ||
. "github.com/onsi/ginkgo/v2" | ||
. "github.com/onsi/gomega" | ||
|
||
"github.com/brandaogabriel7/studio-sol-back-end-test/src/strategies/validation" | ||
) | ||
|
||
var _ = Describe("NoRepeted", func() { | ||
noRepetedStrategy := validation.NoRepetedStrategy{} | ||
|
||
DescribeTable("When password has no consecutive repeated character", | ||
func (password string) { | ||
isValid := noRepetedStrategy.IsValid(password, 0) | ||
|
||
Expect(isValid).To(BeTrue()) | ||
}, | ||
Entry("abacate123", "abacate123"), | ||
Entry("SenhaForte!", "SenhaForte!"), | ||
Entry("aopa", "aopa"), | ||
) | ||
|
||
DescribeTable("When password has consecutive repeated characters", | ||
func (password string) { | ||
isValid := noRepetedStrategy.IsValid(password, 0) | ||
|
||
Expect(isValid).To(BeFalse()) | ||
}, | ||
Entry("P@ssw0rd", "P@ssw0rd"), | ||
Entry("Opaaaa123", "Opaaaa123"), | ||
Entry("1111111", "1111111"), | ||
) | ||
}) |