GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — do these new results make sense? · benthomasson/deepdiff@40bce63

File tree

Expand file treeCollapse file tree
Open diff view settings
Filter options
  • deepdiff
    • lfucache.py
  • tests
    • test_lfucache.py
Expand file treeCollapse file tree
Open diff view settings
Collapse file

‎deepdiff/lfucache.py‎

Copy file name to clipboardExpand all lines: deepdiff/lfucache.py
+4Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
from collections import defaultdict
88
from ordered_set import OrderedSet
99
from threading import Lock
10+
from statistics import mean
1011
from deepdiff.helper import not_found, dict_
1112

1213

@@ -201,6 +202,9 @@ def get_sorted_cache_keys(self):
201202
result.sort(key=lambda x: -x[1])
202203
return result
203204

205+
def get_average_frequency(self):
206+
return mean(freq.freq_node.freq for freq in self.cache.values())
207+
204208

205209
class DummyLFU:
206210

Collapse file

‎tests/test_lfucache.py‎

Copy file name to clipboardExpand all lines: tests/test_lfucache.py
+7-5Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,19 +6,21 @@
66

77
class TestLFUcache:
88

9-
@pytest.mark.parametrize("items, size, expected_results", [
10-
(['a', 'a', 'b', 'a', 'c', 'b', 'd'], 3, [('b', 2), ('c', 1), ('d', 1)]),
11-
(['a', 'a', 'b', 'a', 'c', 'b', 'd', 'e', 'c', 'b'], 3, [('b', 3), ('d', 1), ('e', 1)]),
12-
(['a', 'a', 'b', 'a', 'c', 'b', 'd', 'e', 'c', 'b', 'b', 'c', 'd', 'b'], 3, [('b', 5), ('c', 3), ('d', 2)]),
9+
@pytest.mark.parametrize("items, size, expected_results, expected_freq", [
10+
(['a', 'a', 'b', 'a', 'c', 'b', 'd'], 3, [('b', 2), ('c', 1), ('d', 1)], '1.333'),
11+
(['a', 'a', 'b', 'a', 'c', 'b', 'd', 'e', 'c', 'b'], 3, [('b', 3), ('d', 1), ('e', 1)], '1.666'),
12+
(['a', 'a', 'b', 'a', 'c', 'b', 'd', 'e', 'c', 'b', 'b', 'c', 'd', 'b'], 3, [('b', 5), ('c', 3), ('d', 2)], '3.333'),
1313
])
14-
def test_lfu(self, items, size, expected_results):
14+
def test_lfu(self, items, size, expected_results, expected_freq):
1515
lfucache = LFUCache(size)
1616
for item in items:
1717
lfucache.set(item, value='{}_cached'.format(item))
1818
for item in items:
1919
lfucache.get(item)
2020
results = lfucache.get_sorted_cache_keys()
2121
assert expected_results == results
22+
freq = lfucache.get_average_frequency()
23+
assert expected_freq == str(freq)[:5]
2224

2325
def test_get_multithreading(self):
2426
keys = 'aaaaaaaaaaaaaaaaaaaaaaaaaaabbc'

0 commit comments

Comments
0 (0)
You are visitor 01402792 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.