File tree Expand file tree Collapse file tree 2 files changed +19
-1
lines changed
main/java/com/thealgorithms/datastructures/caches
test/java/com/thealgorithms/datastructures/caches Expand file tree Collapse file tree 2 files changed +19
-1
lines changed Original file line number Diff line number Diff line change @@ -101,7 +101,7 @@ private void addNodeWithUpdatedFrequency(Node node) {
101
101
node .next = temp ;
102
102
node .previous = temp .previous ;
103
103
temp .previous .next = node ;
104
- node .previous = temp . previous ;
104
+ temp .previous = node ;
105
105
break ;
106
106
}
107
107
} else {
Original file line number Diff line number Diff line change @@ -61,4 +61,22 @@ void testLFUCacheWithStringValueShouldPass() {
61
61
assertEquals (null , lfuCache .get (2 ));
62
62
assertEquals ("Zeta" , lfuCache .get (7 ));
63
63
}
64
+
65
+ /**
66
+ * test addNodeWithUpdatedFrequency method
67
+ * @author yuluo
68
+ */
69
+ @ Test
70
+ void testAddNodeWithUpdatedFrequency () {
71
+ LFUCache <Integer , String > lfuCache = new LFUCache <>(3 );
72
+ lfuCache .put (1 , "beijing" );
73
+ lfuCache .put (2 , "shanghai" );
74
+ lfuCache .put (3 , "gansu" );
75
+
76
+ assertEquals ("beijing" , lfuCache .get (1 ));
77
+
78
+ lfuCache .put (1 , "shanxi" );
79
+
80
+ assertEquals ("shanxi" , lfuCache .get (1 ));
81
+ }
64
82
}
You can’t perform that action at this time.
0 commit comments