2022-10-11 23:18:26 -06:00
|
|
|
// Copyright 2022 The Gitea Authors. All rights reserved.
|
2022-11-27 11:20:29 -07:00
|
|
|
// SPDX-License-Identifier: MIT
|
2022-10-11 23:18:26 -06:00
|
|
|
|
|
|
|
package container
|
|
|
|
|
|
|
|
import (
|
|
|
|
"testing"
|
|
|
|
|
|
|
|
"github.com/stretchr/testify/assert"
|
|
|
|
)
|
|
|
|
|
|
|
|
func TestSet(t *testing.T) {
|
|
|
|
s := make(Set[string])
|
|
|
|
|
|
|
|
assert.True(t, s.Add("key1"))
|
|
|
|
assert.False(t, s.Add("key1"))
|
|
|
|
assert.True(t, s.Add("key2"))
|
|
|
|
|
|
|
|
assert.True(t, s.Contains("key1"))
|
|
|
|
assert.True(t, s.Contains("key2"))
|
2024-11-10 13:07:54 -07:00
|
|
|
assert.True(t, s.Contains("key1", "key2"))
|
2022-10-11 23:18:26 -06:00
|
|
|
assert.False(t, s.Contains("key3"))
|
2024-11-10 13:07:54 -07:00
|
|
|
assert.False(t, s.Contains("key1", "key3"))
|
2022-10-11 23:18:26 -06:00
|
|
|
|
|
|
|
assert.True(t, s.Remove("key2"))
|
|
|
|
assert.False(t, s.Contains("key2"))
|
|
|
|
|
|
|
|
assert.False(t, s.Remove("key3"))
|
|
|
|
|
|
|
|
s.AddMultiple("key4", "key5")
|
|
|
|
assert.True(t, s.Contains("key4"))
|
|
|
|
assert.True(t, s.Contains("key5"))
|
|
|
|
|
|
|
|
s = SetOf("key6", "key7")
|
|
|
|
assert.False(t, s.Contains("key1"))
|
|
|
|
assert.True(t, s.Contains("key6"))
|
|
|
|
assert.True(t, s.Contains("key7"))
|
|
|
|
}
|