Example #1
0
 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)
Example #2
0
 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)
Example #3
0
 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))
Example #4
0
    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]))
Example #5
0
 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]))                              
Example #6
0
 def testRemoveItemNotInMedianFinder(self):
     a = [3, 2, 4, 1, 5]
     s = MedianFinder()
     for i in a:
         s.addItem(i)
     self.assertEquals(s.remItem(10), "Wrong!")
Example #7
0
 def testRemoveFromEmptyMedianFinder(self):
     s = MedianFinder()
     self.assertEquals(s.remItem(4), "Wrong!")
Example #8
0
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')
Example #9
0
 def test_first(self):
     obj = MedianFinder()
     obj.addNum(1)
     obj.addNum(2)
     self.assertEqual(obj.findMedian(), 1.5)
Example #10
0
 def test_second(self):
     obj = MedianFinder()
     obj.addNum(1)
     obj.addNum(2)
     obj.addNum(3)
     self.assertEqual(obj.findMedian(), 2)