Esempio n. 1
0
func TestInt64SliceMap(t *testing.T) {
	af := func(i int64) int64 {
		return i + 1
	}
	l := util.Int64Slice{2, 4, 30, 22}
	assert.EqualValues(t, []int64{3, 5, 31, 23}, l.Map(af).ToInt64())
}
Esempio n. 2
0
func TestInt64SliceAny(t *testing.T) {
	l := util.Int64Slice{33, 44, 55, 66}
	assert.True(t, l.Any(func(i int64) bool {
		return i == 44
	}))
	assert.False(t, l.Any(func(i int64) bool {
		return i == 77
	}))
}
Esempio n. 3
0
// IDs returns an Int64Slice with all store ids
func (s GroupSlice) IDs() util.Int64Slice {
	if len(s) == 0 {
		return nil
	}
	var ids util.Int64Slice
	for _, g := range s {
		if g != nil {
			ids.Append(g.Data.GroupID)
		}
	}
	return ids
}
Esempio n. 4
0
// IDs returns an Int64Slice with all store ids
func (ss StoreSlice) IDs() util.Int64Slice {
	if len(ss) == 0 {
		return nil
	}
	var ids util.Int64Slice
	for _, st := range ss {
		if st != nil {
			ids.Append(st.Data.StoreID)
		}
	}
	return ids
}
Esempio n. 5
0
// IDs returns an Int64Slice with all website ids
func (ws WebsiteSlice) IDs() util.Int64Slice {
	if len(ws) == 0 {
		return nil
	}
	var ids util.Int64Slice
	for _, w := range ws {
		if w != nil {
			ids.Append(w.Data.WebsiteID)
		}
	}
	return ids
}
Esempio n. 6
0
// findHandlerByID returns the Handler for the searchID. If not found
// or slices have an indifferent length or something is nil it will
// return the DefaultErrorHandler.
func findHandlerByID(so scope.Scope, id int64, idsIdx util.Int64Slice, handlers []ctxhttp.HandlerFunc) ctxhttp.HandlerFunc {

	if len(idsIdx) != len(handlers) {
		return DefaultAlternativeHandler
	}
	index := idsIdx.Index(id)
	if index < 0 {
		return DefaultAlternativeHandler
	}
	prospect := handlers[index]
	if nil == prospect {
		return DefaultAlternativeHandler
	}

	if PkgLog.IsInfo() {
		PkgLog.Info("geoip.findHandlerByID.found", "scope", so.String(), "id", id, "idsIdx", idsIdx)
	}
	return prospect
}
Esempio n. 7
0
func TestInt64SliceReduce(t *testing.T) {
	af := func(i int64) bool {
		return (i & 1) == 1
	}
	l := util.Int64Slice{2, 4, 30, 22}
	assert.EqualValues(t, []int64{}, l.Reduce(af).ToInt64())
	l.Append(3, 5)
	assert.EqualValues(t, []int64{3, 5}, l.Reduce(af).ToInt64())
}
Esempio n. 8
0
func TestInt64SliceAll(t *testing.T) {
	af := func(i int64) bool {
		return (i & 1) == 0
	}
	l := util.Int64Slice{2, 4, 30, 22}
	assert.True(t, l.All(af))
	l.Append(11)
	assert.False(t, l.All(af))
}
Esempio n. 9
0
func TestInt64SliceSum(t *testing.T) {
	l := util.Int64Slice{2, 4, 30, 22}
	assert.EqualValues(t, 58, l.Sum())
}
Esempio n. 10
0
func TestInt64SliceInclude(t *testing.T) {
	is := util.Int64Slice{-29, 30, -1}
	assert.True(t, is.Include(-1))
	assert.False(t, is.Include(-100))
}
Esempio n. 11
0
func TestInt64SliceIndex(t *testing.T) {
	is := util.Int64Slice{-29, 30, -1}
	assert.EqualValues(t, 2, is.Index(-1))
	assert.EqualValues(t, -1, is.Index(123))
}
Esempio n. 12
0
func TestInt64SliceDelete(t *testing.T) {
	is := util.Int64Slice{-29, 30, -1}
	assert.NoError(t, is.Delete(1))
	assert.EqualValues(t, []int64{-29, -1}, is.ToInt64())
	assert.EqualError(t, util.ErrOutOfRange, is.Delete(100).Error())
}
Esempio n. 13
0
func TestInt64SliceUpdate(t *testing.T) {
	is := util.Int64Slice{-29, 30, -1}
	assert.NoError(t, is.Update(1, 31))
	assert.EqualValues(t, 31, is[1])
	assert.EqualError(t, util.ErrOutOfRange, is.Update(100, 2).Error())
}
Esempio n. 14
0
func TestInt64SliceAppend(t *testing.T) {
	is := util.Int64Slice{30, -1}
	is.Append(6)
	assert.EqualValues(t, []int64{30, -1, 6}, is.ToInt64())
}
Esempio n. 15
0
func TestInt64SliceSort(t *testing.T) {
	is := util.Int64Slice{100, 10, 3, 20, 9, 30, -1}
	assert.EqualValues(t, []int64{-1, 3, 9, 10, 20, 30, 100}, is.Sort().ToInt64())
	assert.EqualValues(t, []int64{100, 30, 20, 10, 9, 3, -1}, is.Reverse().ToInt64())
}
Esempio n. 16
0
func TestInt64SliceUnique(t *testing.T) {
	l := util.Int64Slice{30, 2, 4, 30, 2, 22}
	assert.EqualValues(t, []int64{30, 2, 4, 22}, l.Unique().ToInt64())
}