コード例 #1
0
ファイル: unittests.py プロジェクト: zhu/pyahocorasick
    def testAddingExistingWordShouldReplaceAssociatedValue(self):
        t = Trie()
        t.add_word('python', 'value')
        self.assertEqual(len(t), 1)
        self.assertEqual(t.get('python'), 'value')

        t.add_word('python', 'other')
        self.assertEqual(len(t), 1)
        self.assertEqual(t.get('python'), 'other')
コード例 #2
0
	def testAddingExistingWordShouldReplaceAssociatedValue(self):
		t = Trie()
		t.add_word('python', 'value')
		self.assertEqual(len(t), 1)
		self.assertEqual(t.get('python'), 'value')

		t.add_word('python', 'other')
		self.assertEqual(len(t), 1)
		self.assertEqual(t.get('python'), 'other')
コード例 #3
0
ファイル: unittests.py プロジェクト: zhu/pyahocorasick
 def testGetUnknowWordWithDefaultValueShouldReturnDefault(self):
     t = Trie()
     self.assertEqual(t.get('python', 'default'), 'default')
コード例 #4
0
ファイル: unittests.py プロジェクト: zhu/pyahocorasick
 def testGetUnknowWordWithoutDefaultValueShouldRaiseException(self):
     t = Trie()
     with self.assertRaises(KeyError):
         t.get('python')
コード例 #5
0
ファイル: unittests.py プロジェクト: zhu/pyahocorasick
 def testAddedWordShouldBeCountedAndAvailableForRetrieval(self):
     t = Trie()
     t.add_word('python', 'value')
     self.assertEqual(len(t), 1)
     self.assertEqual(t.get('python'), 'value')
コード例 #6
0
	def testGetUnknowWordWithDefaultValueShouldReturnDefault(self):
		t = Trie()
		self.assertEqual(t.get('python', 'default'), 'default')
コード例 #7
0
	def testGetUnknowWordWithoutDefaultValueShouldRaiseException(self):
		t = Trie()
		with self.assertRaises(KeyError):
			t.get('python')
コード例 #8
0
	def testAddedWordShouldBeCountedAndAvailableForRetrieval(self):
		t = Trie()
		t.add_word('python', 'value')
		self.assertEqual(len(t), 1)
		self.assertEqual(t.get('python'), 'value')