-
-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #82 from tminaorg/unit-tests
Unit tests
- Loading branch information
Showing
16 changed files
with
388 additions
and
308 deletions.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
package _engines_test | ||
|
||
import ( | ||
"github.com/tminaorg/brzaguza/src/config" | ||
"github.com/tminaorg/brzaguza/src/engines" | ||
) | ||
|
||
type TestCaseHasAnyResults struct { | ||
Query string | ||
Options engines.Options | ||
} | ||
|
||
type TestCaseContainsResults struct { | ||
Query string | ||
ResultURL []string | ||
Options engines.Options | ||
} | ||
|
||
type TestCaseRankedResults struct { | ||
Query string | ||
ResultURL []string | ||
Options engines.Options | ||
} | ||
|
||
func NewConfig(engineName engines.Name) *config.Config { | ||
config.EnabledEngines = append(config.EnabledEngines, engineName) | ||
return &config.Config{ | ||
Engines: map[string]config.Engine{ | ||
engineName.ToLower(): { | ||
Enabled: true, | ||
}, | ||
}, | ||
} | ||
} |
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,59 @@ | ||
package _engines_test | ||
|
||
import ( | ||
"strings" | ||
"testing" | ||
|
||
"github.com/tminaorg/brzaguza/src/config" | ||
"github.com/tminaorg/brzaguza/src/search" | ||
) | ||
|
||
func CheckTestCases(tchar []TestCaseHasAnyResults, tccr []TestCaseContainsResults, | ||
tcrr []TestCaseRankedResults, t *testing.T, conf *config.Config) { | ||
|
||
// TestCaseHasAnyResults | ||
for _, tc := range tchar { | ||
if results := search.PerformSearch(tc.Query, tc.Options, conf); len(results) == 0 { | ||
defer t.Errorf("Got no results for %v", tc.Query) | ||
} | ||
} | ||
|
||
// TestCaseContainsResults | ||
for _, tc := range tccr { | ||
results := search.PerformSearch(tc.Query, tc.Options, conf) | ||
if len(results) == 0 { | ||
defer t.Errorf("Got no results for %v", tc.Query) | ||
} else { | ||
for _, rURL := range tc.ResultURL { | ||
found := false | ||
|
||
for _, r := range results { | ||
if strings.Contains(r.URL, rURL) { | ||
found = true | ||
break | ||
} | ||
} | ||
|
||
if !found { | ||
defer t.Errorf("Couldn't find %v (%v)", rURL, tc.Query) | ||
} | ||
} | ||
} | ||
} | ||
|
||
// TestCaseRankedResults | ||
for _, tc := range tcrr { | ||
results := search.PerformSearch(tc.Query, tc.Options, conf) | ||
if len(results) == 0 { | ||
defer t.Errorf("Got no results for %v", tc.Query) | ||
} else if len(results) < len(tc.ResultURL) { | ||
defer t.Errorf("Number of results is less than test case URLs.") | ||
} else { | ||
for i, rURL := range tc.ResultURL { | ||
if !strings.Contains(results[i].URL, rURL) { | ||
defer t.Errorf("Wrong result on position %v: %v (%v)", i, rURL, tc.Query) | ||
} | ||
} | ||
} | ||
} | ||
} |
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
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
Oops, something went wrong.