utils_test.go 576 B

12345678910111213141516171819202122232425262728
  1. package utils
  2. import (
  3. "testing"
  4. )
  5. func TestGetHashtagsFromText(t *testing.T) {
  6. text := `Some text with a #hashtag goes here.\n\n
  7. Another #secondhashtag, goes here.\n\n
  8. #thirdhashtag`
  9. hashtags := GetHashtagsFromText(text)
  10. if hashtags[0] != "#hashtag" || hashtags[1] != "#secondhashtag" || hashtags[2] != "#thirdhashtag" {
  11. t.Error("Incorrect hashtags fetched from text.")
  12. }
  13. }
  14. func TestPercentageUtilsTest(t *testing.T) {
  15. total := 42
  16. number := 18
  17. percent := IntPercentage(number, total)
  18. if percent != 42 {
  19. t.Error("Incorrect percentage calculation.")
  20. }
  21. }