Skip to content

Commit

Permalink
[test] Add examples to SortedList[T]
Browse files Browse the repository at this point in the history
  • Loading branch information
BioCrossCoder committed May 23, 2024
1 parent 58b1fe4 commit d7be91c
Show file tree
Hide file tree
Showing 3 changed files with 55 additions and 0 deletions.
23 changes: 23 additions & 0 deletions typed/collections/sortedcontainers/sortedlist/modify_test.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package sortedlist

import (
"fmt"
"github.com/smartystreets/goconvey/convey"
"github.com/stretchr/testify/assert"
"testing"
Expand Down Expand Up @@ -114,3 +115,25 @@ func TestReverse(t *testing.T) {
assert.True(t, l.Equal(*NewSortedList(DescendOrder, 1, 2, 3, 4, 5)))
})
}

func ExampleSortedList_RemoveRange() {
l := NewSortedList(AscendOrder, 2, 3, 1, 4, 5)
fmt.Println(l.ToArray())
removed := l.RemoveRange(1, 3)
fmt.Println(removed.ToArray())
fmt.Println(l.ToArray())
// Output:
// [1 2 3 4 5]
// [2 3]
// [1 4 5]
}

func ExampleSortedList_Insert() {
l := NewSortedList(AscendOrder, 1, 5, 8)
fmt.Println(l.ToArray())
l.Insert(3)
fmt.Println(l.ToArray())
// Output:
// [1 5 8]
// [1 3 5 8]
}
25 changes: 25 additions & 0 deletions typed/collections/sortedcontainers/sortedlist/search_test.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package sortedlist

import (
"fmt"
"github.com/biocrosscoder/flex/common"
"github.com/smartystreets/goconvey/convey"
"github.com/stretchr/testify/assert"
Expand Down Expand Up @@ -70,3 +71,27 @@ func TestSearchElement(t *testing.T) {
})
})
}

func ExampleSortedList_Max() {
l := NewSortedList(AscendOrder, 1, 2, 3, 2, 4)
m, _ := l.Max()
fmt.Println(m)
l.Reverse()
m, _ = l.Max()
fmt.Println(m)
// Output:
// 4
// 1
}

func ExampleSortedList_Min() {
l := NewSortedList(AscendOrder, 1, 2, 3, 2, 4)
m, _ := l.Min()
fmt.Println(m)
l.Reverse()
m, _ = l.Min()
fmt.Println(m)
// Output:
// 1
// 4
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package sortedlist

import (
"fmt"
"github.com/biocrosscoder/flex/typed/collections/arraylist"
"github.com/smartystreets/goconvey/convey"
"github.com/stretchr/testify/assert"
Expand All @@ -25,3 +26,9 @@ func TestSortedList(t *testing.T) {
assert.True(t, l.Slice(-1, -10, -1).Equal(l.ToReversed()))
})
}

func ExampleSortedList() {
l := NewSortedList(AscendOrder, 1, 3, 2, 5, 6, 9)
fmt.Println(l.ToArray())
// Output: [1 2 3 5 6 9]
}

0 comments on commit d7be91c

Please sign in to comment.