Skip to content
This repository has been archived by the owner on Oct 17, 2018. It is now read-only.

Commit

Permalink
Expose the id of aggregation types
Browse files Browse the repository at this point in the history
  • Loading branch information
Chao Wang committed Jun 12, 2017
1 parent f55a389 commit 59739da
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 0 deletions.
8 changes: 8 additions & 0 deletions policy/aggregation_type.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,9 @@ const (
// The AggregationIDLen will be 1 when totalAggregationTypes <= 64.
AggregationIDLen = (totalAggregationTypes-1)/64 + 1

// MaxAggregationTypeID is the largest id of all the valid aggregation types.
MaxAggregationTypeID = totalAggregationTypes - 1

aggregationTypesSeparator = ","
)

Expand Down Expand Up @@ -122,6 +125,11 @@ func NewAggregationTypeFromSchema(input schema.AggregationType) (AggregationType
return aggType, nil
}

// ID returns the id of the AggregationType.
func (a AggregationType) ID() int {
return int(a)
}

// IsValid checks if an AggregationType is valid.
func (a AggregationType) IsValid() bool {
_, ok := ValidAggregationTypes[a]
Expand Down
5 changes: 5 additions & 0 deletions policy/aggregation_type_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,11 @@ func TestAggregationTypeIsValid(t *testing.T) {
require.False(t, AggregationType(int(P9999)+1).IsValid())
}

func TestAggregationTypeID(t *testing.T) {
require.Equal(t, MaxAggregationTypeID, P9999.ID())
require.Equal(t, P9999, AggregationType(MaxAggregationTypeID))
}

func TestAggregationTypesIsDefault(t *testing.T) {
require.True(t, DefaultAggregationTypes.IsDefault())

Expand Down

0 comments on commit 59739da

Please sign in to comment.