-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
99 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
package converter | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/stretchr/testify/assert" | ||
|
||
"jcourse_go/model/model" | ||
) | ||
|
||
func TestRemoveReviewUserInfo(t *testing.T) { | ||
hides := []bool{true, false, true, false} | ||
expected := []int64{0, 1, 1, 1} | ||
user := model.UserMinimal{ID: 1} | ||
reviews := []model.Review{{ | ||
User: user, | ||
IsAnonymous: true, | ||
}, { | ||
User: user, | ||
IsAnonymous: true, | ||
}, { | ||
User: user, | ||
IsAnonymous: false, | ||
}, { | ||
User: user, | ||
IsAnonymous: false, | ||
}} | ||
for i := range reviews { | ||
r := reviews[i] | ||
hide := hides[i] | ||
RemoveReviewUserInfo(&r, hide) | ||
assert.Equal(t, expected[i], r.User.ID) | ||
} | ||
} | ||
|
||
func TestRemoveReviewsUserInfo(t *testing.T) { | ||
reviews := []model.Review{{ | ||
User: model.UserMinimal{ID: 1}, | ||
IsAnonymous: true, | ||
}} | ||
RemoveReviewsUserInfo(reviews, true) | ||
assert.Equal(t, int64(0), reviews[0].User.ID) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
package model | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/stretchr/testify/assert" | ||
) | ||
|
||
func TestRatingInfo_Calc(t *testing.T) { | ||
rating := &RatingInfo{ | ||
RatingDist: []RatingInfoDistItem{ | ||
{Count: 1, Rating: 1}, | ||
{Count: 2, Rating: 2}, | ||
{Count: 5, Rating: 5}, | ||
}, | ||
} | ||
rating.Calc() | ||
assert.Equal(t, int64(8), rating.Count) | ||
assert.Equal(t, 3.75, rating.Average) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
package util | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/stretchr/testify/assert" | ||
) | ||
|
||
func TestStringsToFloat64s(t *testing.T) { | ||
src := []string{"1", "2", "3", "4", "5"} | ||
dst := StringsToFloat64s(src) | ||
assert.Equal(t, len(src), len(dst)) | ||
for i := range src { | ||
assert.Equal(t, float64(i+1), dst[i]) | ||
} | ||
} |