Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
/**
* @link Problem definition [[docs/hackerrank/interview_preparation_kit/dictionaries_and_hashmaps/two_strings.md]]
*/

package hackerrank

const __TWO_STRINGS_YES__ = "Yes"
const __TWO_STRINGS_NO__ = "No"

func twoStringsCompute(s1 string, s2 string) bool {
for _, letter := range s1 {
for _, n := range s2 {
if letter == n {
return true
}
}
}

return false
}

func twoStrings(s1 string, s2 string) string {
if twoStringsCompute(s1, s2) {
return __TWO_STRINGS_YES__
}

return __TWO_STRINGS_NO__
}

func TwoStrings(s1 string, s2 string) string {
return twoStrings(s1, s2)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
[
{
"title": "Example 1",
"s1": "and",
"s2": "art",
"expected": "Yes"
},
{
"title": "Example 2",
"s1": "be",
"s2": "cat",
"expected": "No"
},
{
"title": "Sample Test Case 0",
"s1": "hello",
"s2": "world",
"expected": "Yes"
}
]
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
package hackerrank

import (
"fmt"
"os"
"testing"

"github.com/stretchr/testify/assert"
"gon.cl/algorithms/utils"
)

type TwoStringsTestCase struct {
S1 string `json:"s1"`
S2 string `json:"s2"`
Expected string `json:"expected"`
}

var TwoStringsTestCases []TwoStringsTestCase

// You can use testing.T, if you want to test the code without benchmarking
func TwoStringsSetupSuite(t testing.TB) {
wd, _ := os.Getwd()
filepath := wd + "/two_strings.testcases.json"
t.Log("Setup test cases from JSON: ", filepath)

var _, err = utils.LoadJSON(filepath, &TwoStringsTestCases)
if err != nil {
t.Log(err)
}
}

func TestTwoStrings(t *testing.T) {

TwoStringsSetupSuite(t)

for _, tt := range TwoStringsTestCases {
testname := fmt.Sprintf("TwoStrings(%v, %v) => %v \n", tt.S1, tt.S2, tt.Expected)
t.Run(testname, func(t *testing.T) {
ans := TwoStrings(tt.S1, tt.S2)
assert.Equal(t, tt.Expected, ans)
})
}
}