コード例 #1
0
 def test_hh_export(self):
     """test exporting a heavy hitters sketch"""
     md5_val = "fb1c39dd1a73f1ef0d7fc79f60fc028e"
     with NamedTemporaryFile(dir=os.getcwd(), suffix=".cms", delete=DELETE_TEMP_FILES) as fobj:
         hh1 = HeavyHitters(num_hitters=1000, width=1000, depth=5)
         hh1.add("this is a test", 100)
         hh1.export(fobj.name)
         md5_out = calc_file_md5(fobj.name)
     self.assertEqual(md5_out, md5_val)
コード例 #2
0
    def test_hh_export(self):
        ''' test exporting a heavy hitters sketch '''
        md5_val = '61d2ea9d0cb09b7bb284e1cf1a860449'
        filename = 'test.cms'
        hh1 = HeavyHitters(num_hitters=1000, width=1000, depth=5)
        hh1.add('this is a test', 100)
        hh1.export(filename)
        md5_out = calc_file_md5(filename)
        os.remove(filename)

        self.assertEqual(md5_out, md5_val)
コード例 #3
0
    def test_hh_export(self):
        ''' test exporting a heavy hitters sketch '''
        md5_val = '61d2ea9d0cb09b7bb284e1cf1a860449'
        filename = 'test.cms'
        hh1 = HeavyHitters(num_hitters=1000, width=1000, depth=5)
        hh1.add('this is a test', 100)
        hh1.export(filename)
        md5_out = calc_file_md5(filename)
        os.remove(filename)

        self.assertEqual(md5_out, md5_val)
コード例 #4
0
    def test_hh_load(self):
        """test loading a heavy hitters from file"""
        md5_val = "fb1c39dd1a73f1ef0d7fc79f60fc028e"
        with NamedTemporaryFile(dir=os.getcwd(), suffix=".cms", delete=DELETE_TEMP_FILES) as fobj:
            hh1 = HeavyHitters(num_hitters=1000, width=1000, depth=5)
            self.assertEqual(hh1.add("this is a test", 100), 100)
            self.assertEqual(hh1.elements_added, 100)
            self.assertEqual(hh1.heavy_hitters, {"this is a test": 100})
            hh1.export(fobj.name)
            md5_out = calc_file_md5(fobj.name)
            self.assertEqual(md5_out, md5_val)

            # try loading directly to file!
            hh2 = HeavyHitters(num_hitters=1000, filepath=fobj.name)
            self.assertEqual(hh2.width, 1000)
            self.assertEqual(hh2.depth, 5)
            self.assertEqual(hh2.elements_added, 100)
            self.assertEqual(hh2.check("this is a test"), 100)
            # show on load that the tracking of heavy hitters is gone
            self.assertEqual(hh2.heavy_hitters, dict())
            self.assertEqual(hh2.add("this is a test", 1), 101)
            self.assertEqual(hh2.heavy_hitters, {"this is a test": 101})
コード例 #5
0
    def test_hh_load(self):
        ''' test loading a heavy hitters from file '''
        md5_val = '61d2ea9d0cb09b7bb284e1cf1a860449'
        filename = 'test.cms'
        hh1 = HeavyHitters(num_hitters=1000, width=1000, depth=5)
        self.assertEqual(hh1.add('this is a test', 100), 100)
        self.assertEqual(hh1.elements_added, 100)
        self.assertEqual(hh1.heavy_hitters, {'this is a test': 100})
        hh1.export(filename)
        md5_out = calc_file_md5(filename)
        self.assertEqual(md5_out, md5_val)

        # try loading directly to file!
        hh2 = HeavyHitters(num_hitters=1000, filepath=filename)
        self.assertEqual(hh2.width, 1000)
        self.assertEqual(hh2.depth, 5)
        self.assertEqual(hh2.elements_added, 100)
        self.assertEqual(hh2.check('this is a test'), 100)
        # show on load that the tracking of heavy hitters is gone
        self.assertEqual(hh2.heavy_hitters, dict())
        self.assertEqual(hh2.add('this is a test', 1), 101)
        self.assertEqual(hh2.heavy_hitters, {'this is a test': 101})
        os.remove(filename)
コード例 #6
0
    def test_hh_load(self):
        ''' test loading a heavy hitters from file '''
        md5_val = '61d2ea9d0cb09b7bb284e1cf1a860449'
        filename = 'test.cms'
        hh1 = HeavyHitters(num_hitters=1000, width=1000, depth=5)
        self.assertEqual(hh1.add('this is a test', 100), 100)
        self.assertEqual(hh1.elements_added, 100)
        self.assertEqual(hh1.heavy_hitters, {'this is a test': 100})
        hh1.export(filename)
        md5_out = calc_file_md5(filename)
        self.assertEqual(md5_out, md5_val)

        # try loading directly to file!
        hh2 = HeavyHitters(num_hitters=1000, filepath=filename)
        self.assertEqual(hh2.width, 1000)
        self.assertEqual(hh2.depth, 5)
        self.assertEqual(hh2.elements_added, 100)
        self.assertEqual(hh2.check('this is a test'), 100)
        # show on load that the tracking of heavy hitters is gone
        self.assertEqual(hh2.heavy_hitters, dict())
        self.assertEqual(hh2.add('this is a test', 1), 101)
        self.assertEqual(hh2.heavy_hitters, {'this is a test': 101})
        os.remove(filename)