You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
79 lines
1.7 KiB
79 lines
1.7 KiB
package changekeys_test
|
|
|
|
import (
|
|
"testing"
|
|
|
|
"git.aiterp.net/rpdata/api/models/changekeys"
|
|
|
|
"git.aiterp.net/rpdata/api/models"
|
|
)
|
|
|
|
func TestMany(t *testing.T) {
|
|
data := []interface{}{
|
|
models.Log{ID: "Stuff"},
|
|
[]interface{}{
|
|
models.Post{ID: "P1"},
|
|
models.Post{ID: "P2"},
|
|
models.Post{ID: "P3"},
|
|
[]interface{}{
|
|
models.Post{ID: "P4"},
|
|
models.Character{ID: "C17"},
|
|
models.Channel{Name: "#Stuff"},
|
|
},
|
|
},
|
|
models.Post{ID: "P5"},
|
|
}
|
|
|
|
expectations := []models.ChangeKey{
|
|
{Model: "Log", ID: "Stuff"},
|
|
{Model: "Post", ID: "P1"},
|
|
{Model: "Post", ID: "P2"},
|
|
{Model: "Post", ID: "P3"},
|
|
{Model: "Post", ID: "P4"},
|
|
{Model: "Character", ID: "C17"},
|
|
{Model: "Channel", ID: "#Stuff"},
|
|
{Model: "Post", ID: "P5"},
|
|
}
|
|
|
|
results := changekeys.Many(data...)
|
|
|
|
if len(results) != len(expectations) {
|
|
t.Fatal("Incorrect result length")
|
|
}
|
|
|
|
for i := range expectations {
|
|
result := results[i]
|
|
expectation := expectations[i]
|
|
|
|
if result.ID != expectation.ID || result.Model != expectation.Model {
|
|
t.Errorf("Incorrect: actual(%#+v, %#+v) != expected(%#+v, %#+v)", result.Model, result.ID, expectation.Model, expectation.ID)
|
|
}
|
|
}
|
|
}
|
|
|
|
func BenchmarkMany(b *testing.B) {
|
|
data := []interface{}{
|
|
models.Log{ID: "Stuff"},
|
|
[]interface{}{
|
|
models.Post{ID: "P1"},
|
|
models.Post{ID: "P2"},
|
|
models.Post{ID: "P3"},
|
|
models.Post{ID: "P4"},
|
|
models.Post{ID: "P5"},
|
|
models.Post{ID: "P6"},
|
|
models.Post{ID: "P7"},
|
|
models.Post{ID: "P8"},
|
|
models.Post{ID: "P9"},
|
|
models.Post{ID: "P10"},
|
|
models.Post{ID: "P11"},
|
|
},
|
|
models.Character{ID: "C17"},
|
|
models.Channel{Name: "#Stuff"},
|
|
}
|
|
|
|
b.ResetTimer()
|
|
|
|
for n := 0; n < b.N; n++ {
|
|
changekeys.Many(data...)
|
|
}
|
|
}
|