Skip to content

Commit

Permalink
Add test case for CategoricalDistribution
Browse files Browse the repository at this point in the history
  • Loading branch information
c-bata committed Jul 29, 2019
1 parent 42d147c commit 436f74a
Showing 1 changed file with 46 additions and 0 deletions.
46 changes: 46 additions & 0 deletions distribution_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,12 @@ func TestDistributionConversionBetweenDistributionAndJSON(t *testing.T) {
Low: 5,
},
},
{
name: "categorical distribution",
distribution: goptuna.CategoricalDistribution{
Choices: []string{"foo", "bar"},
},
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
Expand Down Expand Up @@ -63,6 +69,12 @@ func TestDistributionToInternalRepresentation(t *testing.T) {
args: 3,
want: 3.0,
},
{
name: "categorical distribution",
distribution: &goptuna.CategoricalDistribution{Choices: []string{"a", "b", "c"}},
args: "b",
want: 1,
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
Expand Down Expand Up @@ -92,6 +104,12 @@ func TestDistributionToExternalRepresentation(t *testing.T) {
args: 3.0,
want: 3,
},
{
name: "categorical distribution",
distribution: &goptuna.CategoricalDistribution{Choices: []string{"a", "b", "c"}},
args: 2.0,
want: "c",
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
Expand Down Expand Up @@ -128,6 +146,16 @@ func TestDistributionSingle(t *testing.T) {
distribution: &goptuna.IntUniformDistribution{Low: 0, High: 10},
want: false,
},
{
name: "categorical distribution true",
distribution: &goptuna.CategoricalDistribution{Choices: []string{"a"}},
want: true,
},
{
name: "categorical distribution false",
distribution: &goptuna.CategoricalDistribution{Choices: []string{"a", "b", "c"}},
want: false,
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
Expand Down Expand Up @@ -181,6 +209,24 @@ func TestDistributionContains(t *testing.T) {
args: 15,
want: false,
},
{
name: "categorical distribution true",
distribution: &goptuna.CategoricalDistribution{Choices: []string{"a", "b", "c"}},
args: 1,
want: true,
},
{
name: "categorical distribution lower",
distribution: &goptuna.CategoricalDistribution{Choices: []string{"a", "b", "c"}},
args: -1,
want: false,
},
{
name: "categorical distribution higher",
distribution: &goptuna.CategoricalDistribution{Choices: []string{"a", "b", "c"}},
args: 3,
want: false,
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
Expand Down

0 comments on commit 436f74a

Please sign in to comment.