Exemplo n.º 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')
Exemplo n.º 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')
Exemplo n.º 3
0
 def testGetUnknowWordWithDefaultValueShouldReturnDefault(self):
     t = Trie()
     self.assertEqual(t.get('python', 'default'), 'default')
Exemplo n.º 4
0
 def testGetUnknowWordWithoutDefaultValueShouldRaiseException(self):
     t = Trie()
     with self.assertRaises(KeyError):
         t.get('python')
Exemplo n.º 5
0
 def testAddedWordShouldBeCountedAndAvailableForRetrieval(self):
     t = Trie()
     t.add_word('python', 'value')
     self.assertEqual(len(t), 1)
     self.assertEqual(t.get('python'), 'value')
Exemplo n.º 6
0
	def testGetUnknowWordWithDefaultValueShouldReturnDefault(self):
		t = Trie()
		self.assertEqual(t.get('python', 'default'), 'default')
Exemplo n.º 7
0
	def testGetUnknowWordWithoutDefaultValueShouldRaiseException(self):
		t = Trie()
		with self.assertRaises(KeyError):
			t.get('python')
Exemplo n.º 8
0
	def testAddedWordShouldBeCountedAndAvailableForRetrieval(self):
		t = Trie()
		t.add_word('python', 'value')
		self.assertEqual(len(t), 1)
		self.assertEqual(t.get('python'), 'value')