예제 #1
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')
예제 #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
 def testGetUnknowWordWithDefaultValueShouldReturnDefault(self):
     t = Trie()
     self.assertEqual(t.get('python', 'default'), 'default')
예제 #4
0
 def testGetUnknowWordWithoutDefaultValueShouldRaiseException(self):
     t = Trie()
     with self.assertRaises(KeyError):
         t.get('python')
예제 #5
0
 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')