From c78081fb841628d0252275d4306d160bc99fb000 Mon Sep 17 00:00:00 2001 From: alfred-mk Date: Tue, 4 Feb 2025 11:42:14 +0300 Subject: [PATCH] added TestInsertOrShift --- profile/profile_test.go | 42 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) create mode 100644 profile/profile_test.go diff --git a/profile/profile_test.go b/profile/profile_test.go new file mode 100644 index 0000000..a210646 --- /dev/null +++ b/profile/profile_test.go @@ -0,0 +1,42 @@ +package profile + +import ( + "testing" + + "github.com/alecthomas/assert/v2" + "github.com/stretchr/testify/require" +) + +func TestInsertOrShift(t *testing.T) { + tests := []struct { + name string + profile Profile + index int + value string + expected []string + }{ + { + name: "Insert within range", + profile: Profile{ProfileItems: []string{"A", "B", "C"}, Max: 5}, + index: 1, + value: "X", + expected: []string{"A", "X"}, + }, + { + name: "Insert beyond range", + profile: Profile{ProfileItems: []string{"A"}, Max: 5}, + index: 3, + value: "Y", + expected: []string{"A", "0", "0", "Y"}, + }, + } + + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + p := tt.profile + p.InsertOrShift(tt.index, tt.value) + require.NotNil(t, p.ProfileItems) + assert.Equal(t, tt.expected, p.ProfileItems) + }) + } +}