diff --git a/linear/queue.go b/linear/queue.go index 7b4092f..af77cf9 100644 --- a/linear/queue.go +++ b/linear/queue.go @@ -11,8 +11,8 @@ type Queue[T any] struct { container []T } -// QueueFixed -> QueueFixed[Type](size) creates a Queue with no fixed size -func QueueFixed[T any](value uint8) *Queue[T] { +// NewQueueFixed -> NewQueueFixed[Type](size) creates a Queue with no fixed size +func NewQueueFixed[T any](value uint8) *Queue[T] { return &Queue[T]{ capacity: value, container: make([]T, 0, value), diff --git a/linear/stack.go b/linear/stack.go index f249633..3ab526d 100644 --- a/linear/stack.go +++ b/linear/stack.go @@ -10,8 +10,8 @@ type Stack[T any] struct { container []T } -// StackFixed -> creates Stack with a fixed size -func StackFixed[T any](value int) *Stack[T] { +// NewStackFixed -> creates Stack with a fixed size +func NewStackFixed[T any](value int) *Stack[T] { return &Stack[T]{ capacity: value, container: make([]T, 0, value), diff --git a/tests/linearTests/queue_test.go b/tests/linearTests/queue_test.go index 9fa2952..ab39850 100644 --- a/tests/linearTests/queue_test.go +++ b/tests/linearTests/queue_test.go @@ -9,7 +9,7 @@ import ( // --- map type --- func TestQueueWithMaps(t *testing.T) { - q := linear.QueueFixed[map[string]int](3) + q := linear.NewQueueFixed[map[string]int](3) m1 := map[string]int{"a": 1} m2 := map[string]int{"b": 2, "c": 3} @@ -39,7 +39,7 @@ func TestQueueWithMaps(t *testing.T) { } func TestQueueMapMutationAfterEnqueue(t *testing.T) { - q := linear.QueueFixed[map[string]int](2) + q := linear.NewQueueFixed[map[string]int](2) m := map[string]int{"x": 10} q.Push(m) @@ -56,7 +56,7 @@ func TestQueueMapMutationAfterEnqueue(t *testing.T) { } func TestQueueMapOverCapacity(t *testing.T) { - q := linear.QueueFixed[map[string]int](1) + q := linear.NewQueueFixed[map[string]int](1) q.Push(map[string]int{"a": 1}) err := q.Push(map[string]int{"b": 2}) @@ -73,7 +73,7 @@ type Person struct { } func TestQueueWithStructs(t *testing.T) { - q := linear.QueueFixed[Person](3) + q := linear.NewQueueFixed[Person](3) q.Push(Person{"Alice", 30}) q.Push(Person{"Bob", 25}) @@ -95,7 +95,7 @@ func TestQueueWithStructs(t *testing.T) { } func TestQueueStructOverCapacity(t *testing.T) { - q := linear.QueueFixed[Person](2) + q := linear.NewQueueFixed[Person](2) q.Push(Person{"A", 1}) q.Push(Person{"B", 2}) @@ -108,7 +108,7 @@ func TestQueueStructOverCapacity(t *testing.T) { // --- pointer type --- func TestQueueWithPointers(t *testing.T) { - q := linear.QueueFixed[*Person](3) + q := linear.NewQueueFixed[*Person](3) p1 := &Person{"Alice", 30} p2 := &Person{"Bob", 25} @@ -128,7 +128,7 @@ func TestQueueWithPointers(t *testing.T) { } func TestQueueNilPointerPull(t *testing.T) { - q := linear.QueueFixed[*Person](2) + q := linear.NewQueueFixed[*Person](2) q.Push(nil) got, err := q.Pop() @@ -141,7 +141,7 @@ func TestQueueNilPointerPull(t *testing.T) { } func TestQueuePointerMutationAfterEnqueue(t *testing.T) { - q := linear.QueueFixed[*Person](1) + q := linear.NewQueueFixed[*Person](1) p := &Person{"Alice", 30} q.Push(p) @@ -157,7 +157,7 @@ func TestQueuePointerMutationAfterEnqueue(t *testing.T) { // --- slice type --- func TestQueueWithSlices(t *testing.T) { - q := linear.QueueFixed[[]int](3) + q := linear.NewQueueFixed[[]int](3) q.Push([]int{1, 2, 3}) q.Push([]int{}) // empty slice @@ -174,7 +174,7 @@ func TestQueueWithSlices(t *testing.T) { } func TestQueueSliceMutationAfterEnqueue(t *testing.T) { - q := linear.QueueFixed[[]int](1) + q := linear.NewQueueFixed[[]int](1) s := []int{1, 2, 3} q.Push(s) @@ -190,7 +190,7 @@ func TestQueueSliceMutationAfterEnqueue(t *testing.T) { } func TestQueueSliceOverCapacity(t *testing.T) { - q := linear.QueueFixed[[]int](1) + q := linear.NewQueueFixed[[]int](1) q.Push([]int{1}) err := q.Push([]int{2}) @@ -202,7 +202,7 @@ func TestQueueSliceOverCapacity(t *testing.T) { // --- empty queue edge cases across all types --- func TestQueuePullEmptyMap(t *testing.T) { - q := linear.QueueFixed[map[string]int](2) + q := linear.NewQueueFixed[map[string]int](2) _, err := q.Pop() if err == nil { t.Error("expected error pulling from empty map queue") @@ -210,7 +210,7 @@ func TestQueuePullEmptyMap(t *testing.T) { } func TestQueuePullEmptyPointer(t *testing.T) { - q := linear.QueueFixed[*Person](2) + q := linear.NewQueueFixed[*Person](2) _, err := q.Pop() if err == nil { t.Error("expected error pulling from empty pointer queue") @@ -218,7 +218,7 @@ func TestQueuePullEmptyPointer(t *testing.T) { } func TestQueuePullEmptySlice(t *testing.T) { - q := linear.QueueFixed[[]int](2) + q := linear.NewQueueFixed[[]int](2) _, err := q.Pop() if err == nil { t.Error("expected error pulling from empty slice queue") @@ -226,7 +226,7 @@ func TestQueuePullEmptySlice(t *testing.T) { } func TestQueueCullEmptyStruct(t *testing.T) { - q := linear.QueueFixed[Person](2) + q := linear.NewQueueFixed[Person](2) _, err := q.Cull() if err == nil { t.Error("expected error culling from empty struct queue") @@ -234,7 +234,7 @@ func TestQueueCullEmptyStruct(t *testing.T) { } func TestQueuePeekEmptyPointer(t *testing.T) { - q := linear.QueueFixed[*Person](2) + q := linear.NewQueueFixed[*Person](2) val, ok := q.Peek() if ok || val != nil { t.Errorf("expected (nil, false) from empty pointer queue Peek, got (%v, %v)", val, ok) diff --git a/tests/linearTests/stack_test.go b/tests/linearTests/stack_test.go index f95babb..a43f544 100644 --- a/tests/linearTests/stack_test.go +++ b/tests/linearTests/stack_test.go @@ -9,7 +9,7 @@ import ( // --- map type --- func TestStackWithMaps(t *testing.T) { - s := linear.StackFixed[map[string]int](3) + s := linear.NewStackFixed[map[string]int](3) m1 := map[string]int{"a": 1} m2 := map[string]int{"b": 2, "c": 3} @@ -39,7 +39,7 @@ func TestStackWithMaps(t *testing.T) { } func TestStackMapMutationAfterPush(t *testing.T) { - s := linear.StackFixed[map[string]int](2) + s := linear.NewStackFixed[map[string]int](2) m := map[string]int{"x": 10} s.Push(m) @@ -55,7 +55,7 @@ func TestStackMapMutationAfterPush(t *testing.T) { } func TestStackMapOverCapacity(t *testing.T) { - s := linear.StackFixed[map[string]int](1) + s := linear.NewStackFixed[map[string]int](1) s.Push(map[string]int{"a": 1}) err := s.Push(map[string]int{"b": 2}) @@ -67,7 +67,7 @@ func TestStackMapOverCapacity(t *testing.T) { // --- struct (object) type --- func TestStackWithStructs(t *testing.T) { - s := linear.StackFixed[Person](3) + s := linear.NewStackFixed[Person](3) s.Push(Person{"Alice", 30}) s.Push(Person{"Bob", 25}) @@ -94,7 +94,7 @@ func TestStackWithStructs(t *testing.T) { } func TestStackStructOverCapacity(t *testing.T) { - s := linear.StackFixed[Person](2) + s := linear.NewStackFixed[Person](2) s.Push(Person{"A", 1}) s.Push(Person{"B", 2}) @@ -105,7 +105,7 @@ func TestStackStructOverCapacity(t *testing.T) { } func TestStackClearStructs(t *testing.T) { - s := linear.StackFixed[Person](3) + s := linear.NewStackFixed[Person](3) s.Push(Person{"Alice", 30}) s.Push(Person{"Bob", 25}) @@ -119,7 +119,7 @@ func TestStackClearStructs(t *testing.T) { // --- pointer type --- func TestStackWithPointers(t *testing.T) { - s := linear.StackFixed[*Person](3) + s := linear.NewStackFixed[*Person](3) p1 := &Person{"Alice", 30} p2 := &Person{"Bob", 25} @@ -144,7 +144,7 @@ func TestStackWithPointers(t *testing.T) { } func TestStackNilPointerPop(t *testing.T) { - s := linear.StackFixed[*Person](2) + s := linear.NewStackFixed[*Person](2) s.Push(nil) got, err := s.Pop() @@ -157,7 +157,7 @@ func TestStackNilPointerPop(t *testing.T) { } func TestStackPointerMutationAfterPush(t *testing.T) { - s := linear.StackFixed[*Person](1) + s := linear.NewStackFixed[*Person](1) p := &Person{"Alice", 30} s.Push(p) @@ -173,7 +173,7 @@ func TestStackPointerMutationAfterPush(t *testing.T) { // --- slice type --- func TestStackWithSlices(t *testing.T) { - s := linear.StackFixed[[]int](3) + s := linear.NewStackFixed[[]int](3) s.Push([]int{1, 2, 3}) s.Push([]int{}) @@ -195,7 +195,7 @@ func TestStackWithSlices(t *testing.T) { } func TestStackSliceMutationAfterPush(t *testing.T) { - s := linear.StackFixed[[]int](1) + s := linear.NewStackFixed[[]int](1) sl := []int{1, 2, 3} s.Push(sl) @@ -211,7 +211,7 @@ func TestStackSliceMutationAfterPush(t *testing.T) { } func TestStackSliceOverCapacity(t *testing.T) { - s := linear.StackFixed[[]int](1) + s := linear.NewStackFixed[[]int](1) s.Push([]int{1}) err := s.Push([]int{2}) @@ -223,7 +223,7 @@ func TestStackSliceOverCapacity(t *testing.T) { // --- empty stack edge cases --- func TestStackPopEmpty(t *testing.T) { - s := linear.StackFixed[map[string]int](2) + s := linear.NewStackFixed[map[string]int](2) _, err := s.Pop() if err == nil { t.Error("expected error popping from empty map stack") @@ -231,7 +231,7 @@ func TestStackPopEmpty(t *testing.T) { } func TestStackPopEmptyPointer(t *testing.T) { - s := linear.StackFixed[*Person](2) + s := linear.NewStackFixed[*Person](2) _, err := s.Pop() if err == nil { t.Error("expected error popping from empty pointer stack") @@ -239,7 +239,7 @@ func TestStackPopEmptyPointer(t *testing.T) { } func TestStackPopEmptySlice(t *testing.T) { - s := linear.StackFixed[[]int](2) + s := linear.NewStackFixed[[]int](2) _, err := s.Pop() if err == nil { t.Error("expected error popping from empty slice stack") @@ -247,7 +247,7 @@ func TestStackPopEmptySlice(t *testing.T) { } func TestStackPopEmptyStruct(t *testing.T) { - s := linear.StackFixed[Person](2) + s := linear.NewStackFixed[Person](2) _, err := s.Pop() if err == nil { t.Error("expected error popping from empty struct stack") @@ -263,7 +263,7 @@ func TestStackPeekEmptyPanics(t *testing.T) { t.Error("expected panic from Peek on empty stack, got none") } }() - s := linear.StackFixed[*Person](2) + s := linear.NewStackFixed[*Person](2) s.Peek() } @@ -273,6 +273,6 @@ func TestStackFirstEmptyPanics(t *testing.T) { t.Error("expected panic from First on empty stack, got none") } }() - s := linear.StackFixed[*Person](2) + s := linear.NewStackFixed[*Person](2) s.First() }