app_test.go 951 B

12345678910111213141516171819202122232425262728293031323334
  1. package main
  2. import (
  3. "testing"
  4. )
  5. type testCase struct {
  6. text string
  7. count int
  8. }
  9. func TestDecodeEncode(t *testing.T) {
  10. testCases := []testCase{
  11. {"This is a long looong test sentence,\nwith some big (biiiiig) words!", 8},
  12. {"Pre-translation generally means applying the TM(s) to one or more files as whole instead of moving segment by segment.", 11},
  13. }
  14. for _, item := range testCases {
  15. encoded := EncodeText(item.text)
  16. if encoded.text == item.text {
  17. t.Errorf("Encoded text '%s' should be different than provided text '%s'!", encoded.text, item.text)
  18. }
  19. count := len(encoded.encodedWords)
  20. if count != item.count {
  21. t.Errorf("There should be %d encoded words instead of %d! %v", item.count, count, encoded.encodedWords)
  22. }
  23. decodedText := DecodeText(encoded.text, encoded.encodedWords)
  24. if decodedText != item.text {
  25. t.Errorf("Decoded text '%s' should be same as provided text '%s'!", decodedText, item.text)
  26. }
  27. }
  28. }