test_englishcorpus.py 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637
  1. from django.test import TestCase
  2. from ..englishcorpus import EnglishCorpus
  3. class EnglishCorpusTests(TestCase):
  4. def test_corpus_has_length(self):
  5. """corpus returns length"""
  6. corpus = EnglishCorpus()
  7. self.assertTrue(len(corpus))
  8. def test_corpus_can_be_shuffled(self):
  9. """corpus returns length"""
  10. corpus = EnglishCorpus()
  11. corpus.shuffle()
  12. def test_shorter_than_100(self):
  13. """corpus returns phrases shorter than 100"""
  14. corpus = EnglishCorpus(max_length=100)
  15. self.assertTrue(len(corpus))
  16. def test_longer_than_150(self):
  17. """corpus returns phrases longer than 150"""
  18. corpus = EnglishCorpus(min_length=100)
  19. self.assertTrue(len(corpus))
  20. def test_random_choice(self):
  21. """corpus random choice renturns non-repeatable choices"""
  22. corpus = EnglishCorpus()
  23. choices = [corpus.random_choice() for _ in range(2)]
  24. self.assertEqual(len(choices), len(set(choices)))
  25. def test_random_sentences(self):
  26. """corpus random_sentences returns x random sentences"""
  27. corpus = EnglishCorpus()
  28. self.assertEqual(len(corpus.random_sentences(5)), 5)