summaryrefslogtreecommitdiffstats
path: root/modules/container/set_test.go
blob: 1502236034a13b20183fd274b65bda63b991521d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
// Copyright 2022 The Gitea Authors. All rights reserved.
// SPDX-License-Identifier: MIT

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"))
	assert.False(t, s.Contains("key3"))

	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"))
}