-
Notifications
You must be signed in to change notification settings - Fork 16
/
Copy pathmodel_test.go
33 lines (29 loc) · 937 Bytes
/
model_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
package main
import (
"sort"
"strings"
"testing"
"github.com/stretchr/testify/assert"
)
func TestTimeSorter(t *testing.T) {
notes := []Note{
Note{Updated: "2006-01-02T15:04:05Z07:00"},
Note{Updated: "2007-01-02T15:04:05Z07:00"},
Note{Updated: "2005-01-02T15:04:05Z07:00"},
}
sort.Sort(TimeSorter(notes))
assert.True(t, strings.HasPrefix(notes[0].Updated, "2005"))
assert.True(t, strings.HasPrefix(notes[1].Updated, "2006"))
assert.True(t, strings.HasPrefix(notes[2].Updated, "2007"))
}
func TestTimeSorterReverse(t *testing.T) {
notes := []Note{
Note{Updated: "2006-01-02T15:04:05Z07:00"},
Note{Updated: "2007-01-02T15:04:05Z07:00"},
Note{Updated: "2005-01-02T15:04:05Z07:00"},
}
sort.Sort(sort.Reverse(TimeSorter(notes)))
assert.True(t, strings.HasPrefix(notes[0].Updated, "2007"))
assert.True(t, strings.HasPrefix(notes[1].Updated, "2006"))
assert.True(t, strings.HasPrefix(notes[2].Updated, "2005"))
}