Esempio n. 1
0
    def test_citation_histograms(self):
        '''Test getting the citation histograms'''
        from metrics import get_citation_histograms

        hist = get_citation_histograms(testset)

        histograms = [
            'refereed to refereed', 'refereed to nonrefereed',
            'nonrefereed to refereed', 'nonrefereed to nonrefereed',
            'refereed to refereed normalized',
            'refereed to nonrefereed normalized',
            'nonrefereed to refereed normalized',
            'nonrefereed to nonrefereed normalized'
        ]
        for histogram in histograms:
            # Get the expected values
            expected = expected_results['histograms']['citations'][histogram]
            # Make the key integer again, because JSON turned it into a string
            expected = {int(k): v for k, v in expected.items()}
            # Get the non-zero entries for the histogram we just generated
            nonzero = dict([(year, freq)
                            for year, freq in hist[histogram].items()
                            if freq != 0])
            # and compare
            self.assertEqual(nonzero, expected)
    def test_citation_histograms(self):
        '''Test getting the citation histograms'''
        from metrics import get_citation_histograms

        hist = get_citation_histograms(testset)

        histograms = ['refereed to refereed',
                      'refereed to nonrefereed',
                      'nonrefereed to refereed',
                      'nonrefereed to nonrefereed',
                      'refereed to refereed normalized',
                      'refereed to nonrefereed normalized',
                      'nonrefereed to refereed normalized',
                      'nonrefereed to nonrefereed normalized']
        for histogram in histograms:
            # Get the expected values
            expected = expected_results['histograms']['citations'][histogram]
            # Make the key integer again, because JSON turned it into a string
            expected = {int(k): v for k, v in expected.items()}
            # Get the non-zero entries for the histogram we just generated
            nonzero = dict(
                [(year, freq) for year, freq in
                 hist[histogram].items() if freq != 0])
            # and compare
            self.assertEqual(nonzero, expected)
 def test_no_refereed_citations(self):
     '''Test getting citation histograms when no refereed citations'''
     from metrics import get_citation_histograms
     years = [int(b[:4]) for b in testset]
     # Expected histogram (for all)
     expected = {year: 0 for year in range(min(years), current_year + 1)}
     # Get the reads histograms
     hist = get_citation_histograms(testset)
     histograms = ['refereed to refereed',
                   'refereed to nonrefereed',
                   'refereed to refereed normalized',
                   'refereed to nonrefereed normalized']
     for histogram in histograms:
         self.assertEqual(hist[histogram], expected)
 def test_no_refereed_citations(self):
     '''Test getting citation histograms when no refereed citations'''
     from metrics import get_citation_histograms
     years = [int(b[:4]) for b in testset]
     # Expected histogram (for all)
     expected = {year: 0 for year in range(min(years), current_year + 1)}
     # Get the reads histograms
     hist = get_citation_histograms(testset)
     histograms = [
         'refereed to refereed', 'refereed to nonrefereed',
         'refereed to refereed normalized',
         'refereed to nonrefereed normalized'
     ]
     for histogram in histograms:
         self.assertEqual(hist[histogram], expected)