comment_sentiment_test.go 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. package hercules
  2. import (
  3. "testing"
  4. "github.com/stretchr/testify/assert"
  5. "gopkg.in/src-d/go-git.v4/plumbing"
  6. )
  7. func TestCommentSentimentMeta(t *testing.T) {
  8. sent := CommentSentimentAnalysis{}
  9. assert.Equal(t, sent.Name(), "Sentiment")
  10. assert.Equal(t, len(sent.Provides()), 0)
  11. required := [...]string{DependencyUastChanges, DependencyDay}
  12. for _, name := range required {
  13. assert.Contains(t, sent.Requires(), name)
  14. }
  15. opts := sent.ListConfigurationOptions()
  16. matches := 0
  17. for _, opt := range opts {
  18. switch opt.Name {
  19. case ConfigCommentSentimentMinLength, ConfigCommentSentimentGap:
  20. matches++
  21. }
  22. }
  23. assert.Len(t, opts, matches)
  24. assert.Equal(t, sent.Flag(), "sentiment")
  25. assert.Len(t, sent.Features(), 1)
  26. assert.Equal(t, sent.Features()[0], FeatureUast)
  27. }
  28. func TestCommentSentimentConfigure(t *testing.T) {
  29. sent := CommentSentimentAnalysis{}
  30. facts := map[string]interface{}{}
  31. facts[ConfigCommentSentimentMinLength] = 77
  32. facts[ConfigCommentSentimentGap] = float32(0.77)
  33. facts[FactCommitsByDay] = map[int][]plumbing.Hash{}
  34. sent.Configure(facts)
  35. assert.Equal(t, sent.Gap, float32(0.77))
  36. assert.Equal(t, sent.MinCommentLength, 77)
  37. facts[ConfigCommentSentimentMinLength] = -10
  38. facts[ConfigCommentSentimentGap] = float32(2)
  39. sent.Configure(facts)
  40. assert.Equal(t, sent.Gap, DefaultCommentSentimentGap)
  41. assert.Equal(t, sent.MinCommentLength, DefaultCommentSentimentCommentMinLength)
  42. }
  43. func TestCommentSentimentRegistration(t *testing.T) {
  44. tp, exists := Registry.registered[(&CommentSentimentAnalysis{}).Name()]
  45. assert.True(t, exists)
  46. assert.Equal(t, tp.Elem().Name(), "CommentSentimentAnalysis")
  47. tp, exists = Registry.flags[(&CommentSentimentAnalysis{}).Flag()]
  48. assert.True(t, exists)
  49. assert.Equal(t, tp.Elem().Name(), "CommentSentimentAnalysis")
  50. }