Skip to content

Commit

Permalink
#481 reproduced and fixed
Browse files Browse the repository at this point in the history
  • Loading branch information
yegor256 committed Dec 1, 2017
1 parent ed0b73f commit 2e1701d
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 6 deletions.
4 changes: 2 additions & 2 deletions src/main/java/org/cactoos/func/StickyBiFunc.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
*/
package org.cactoos.func;

import java.util.HashMap;
import java.util.LinkedHashMap;
import java.util.Map;
import org.cactoos.BiFunc;
import org.cactoos.map.MapEntry;
Expand Down Expand Up @@ -81,7 +81,7 @@ public StickyBiFunc(final BiFunc<X, Y, Z> fnc) {
*/
public StickyBiFunc(final BiFunc<X, Y, Z> fnc, final int max) {
this.func = fnc;
this.cache = new HashMap<>(0);
this.cache = new LinkedHashMap<>(0);
this.size = max;
}

Expand Down
15 changes: 11 additions & 4 deletions src/test/java/org/cactoos/func/StickyFuncTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -52,12 +52,19 @@ public void cachesFuncResults() throws Exception {

@Test
public void cachesWithLimitedBuffer() throws Exception {
final Func<Boolean, Integer> func = new StickyFunc<>(
input -> new SecureRandom().nextInt(), 1
final Func<Integer, Integer> func = new StickyFunc<>(
input -> new SecureRandom().nextInt(), 2
);
final int first = func.apply(0);
final int second = func.apply(1);
MatcherAssert.assertThat(
func.apply(true) + func.apply(true),
Matchers.equalTo(func.apply(true) + func.apply(true))
first + second,
Matchers.equalTo(func.apply(0) + func.apply(1))
);
final int third = func.apply(-1);
MatcherAssert.assertThat(
second + third,
Matchers.equalTo(func.apply(1) + func.apply(-1))
);
}

Expand Down

0 comments on commit 2e1701d

Please sign in to comment.