The following test code is able to test an HashMap in Golang. The question is whether this is the most concise way of TDD an HashMap in Golang.
import (
"regexp"
"testing"
)
func TestHashMap(t *testing.T) {
for actualKey, actualValue := range hashMap() {
expectedKey := "(hello|world)"
matchedKeys, _ := regexp.MatchString(expectedKey, actualKey)
expectedValue := "test"
matchedValues, _ := regexp.MatchString(expectedValue, actualValue)
if !matchedKeys {
t.Errorf("Test failed, expected: '%s', got: '%s'", expectedKey, actualKey)
}
if !matchedValues {
t.Errorf("Test failed, expected: '%s', got: '%s'", expectedValue, actualValue)
}
}
}
Aucun commentaire:
Enregistrer un commentaire