示例#1
0
 def test_word_storage_put_existing(self):
     """existing word is not added to storage"""
     word_storage = WordStorage()
     word = 'word'
     word_storage.storage = {'word': 1}
     word_storage.put(word)
     self.assertEqual(word_storage.storage, {'word': 1})
示例#2
0
 def test_word_storage_from_corpus_duplicates(self):
     """ideal case for get_id_of"""
     word_storage = WordStorage()
     sentence = ('<s>', 'mary', 'wanted', 'to', 'to', 'swim', '</s>')
     word_storage.from_corpus(sentence)
     self.assertEqual(len(word_storage.storage), 6)
示例#3
0
 def test_word_storage_get_original_id_not_num(self):
     """ideal case for get_id_of"""
     word_storage = WordStorage()
     word_storage.storage = {'word': 1}
     self.assertEqual(word_storage.get_original_by(None), 'UNK')
示例#4
0
 def test_word_storage_get_original_by_not_in_storage(self):
     """id not in storage get_original_by"""
     word_storage = WordStorage()
     word_storage.storage = {'word': 1}
     self.assertEqual(word_storage.get_original_by(2), 'UNK')
示例#5
0
 def test_word_storage_get_original_by_ideal(self):
     """ideal case for get_original_by"""
     word_storage = WordStorage()
     word_storage.storage = {'word': 1}
     self.assertEqual(word_storage.get_original_by(1), 'word')
示例#6
0
 def test_word_storage_get_id_of_word_not_in_storage(self):
     """word not in storage"""
     word_storage = WordStorage()
     word_storage.storage = {'word': 1}
     self.assertEqual(word_storage.get_id_of('another'), -1)
示例#7
0
 def test_word_storage_get_id_of_not_str(self):
     """id is not str  get_id_of"""
     word_storage = WordStorage()
     word_storage.storage = {'word': 1}
     self.assertEqual(word_storage.get_id_of(123), -1)
示例#8
0
 def test_word_storage_get_id_of_none(self):
     """get_id_of none"""
     word_storage = WordStorage()
     word_storage.storage = {'word': 1}
     self.assertEqual(word_storage.get_id_of(None), -1)
示例#9
0
 def test_word_storage_get_id_of_ideal(self):
     """ideal case for get_id_of"""
     word_storage = WordStorage()
     word_storage.storage = {'word': 1}
     self.assertEqual(word_storage.get_id_of('word'), 1)
示例#10
0
 def test_word_storage_put_word_not_str(self):
     """non string word is not added to storage"""
     word_storage = WordStorage()
     word = 123
     word_storage.put(word)
     self.assertEqual(word_storage.storage, {})
示例#11
0
 def test_word_storage_put_word_none(self):
     """none is not added to storage"""
     word_storage = WordStorage()
     word = None
     word_storage.put(word)
     self.assertEqual(word_storage.storage, {})
示例#12
0
 def test_word_storage_put_ideal(self):
     """word is added to storage"""
     word_storage = WordStorage()
     word = 'word'
     num = word_storage.put(word)
     self.assertEqual(word_storage.storage[word], num)
示例#13
0
 def test_word_storage_from_corpus_not_tuple(self):
     """ideal case for get_id_of"""
     word_storage = WordStorage()
     sentence = 'Mary wanted to swim'
     word_storage.from_corpus(sentence)
     self.assertEqual(word_storage.storage, {})
示例#14
0
 def test_word_storage_from_corpus_none(self):
     """ideal case for get_id_of"""
     word_storage = WordStorage()
     sentence = None
     word_storage.from_corpus(sentence)
     self.assertEqual(word_storage.storage, {})