old_contents: from nose.tools import assert_equal, assert_greater
  
  from otdet.evaluation import TopListEvaluator
  
  
  class TestAddResult:
      def setUp(self):
          self.sample_result = [(5.0, True), (4.0, False), (3.0, True),
                                (2.0, False), (1.0, False)]
          self.M = len(self.sample_result)
          self.n = sum(elm[1] for elm in self.sample_result)
  
      def test_normal_result(self):
          N = 2
          k = sum(elm[1] for elm in self.sample_result[:N])
          evaluator = TopListEvaluator(N)
          evaluator.add_result(self.sample_result)
          assert_equal(evaluator._M, self.M)
          assert_equal(evaluator._n, self.n)
          assert_equal(evaluator._numexpr, 1)
          assert_equal(evaluator._freq[k], 1)
  
      def test_short_result(self):
          N = 10
          k = sum(elm[1] for elm in self.sample_result[:N])
          evaluator = TopListEvaluator(N)
          evaluator.add_result(self.sample_result)
          assert_equal(evaluator._M, self.M)
          assert_equal(evaluator._n, self.n)
          assert_equal(evaluator._numexpr, 1)
          assert_equal(evaluator._freq[k], 1)
  
      def test_called_twice(self):
          N = 2
          evaluator = TopListEvaluator(N)
          evaluator.add_result(self.sample_result)
          evaluator.add_result(self.sample_result)
          assert_equal(evaluator._numexpr, 2)
          assert_greater(len(evaluator._result_list), 0)
          assert_equal(evaluator._result_list[0], self.sample_result)
  
new_contents: from nose.tools import assert_equal, assert_greater
  from numpy.testing import assert_almost_equal
  import numpy as np
  
  from otdet.evaluation import TopListEvaluator
  
  
  class TestAddResult:
      def setUp(self):
          self.sample_result = [(5.0, True), (4.0, False), (3.0, True),
                                (2.0, False), (1.0, False)]
          self.M = len(self.sample_result)
          self.n = sum(elm[1] for elm in self.sample_result)
  
      def test_normal_result(self):
          N = 2
          k = sum(elm[1] for elm in self.sample_result[:N])
          evaluator = TopListEvaluator(N)
          evaluator.add_result(self.sample_result)
          assert_equal(evaluator._M, self.M)
          assert_equal(evaluator._n, self.n)
          assert_equal(evaluator._numexpr, 1)
          assert_equal(evaluator._freq[k], 1)
  
      def test_short_result(self):
          N = 10
          k = sum(elm[1] for elm in self.sample_result[:N])
          evaluator = TopListEvaluator(N)
          evaluator.add_result(self.sample_result)
          assert_equal(evaluator._M, self.M)
          assert_equal(evaluator._n, self.n)
          assert_equal(evaluator._numexpr, 1)
          assert_equal(evaluator._freq[k], 1)
  
      def test_called_twice(self):
          N = 2
          evaluator = TopListEvaluator(N)
          evaluator.add_result(self.sample_result)
          evaluator.add_result(self.sample_result)
          assert_equal(evaluator._numexpr, 2)
          assert_greater(len(evaluator._result_list), 0)
          assert_equal(evaluator._result_list[0], self.sample_result)
  
  
  class TestBaseline:
      def setUp(self):
          self.sample_result = [(5.0, True), (4.0, False), (3.0, True),
                                (2.0, False), (1.0, False)]
          self.M = len(self.sample_result)
          self.n = sum(elm[1] for elm in self.sample_result)
  
      def test_normal_case(self):
          N = 3
          evaluator = TopListEvaluator(N)
          evaluator.add_result(self.sample_result)
          expected = np.array([0.1, 0.6, 0.3])
          assert_almost_equal(evaluator.baseline, expected)
  
      def test_top_few_list(self):
          N = 1
          evaluator = TopListEvaluator(N)
          evaluator.add_result(self.sample_result)
          expected = np.array([0.6, 0.4, 0.0])
          assert_almost_equal(evaluator.baseline, expected)
  
      def test_top_many_list(self):
          N = 4
          evaluator = TopListEvaluator(N)
          evaluator.add_result(self.sample_result)
          expected = np.array([0.0, 0.4, 0.6])
          assert_almost_equal(evaluator.baseline, expected)
  
subject: Add more tests!