52 lines
841 B
Go
52 lines
841 B
Go
|
// Copyright 2024 Matthew Rich <matthewrich.conf@gmail.com>. All rights reserved.
|
||
|
|
||
|
package ds
|
||
|
|
||
|
import (
|
||
|
"github.com/stretchr/testify/assert"
|
||
|
"testing"
|
||
|
"log/slog"
|
||
|
)
|
||
|
|
||
|
var (
|
||
|
)
|
||
|
|
||
|
func TestNewOrderedSet(t *testing.T) {
|
||
|
s := NewOrderedSet[string]()
|
||
|
assert.NotNil(t, s)
|
||
|
|
||
|
testValues := []string{
|
||
|
"foo",
|
||
|
"bar",
|
||
|
"baz",
|
||
|
"quuz",
|
||
|
}
|
||
|
|
||
|
for _,value := range testValues {
|
||
|
|
||
|
s.Add(value)
|
||
|
|
||
|
|
||
|
slog.Info("TestNewOrderedSet - ADD", "item", value, "s", s)
|
||
|
|
||
|
assert.True(t, s.Contains(value))
|
||
|
slog.Info("TestNewOrderedSet - CONTAINS", "s", s)
|
||
|
|
||
|
for x, item := range s.Items() {
|
||
|
slog.Info("TestNewOrderedSet", "item", item, "s", s)
|
||
|
assert.Equal(t, testValues[x], *item)
|
||
|
}
|
||
|
|
||
|
}
|
||
|
s.Delete("bar")
|
||
|
|
||
|
expectedValues := []string {
|
||
|
"foo",
|
||
|
"baz",
|
||
|
"quuz",
|
||
|
}
|
||
|
for x, item := range s.Items() {
|
||
|
assert.Equal(t, expectedValues[x], *item)
|
||
|
}
|
||
|
}
|