mirror of
https://github.com/nbd-wtf/go-nostr.git
synced 2025-10-10 21:04:10 +02:00
CompareEvent/Ptr/Reverse utils.
This commit is contained in:
@@ -1,9 +1,11 @@
|
||||
package nostr
|
||||
|
||||
import (
|
||||
"slices"
|
||||
"testing"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
"github.com/stretchr/testify/require"
|
||||
)
|
||||
|
||||
func TestIsValidRelayURL(t *testing.T) {
|
||||
@@ -24,3 +26,53 @@ func TestIsValidRelayURL(t *testing.T) {
|
||||
assert.Equal(t, test.want, got)
|
||||
}
|
||||
}
|
||||
|
||||
func TestEventsCompare(t *testing.T) {
|
||||
list := []Event{
|
||||
{CreatedAt: 12},
|
||||
{CreatedAt: 8},
|
||||
{CreatedAt: 26},
|
||||
{CreatedAt: 1},
|
||||
}
|
||||
|
||||
slices.SortFunc(list, CompareEvent)
|
||||
require.Equal(t, []Event{
|
||||
{CreatedAt: 1},
|
||||
{CreatedAt: 8},
|
||||
{CreatedAt: 12},
|
||||
{CreatedAt: 26},
|
||||
}, list)
|
||||
|
||||
slices.SortFunc(list, CompareEventReverse)
|
||||
require.Equal(t, []Event{
|
||||
{CreatedAt: 26},
|
||||
{CreatedAt: 12},
|
||||
{CreatedAt: 8},
|
||||
{CreatedAt: 1},
|
||||
}, list)
|
||||
}
|
||||
|
||||
func TestEventsComparePtr(t *testing.T) {
|
||||
list := []*Event{
|
||||
{CreatedAt: 12},
|
||||
{CreatedAt: 8},
|
||||
{CreatedAt: 26},
|
||||
{CreatedAt: 1},
|
||||
}
|
||||
|
||||
slices.SortFunc(list, CompareEventPtr)
|
||||
require.Equal(t, []*Event{
|
||||
{CreatedAt: 1},
|
||||
{CreatedAt: 8},
|
||||
{CreatedAt: 12},
|
||||
{CreatedAt: 26},
|
||||
}, list)
|
||||
|
||||
slices.SortFunc(list, CompareEventPtrReverse)
|
||||
require.Equal(t, []*Event{
|
||||
{CreatedAt: 26},
|
||||
{CreatedAt: 12},
|
||||
{CreatedAt: 8},
|
||||
{CreatedAt: 1},
|
||||
}, list)
|
||||
}
|
||||
|
Reference in New Issue
Block a user