generated from OtusGolang/home_work
-
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.
Signed-off-by: Pavel Pogodaev <[email protected]>
- Loading branch information
Pavel Pogodaev
committed
Nov 18, 2024
1 parent
411b524
commit 9488b41
Showing
7 changed files
with
223 additions
and
25 deletions.
There are no files selected for viewing
Empty file.
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
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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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 |
---|---|---|
@@ -1,3 +1,4 @@ | ||
//go:build !bench | ||
// +build !bench | ||
|
||
package hw10programoptimization | ||
|
@@ -6,15 +7,30 @@ import ( | |
"bytes" | ||
"testing" | ||
|
||
"github.com/stretchr/testify/require" | ||
"github.com/stretchr/testify/require" //nolint:depguard | ||
) | ||
|
||
func TestGetDomainStat(t *testing.T) { | ||
data := `{"Id":1,"Name":"Howard Mendoza","Username":"0Oliver","Email":"[email protected]","Phone":"6-866-899-36-79","Password":"InAQJvsq","Address":"Blackbird Place 25"} | ||
{"Id":2,"Name":"Jesse Vasquez","Username":"qRichardson","Email":"[email protected]","Phone":"9-373-949-64-00","Password":"SiZLeNSGn","Address":"Fulton Hill 80"} | ||
{"Id":3,"Name":"Clarence Olson","Username":"RachelAdams","Email":"[email protected]","Phone":"988-48-97","Password":"71kuz3gA5w","Address":"Monterey Park 39"} | ||
{"Id":4,"Name":"Gregory Reid","Username":"tButler","Email":"[email protected]","Phone":"520-04-16","Password":"r639qLNu","Address":"Sunfield Park 20"} | ||
{"Id":5,"Name":"Janice Rose","Username":"KeithHart","Email":"[email protected]","Phone":"146-91-01","Password":"acSBF5","Address":"Russell Trail 61"}` | ||
{"Id":2,"Name":"Jesse Vasquez","Username":"qRichardson","Email":"[email protected]","Phone":"9-373-949-64-00","Password":"SiZLeNSGn","Address":"Fulton Hill 80"} | ||
{"Id":3,"Name":"Clarence Olson","Username":"RachelAdams","Email":"[email protected]","Phone":"988-48-97","Password":"71kuz3gA5w","Address":"Monterey Park 39"} | ||
{"Id":4,"Name":"Gregory Reid","Username":"tButler","Email":"[email protected]","Phone":"520-04-16","Password":"r639qLNu","Address":"Sunfield Park 20"} | ||
{"Id":5,"Name":"Janice Rose","Username":"KeithHart","Email":"[email protected]","Phone":"146-91-01","Password":"acSBF5","Address":"Russell Trail 61"}` | ||
|
||
data2 := `{"Id":1,"Name":"Howard Mendoza","Username":"0Oliver","Email":"aliquid_qui_ea@я.ру","Phone":"6-866-899-36-79","Password":"InAQJvsq","Address":"Blackbird Place 25"} | ||
{"Id":2,"Name":"Jesse Vasquez","Username":"qRichardson","Email":"mLynch@я.ру","Phone":"6-866-899-36-79","Password":"InAQJvsq","Address":"Blackbird Place 25"}` | ||
|
||
data3 := `{"Id":1,"Name":"Howard Mendoza","Username":"0Oliver","Email":"aliquid_qui_ea@Browsedrive","Phone":"6-866-899-36-79","Password":"InAQJvsq","Address":"Blackbird Place 25"} | ||
{"Id":2,"Name":"Jesse Vasquez","Username":"qRichardson","Email":"[email protected]","Phone":"9-373-949-64-00","Password":"SiZLeNSGn","Address":"Fulton Hill 80"} | ||
{"Id":3,"Name":"Clarence Olson","Username":"RachelAdams","Email":"RoseSmith@Browsecat","Phone":"988-48-97","Password":"71kuz3gA5w","Address":"Monterey Park 39"}` | ||
|
||
data4 := `{"Id":1,"Name":"Howard Mendoza","Username":"0Oliver","Email":"@browsedrive.su","Phone":"6-866-899-36-79","Password":"InAQJvsq","Address":"Blackbird Place 25"} | ||
{"Id":2,"Name":"Jesse Vasquez","Username":"qRichardson","Email":"@browsecat.com","Phone":"9-373-949-64-00","Password":"SiZLeNSGn","Address":"Fulton Hill 80"} | ||
{"Id":3,"Name":"Clarence Olson","Username":"RachelAdams","Email":"[email protected]","Phone":"988-48-97","Password":"71kuz3gA5w","Address":"Monterey Park 39"}` | ||
|
||
data5 := `{"Id":1,"Name":"Howard Mendoza","Username":"0Oliver","Email":"aliquid_qui_ea@","Phone":"6-866-899-36-79","Password":"InAQJvsq","Address":"Blackbird Place 25"} | ||
{"Id":2,"Name":"Jesse Vasquez","Username":"qRichardson","Email":"[email protected]","Phone":"9-373-949-64-00","Password":"SiZLeNSGn","Address":"Fulton Hill 80"} | ||
{"Id":3,"Name":"Clarence Olson","Username":"RachelAdams","Email":"RoseSmith@","Phone":"988-48-97","Password":"71kuz3gA5w","Address":"Monterey Park 39"}` | ||
|
||
t.Run("find 'com'", func(t *testing.T) { | ||
result, err := GetDomainStat(bytes.NewBufferString(data), "com") | ||
|
@@ -36,4 +52,50 @@ func TestGetDomainStat(t *testing.T) { | |
require.NoError(t, err) | ||
require.Equal(t, DomainStat{}, result) | ||
}) | ||
|
||
t.Run("find empty domain", func(t *testing.T) { | ||
_, err := GetDomainStat(bytes.NewBufferString(data), "") | ||
require.ErrorIs(t, err, ErrEmptyDomain) | ||
}) | ||
|
||
t.Run("find domain with capital letter", func(t *testing.T) { | ||
result, err := GetDomainStat(bytes.NewBufferString(data), "Com") | ||
require.NoError(t, err) | ||
require.Equal(t, DomainStat{ | ||
"browsecat.com": 2, | ||
"linktype.com": 1, | ||
}, result) | ||
}) | ||
|
||
t.Run("find cyrillic 'ру'", func(t *testing.T) { | ||
result, err := GetDomainStat(bytes.NewBufferString(data2), "ру") | ||
require.NoError(t, err) | ||
require.Equal(t, DomainStat{ | ||
"я.ру": 2, | ||
}, result) | ||
}) | ||
|
||
t.Run("find 'com' without domain", func(t *testing.T) { | ||
result, err := GetDomainStat(bytes.NewBufferString(data3), "com") | ||
require.NoError(t, err) | ||
require.Equal(t, DomainStat{ | ||
"browsecat.com": 1, | ||
}, result) | ||
}) | ||
|
||
t.Run("find 'com' without user name", func(t *testing.T) { | ||
result, err := GetDomainStat(bytes.NewBufferString(data4), "com") | ||
require.NoError(t, err) | ||
require.Equal(t, DomainStat{ | ||
"browsecat.com": 1, | ||
}, result) | ||
}) | ||
|
||
t.Run("find 'com' none symbols after @", func(t *testing.T) { | ||
result, err := GetDomainStat(bytes.NewBufferString(data5), "com") | ||
require.NoError(t, err) | ||
require.Equal(t, DomainStat{ | ||
"browsecat.com": 1, | ||
}, result) | ||
}) | ||
} |