def testAddedItemsAreSorted1(self): a = [3, 2, 4, 1, 5] s = MedianFinder() for i in range(1, len(a) + 1): s.addItem(a[i - 1]) m = a[0:i] self.assertEquals(sorted(m), s.items)
def testItemsSortedAfterRemoval1(self): a = [3, 2, 4, 1, 5] s = MedianFinder() for i in a: s.addItem(i) for i in range(1, len(a) + 1): s.remItem(a[i - 1]) m = a[i: len(a)] self.assertEquals(sorted(m),s.items)
def testInput01(self): x = "C:/xampp/htdocs/PracticeCodePy/testInputs/medianInputs/Input01.txt" data = open(x) N = data.readline(); s = MedianFinder() for i in range(int(N)): Q = data.readline().split(" ") num = int(Q[1]) if(Q[0] == "a"): print(s.addItem(num)) elif(Q[0] == "r"): print(s.remItem(num))
def testMedianOnRemoval(self): a = [-3, -2, -4, -1, -5] aMedian = [-3, -4, -3, -5, "Wrong!"] s = MedianFinder() self.assertEquals("Wrong!", s.remItem(a[0])) for i in a: s.addItem(i) for i in range(1, len(a) + 1): self.assertEquals(aMedian[i - 1], s.remItem(a[i - 1]))
def testMedianOnAdd(self): a = [3, 2, 4, 1, 5] aMedian = [3, 2.5, 3, 2.5, 3] s = MedianFinder() for i in range(1, len(a) + 1): self.assertEquals(aMedian[i - 1], s.addItem(a[i - 1]))
def testRemoveItemNotInMedianFinder(self): a = [3, 2, 4, 1, 5] s = MedianFinder() for i in a: s.addItem(i) self.assertEquals(s.remItem(10), "Wrong!")
def testRemoveFromEmptyMedianFinder(self): s = MedianFinder() self.assertEquals(s.remItem(4), "Wrong!")
from median import MedianFinder import numpy as np obj = MedianFinder() for i in np.random.randint(-10, 10, 7): obj.addNum(i) median = obj.findMedian() print('#---------------------------------') print(f'Median :: {median}\nFull array :: {obj.data}\n')
def test_first(self): obj = MedianFinder() obj.addNum(1) obj.addNum(2) self.assertEqual(obj.findMedian(), 1.5)
def test_second(self): obj = MedianFinder() obj.addNum(1) obj.addNum(2) obj.addNum(3) self.assertEqual(obj.findMedian(), 2)