From 639633018e6aa2afe52ffebb54c77c6ce42f1b73 Mon Sep 17 00:00:00 2001 From: Alexey Andreev Date: Thu, 14 May 2015 18:11:47 +0400 Subject: [PATCH] Probably fix https://github.com/konsoletyper/teavm/issues/112 --- .../org/teavm/classlib/java/util/TTreeMap.java | 4 ++-- .../org/teavm/classlib/java/util/TreeMapTest.java | 15 +++++++++++++++ 2 files changed, 17 insertions(+), 2 deletions(-) diff --git a/teavm-classlib/src/main/java/org/teavm/classlib/java/util/TTreeMap.java b/teavm-classlib/src/main/java/org/teavm/classlib/java/util/TTreeMap.java index ef7a7263e..9263831d3 100644 --- a/teavm-classlib/src/main/java/org/teavm/classlib/java/util/TTreeMap.java +++ b/teavm-classlib/src/main/java/org/teavm/classlib/java/util/TTreeMap.java @@ -363,9 +363,9 @@ public class TTreeMap extends TAbstractMap implements TCloneable, TS while (minDepth > 0) { TreeNode node = pathToMin[--minDepth]; node.left = right; - right = node; node.fix(); - node.balance(); + node = node.balance(); + right = node; } min.right = right; min.left = left; diff --git a/teavm-tests/src/test/java/org/teavm/classlib/java/util/TreeMapTest.java b/teavm-tests/src/test/java/org/teavm/classlib/java/util/TreeMapTest.java index 995a2af6b..868df7ab8 100644 --- a/teavm-tests/src/test/java/org/teavm/classlib/java/util/TreeMapTest.java +++ b/teavm-tests/src/test/java/org/teavm/classlib/java/util/TreeMapTest.java @@ -639,4 +639,19 @@ public class TreeMapTest { } return treeMap; } + + @Test + public void deletesProperly() { + TreeMap tm = new TreeMap<>(); + for (int i = 0; i <= 100; ++i) { + tm.put(i, i); + } + for (int i = 0; i <= 100; ++i) { + Integer removed = tm.remove(i); + assertEquals(Integer.valueOf(i), removed); + tm.put(i, i + 1); + assertTrue("13 is expected to be in the map: " + i, tm.containsKey(13)); + assertTrue("99 is expected to be in the map: " + i, tm.containsKey(99)); + } + } }