Skip to content

Commit

Permalink
Merge pull request #87 from c-bata/fix-trial-number
Browse files Browse the repository at this point in the history
Fix trial number on RDB storage
  • Loading branch information
c-bata authored Mar 11, 2020
2 parents 59b071f + 4a06fc7 commit 5bad401
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 5 deletions.
1 change: 1 addition & 0 deletions rdb/storage.go
Original file line number Diff line number Diff line change
Expand Up @@ -227,6 +227,7 @@ func (s *Storage) CreateNewTrial(studyID int) (int, error) {
var number int
err := tx.Model(&trialModel{}).
Where("study_id = ?", studyID).
Where("trial_id < ?", trial.ID).
Count(&number).Error
if err != nil {
tx.Rollback()
Expand Down
10 changes: 5 additions & 5 deletions rdb/storage_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -541,7 +541,7 @@ func TestStorage_GetBestTrial(t *testing.T) {
t.Errorf("error: %v != nil", err)
return
}
// trial number 1 (not completed yet)
// trial number 0 (not completed yet)
trialID, err := storage.CreateNewTrial(studyID)
if err != nil {
t.Errorf("error: %v != nil", err)
Expand All @@ -553,7 +553,7 @@ func TestStorage_GetBestTrial(t *testing.T) {
return
}

// trial number 2
// trial number 1
trialID, err = storage.CreateNewTrial(studyID)
if err != nil {
t.Errorf("error: %v != nil", err)
Expand All @@ -570,7 +570,7 @@ func TestStorage_GetBestTrial(t *testing.T) {
return
}

// trial number 3
// trial number 2
trialID, err = storage.CreateNewTrial(studyID)
if err != nil {
t.Errorf("error: %v != nil", err)
Expand All @@ -592,8 +592,8 @@ func TestStorage_GetBestTrial(t *testing.T) {
t.Errorf("error: %v != nil", err)
return
}
if bestTrial.Value == 0.2 && bestTrial.Number != 3 {
t.Errorf("want Trial(Value=0.2, Number: 3), but got %#v", bestTrial)
if bestTrial.Value == 0.2 && bestTrial.Number != 2 {
t.Errorf("want Trial(Value=0.2, Number: 2), but got %#v", bestTrial)
}
}

Expand Down

0 comments on commit 5bad401

Please sign in to comment.