main_test.go 684 B

12345678910111213141516171819202122232425262728293031323334353637
  1. package main
  2. import (
  3. "bytes"
  4. "testing"
  5. )
  6. func TestCountWords(t *testing.T) {
  7. b := bytes.NewBufferString("hello world world2 world3 world4\n")
  8. exp := 5
  9. res := count(b, false, false)
  10. if res != exp {
  11. t.Errorf("Expected %d, got %d instead.\n", exp, res)
  12. }
  13. }
  14. func TestCountLines(t *testing.T) {
  15. b := bytes.NewBufferString("hello world world2\nworld3\nworld4\n")
  16. exp := 3
  17. res := count(b, true, false)
  18. if res != exp {
  19. t.Errorf("Expected %d, got %d instead.\n", exp, res)
  20. }
  21. }
  22. func TestCountBytes(t *testing.T) {
  23. b := bytes.NewBufferString("hello\n")
  24. exp := 6
  25. res := count(b, false, true)
  26. if res != exp {
  27. t.Errorf("Expected %d, got %d instead.\n", exp, res)
  28. }
  29. }