Exemplo n.º 1
0
func TestExistsInStringSet(t *testing.T) {
	words := []string{
		"www", "wwww", "mail", "api", "status", "cache", "cdn", "direct",
		"blog", "wiki", "faq", "help", "support", "knowledgebase", "mobile",
		"demo", "beta", "test", "testing", "prod", "production", "stg", "staging", "dev", "devel", "development",
		"root", "admin", "administrator", "superadmin", "sysadmin", "webmaster",
		"user", "account", "bot", "anonymous", "guest", "member", "collaborator", "moderator", "owner",
		"news", "job", "jobs", "career", "pricing", "about", "contact", "terms", "privacy", "tour",
		"search", "discover", "popular", "trending", "enterprise",
		"join", "invite", "register", "follow", "login", "logout", "auth", "oauth", "ping",
		"download", "upload", "app", "apps", "marketplace", "addons",
		"mention", "mentions", "tag", "tags", "email", "example", "old", "new",
	}

	s := set.NewStringSet(words...)

	for _, v := range words {
		if !s.Exists(v) {
			t.Errorf("expecting value %v to exist in the set", v)
		}
	}
}
Exemplo n.º 2
0
func TestStringSet(t *testing.T) {
	s := set.NewStringSet("a", "b", "a", "c")

	s = s.Add("d", "a", "b", "c", "e")
	if len(s) != 5 {
		t.Error("expecting 5 values in the set")
	}
	if !reflect.DeepEqual([]string(s), []string{"a", "b", "c", "d", "e"}) {
		t.Error("invalid set")
	}

	s = s.Remove("d", "a")
	if len(s) != 3 {
		t.Error("expecting 3 values in the set")
	}
	if !reflect.DeepEqual([]string(s), []string{"b", "c", "e"}) {
		t.Error("invalid set")
	}

	s = s.Add("z", "f", "e", "b", "c")
	if len(s) != 5 {
		t.Error("expecting 5 values in the set, got:", len(s))
	}
	if !reflect.DeepEqual([]string(s), []string{"b", "c", "e", "f", "z"}) {
		t.Error("invalid set")
	}

	if !s.Exists("b") {
		t.Error("expecting value to exist in the set")
	}
	if s.Exists("asdf") {
		t.Error("expecting value to not exist in the set")
	}

	if !reflect.DeepEqual([]string(s), []string{"b", "c", "e", "f", "z"}) {
		t.Error("invalid set")
	}

}