def test_can_drop_outliers(self, x, y, k):
        assert sum(x) == sum(y)
        x1 = MajorityJudgement(x)
        y1 = MajorityJudgement(y)

        def drop_outliers(l, k):
            l = list(l)
            for r in [xrange(len(l)), reversed(xrange(len(l)))]:
                k2 = k
                for i in r:
                    if l[i] >= k2:
                        l[i] = l[i] - k2
                        break
                    else:
                        k2 = k2 - l[i]
                        l[i] = 0
            return l

        x2 = MajorityJudgement(drop_outliers(x, k))
        y2 = MajorityJudgement(drop_outliers(y, k))

        if x1 <= y1:
            assert x2 <= y2
        else:
            assert y2 <= x2
    def test_input_validation_integer(self):
        with pytest.raises(ValueError) as exinfo:
            MajorityJudgement([[]])
        assert re.search("integer", exinfo.value.message)

        with pytest.raises(ValueError) as exinfo:
            MajorityJudgement([-1.0])
        assert re.search("integer", exinfo.value.message)
 def test_front_loading_moves_earlier(self, x):
     for i in xrange(1, len(x)):
         
         y = list(x)
         y[i] = y[i] - 1
         if y[i] < 0:
             continue
         y[i-1] = y[i-1] + 1
         assert MajorityJudgement(y) < MajorityJudgement(x)
 def test_small_variations_order_correctly(self, x):
     xj = MajorityJudgement(x)
     xnj = naive_majority_judgement(x)
     for v in small_variations(x):
         vj = MajorityJudgement(v)
         vnj = naive_majority_judgement(v)
         if vnj < xnj: assert vj < xj
         elif vnj > xnj: assert vj > xj
         else: assert vj == xj
 def test_not_less_than_self(self, x):
     assert MajorityJudgement(x) >= MajorityJudgement(x)
 def test_puts_pairs_in_correct_order(self, x, y):
     assert MajorityJudgement(x) < MajorityJudgement(y)
    def test_input_validation_non_negative(self):
        with pytest.raises(ValueError) as exinfo:
            MajorityJudgement([-1, 2])

        assert re.search("negative", exinfo.value.message)
 def test_greater_equal_same_input(self,x):
     x = MajorityJudgement(x)
     assert x >= x
 def test_empty_behaviour(self):
     assert MajorityJudgement([]) == MajorityJudgement([])
     assert MajorityJudgement([]) >= MajorityJudgement([])
     assert MajorityJudgement([]) < MajorityJudgement([1])
     assert MajorityJudgement([1]) > MajorityJudgement([])
 def test_sorts_all_small_examples_like_naive_version(self, ev):
     ev = [(naive_majority_judgement(x), x) for x in ev]
     ev.sort()
     for i in xrange(0, len(ev) - 1):
         assert MajorityJudgement(ev[i][1]) < MajorityJudgement(ev[i+1][1])
    def test_sorts_like_corresponding_lists(self, ev):
        blah = [ (i, MajorityJudgement(x), 
                 naive_majority_judgement(x)) 
                 for i, x in zip(range(len(ev)),ev)]

        assert sorted(blah,key=operator.itemgetter(1)) == sorted(blah,key=operator.itemgetter(2))
 def test_repr_does_not_error(self, x):
     x = MajorityJudgement(x)
     repr(x)
 def test_equality_of_same_input(self, x):
     x = MajorityJudgement(x)
     assert x == x
 def test_doubling_preserves_order(self,x,y):
     x = [2 * t for t in x]
     y = [2 * t for t in y]
     
     assert MajorityJudgement(x) < MajorityJudgement(y)
 def test_single_upvote_determines_result(self, k, m, n):
     assert (MajorityJudgement(self.build_single_upvote(k, n)) >
             MajorityJudgement(self.build_single_upvote(k, m)))
 def test_equality_of_identical_inputs(self, x):
     assert MajorityJudgement(x) == MajorityJudgement(x)
 def test_anti_symmetry_of__compare(self, x, y):
     assert (MajorityJudgement(x)._compare(MajorityJudgement(y)) ==
             -MajorityJudgement(y)._compare(MajorityJudgement(x)))
 def test_inequality_of_different_inputs(self, x, y):
     assert MajorityJudgement(x) != MajorityJudgement(y)
 def test_greater_equal_identical_inputs(self, x):
     assert MajorityJudgement(x) >= MajorityJudgement(x)