def test_string(self): t3 = App(5) self.assertEqual(t3.getTopK(), []) t3.offer("Apple") t3.offer("candy") t3.offer("banana") self.assertEqual(t3.getTopK(), ["candy", "banana", "Apple"]) t3.offer("orange") t3.offer("pineapple") self.assertEqual(t3.getTopK(), ["pineapple", "orange", "candy", "banana", "Apple"]) t3.offer("watermelon") self.assertEqual(t3.getTopK(), ["watermelon", "pineapple", "orange", "candy", "banana"])
def test_Int(self): # test for string of length 4 t1 = App(4) # should be empty self.assertEqual(t1.getTopK(), []) t1.offer(15) t1.offer(18) t1.offer(3) self.assertEqual(t1.getTopK(), [18, 15, 3]) t1.offer(55) self.assertEqual(t1.getTopK(), [55, 18, 15, 3]) t1.offer(17) # list should main the size 4 self.assertEqual(t1.getTopK(), [55, 18, 17, 15]) t1.offer(1) self.assertEqual(t1.getTopK(), [55, 18, 17, 15])
def test_Double(self): # test for string of length 3 t2 = App(3) # should be empty self.assertEqual(t2.getTopK(), []) t2.offer(15.2) t2.offer(1.3) t2.offer(6.7) self.assertEqual(t2.getTopK(), [15.2, 6.7, 1.3]) t2.offer(55) self.assertEqual(t2.getTopK(), [55.0, 15.2, 6.7]) t2.offer(17.2) # list should main the size 3 self.assertEqual(t2.getTopK(), [55.0, 17.2, 15.2]) t2.offer(1) self.assertEqual(t2.getTopK(), [55.0, 17.2, 15.2])