Format code with prettier (#3375)

This commit is contained in:
acbin
2022-10-03 17:23:00 +08:00
committed by GitHub
parent 32b9b11ed5
commit e96f567bfc
464 changed files with 11483 additions and 6189 deletions

View File

@ -6,62 +6,59 @@ import org.junit.jupiter.api.Test;
class LFUCacheTest {
@Test
void testLFUCacheWithIntegerValueShouldPass() {
@Test
void testLFUCacheWithIntegerValueShouldPass() {
LFUCache<Integer, Integer> lfuCache = new LFUCache<>(5);
lfuCache.put(1, 10);
lfuCache.put(2, 20);
lfuCache.put(3, 30);
lfuCache.put(4, 40);
lfuCache.put(5, 50);
LFUCache<Integer, Integer> lfuCache = new LFUCache<>(5);
lfuCache.put(1, 10);
lfuCache.put(2, 20);
lfuCache.put(3, 30);
lfuCache.put(4, 40);
lfuCache.put(5, 50);
//get method call will increase frequency of key 1 by 1
assertEquals(10, lfuCache.get(1));
//get method call will increase frequency of key 1 by 1
assertEquals(10, lfuCache.get(1));
//this operation will remove value with key as 2
lfuCache.put(6, 60);
//this operation will remove value with key as 2
lfuCache.put(6, 60);
//will return null as value with key 2 is now evicted
assertEquals(null, lfuCache.get(2));
//will return null as value with key 2 is now evicted
assertEquals(null, lfuCache.get(2));
//should return 60
assertEquals(60, lfuCache.get(6));
//should return 60
assertEquals(60, lfuCache.get(6));
//this operation will remove value with key as 3
lfuCache.put(7, 70);
//this operation will remove value with key as 3
lfuCache.put(7, 70);
assertEquals(null, lfuCache.get(2));
assertEquals(70, lfuCache.get(7));
}
assertEquals(null, lfuCache.get(2));
assertEquals(70, lfuCache.get(7));
}
@Test
void testLFUCacheWithStringValueShouldPass() {
LFUCache<Integer, String> lfuCache = new LFUCache<>(5);
lfuCache.put(1, "Alpha");
lfuCache.put(2, "Beta");
lfuCache.put(3, "Gamma");
lfuCache.put(4, "Delta");
lfuCache.put(5, "Eplison");
@Test
void testLFUCacheWithStringValueShouldPass() {
//get method call will increase frequency of key 1 by 1
assertEquals("Alpha", lfuCache.get(1));
LFUCache<Integer, String> lfuCache = new LFUCache<>(5);
lfuCache.put(1, "Alpha");
lfuCache.put(2, "Beta");
lfuCache.put(3, "Gamma");
lfuCache.put(4, "Delta");
lfuCache.put(5, "Eplison");
//this operation will remove value with key as 2
lfuCache.put(6, "Digamma");
//get method call will increase frequency of key 1 by 1
assertEquals("Alpha", lfuCache.get(1));
//will return null as value with key 2 is now evicted
assertEquals(null, lfuCache.get(2));
//this operation will remove value with key as 2
lfuCache.put(6, "Digamma");
//should return string Digamma
assertEquals("Digamma", lfuCache.get(6));
//will return null as value with key 2 is now evicted
assertEquals(null, lfuCache.get(2));
//should return string Digamma
assertEquals("Digamma", lfuCache.get(6));
//this operation will remove value with key as 3
lfuCache.put(7, "Zeta");
assertEquals(null, lfuCache.get(2));
assertEquals("Zeta", lfuCache.get(7));
}
//this operation will remove value with key as 3
lfuCache.put(7, "Zeta");
assertEquals(null, lfuCache.get(2));
assertEquals("Zeta", lfuCache.get(7));
}
}

View File

@ -13,11 +13,11 @@ public class LRUCacheTest {
public void putAndGetIntegerValues() {
LRUCache<Integer, Integer> lruCache = new LRUCache<>(SIZE);
for(int i = 0; i < SIZE; i++) {
for (int i = 0; i < SIZE; i++) {
lruCache.put(i, i);
}
for(int i = 0; i < SIZE; i++) {
for (int i = 0; i < SIZE; i++) {
assertEquals(i, lruCache.get(i));
}
}
@ -26,11 +26,11 @@ public class LRUCacheTest {
public void putAndGetStringValues() {
LRUCache<String, String> lruCache = new LRUCache<>(SIZE);
for(int i = 0; i < SIZE; i++) {
for (int i = 0; i < SIZE; i++) {
lruCache.put("key" + i, "value" + i);
}
for(int i = 0; i < SIZE; i++) {
for (int i = 0; i < SIZE; i++) {
assertEquals("value" + i, lruCache.get("key" + i));
}
}
@ -49,7 +49,7 @@ public class LRUCacheTest {
public void overCapacity() {
LRUCache<Integer, Integer> mruCache = new LRUCache<>(SIZE);
for(int i = 0; i < 10; i++) {
for (int i = 0; i < 10; i++) {
mruCache.put(i, i);
}

View File

@ -1,10 +1,10 @@
package com.thealgorithms.datastructures.caches;
import org.junit.jupiter.api.Test;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNull;
import org.junit.jupiter.api.Test;
public class MRUCacheTest {
private static final int SIZE = 5;
@ -13,11 +13,11 @@ public class MRUCacheTest {
public void putAndGetIntegerValues() {
MRUCache<Integer, Integer> lruCache = new MRUCache<>(SIZE);
for(int i = 0; i < SIZE; i++) {
for (int i = 0; i < SIZE; i++) {
lruCache.put(i, i);
}
for(int i = 0; i < SIZE; i++) {
for (int i = 0; i < SIZE; i++) {
assertEquals(i, lruCache.get(i));
}
}
@ -26,11 +26,11 @@ public class MRUCacheTest {
public void putAndGetStringValues() {
MRUCache<String, String> lruCache = new MRUCache<>(SIZE);
for(int i = 0; i < SIZE; i++) {
for (int i = 0; i < SIZE; i++) {
lruCache.put("key" + i, "value" + i);
}
for(int i = 0; i < SIZE; i++) {
for (int i = 0; i < SIZE; i++) {
assertEquals("value" + i, lruCache.get("key" + i));
}
}
@ -49,7 +49,7 @@ public class MRUCacheTest {
public void overCapacity() {
MRUCache<Integer, Integer> mruCache = new MRUCache<>(SIZE);
for(int i = 0; i < 10; i++) {
for (int i = 0; i < 10; i++) {
mruCache.put(i, i);
}