Add some simple tests on HashPMap
This commit is contained in:
@@ -0,0 +1,22 @@
|
||||
import kotlin.reflect.jvm.internal.pcollections.HashPMap
|
||||
import kotlin.test.*
|
||||
|
||||
fun box(): String {
|
||||
val map = HashPMap.empty<String, Any>()!!
|
||||
|
||||
assertEquals(0, map.size())
|
||||
|
||||
assertFalse(map.containsKey(""))
|
||||
assertFalse(map.containsKey("abacaba"))
|
||||
assertEquals(null, map[""])
|
||||
assertEquals(null, map["lol"])
|
||||
|
||||
// Check that doesn't create a new map
|
||||
assertEquals(map, map.minus(""))
|
||||
|
||||
// Check that all empty()s are equal
|
||||
val other = HashPMap.empty<String, Any>()!!
|
||||
assertEquals(map, other)
|
||||
|
||||
return "OK"
|
||||
}
|
||||
@@ -0,0 +1,47 @@
|
||||
import java.util.*
|
||||
import kotlin.reflect.jvm.internal.pcollections.HashPMap
|
||||
import kotlin.test.*
|
||||
|
||||
fun digitSum(number: Int): Int {
|
||||
var x = number
|
||||
var ans = 0
|
||||
while (x != 0) {
|
||||
ans += x % 10
|
||||
x /= 10
|
||||
}
|
||||
return ans
|
||||
}
|
||||
|
||||
val N = 1000000
|
||||
|
||||
fun box(): String {
|
||||
var map = HashPMap.empty<Int, Any>()!!
|
||||
|
||||
for (x in 1..N) {
|
||||
map = map.plus(x, digitSum(x))!!
|
||||
}
|
||||
|
||||
assertEquals(N, map.size())
|
||||
|
||||
// Check in reverse order just in case
|
||||
for (x in N downTo 1) {
|
||||
assertTrue(map.containsKey(x), "Not found: $x")
|
||||
assertEquals(digitSum(x), map[x], "Incorrect value for $x")
|
||||
}
|
||||
|
||||
// Delete in random order
|
||||
val list = (1..N).toCollection(ArrayList<Int>())
|
||||
Collections.shuffle(list, Random(42))
|
||||
for (x in list) {
|
||||
map = map.minus(x)!!
|
||||
}
|
||||
|
||||
assertEquals(0, map.size())
|
||||
|
||||
for (x in 1..N) {
|
||||
assertFalse(map.containsKey(x), "Incorrectly found: $x")
|
||||
assertEquals(null, map[x], "Incorrectly found value for $x")
|
||||
}
|
||||
|
||||
return "OK"
|
||||
}
|
||||
@@ -0,0 +1,28 @@
|
||||
import kotlin.reflect.jvm.internal.pcollections.HashPMap
|
||||
import kotlin.test.*
|
||||
|
||||
fun box(): String {
|
||||
var map = HashPMap.empty<String, Any>()!!
|
||||
|
||||
map = map.plus("lol", 42)!!
|
||||
map = map.plus("lol", 239)!!
|
||||
|
||||
assertEquals(1, map.size())
|
||||
assertTrue(map.containsKey("lol"))
|
||||
assertFalse(map.containsKey(""))
|
||||
assertEquals(239, map["lol"])
|
||||
assertEquals(null, map[""])
|
||||
|
||||
map = map.plus("", 0)!!
|
||||
map = map.plus("", 2.71828)!!
|
||||
map = map.plus("lol", 42)!!
|
||||
map = map.plus("", 3.14)!!
|
||||
|
||||
assertEquals(2, map.size())
|
||||
assertTrue(map.containsKey("lol"))
|
||||
assertTrue(map.containsKey(""))
|
||||
assertEquals(42, map["lol"])
|
||||
assertEquals(3.14, map[""])
|
||||
|
||||
return "OK"
|
||||
}
|
||||
@@ -0,0 +1,28 @@
|
||||
import kotlin.reflect.jvm.internal.pcollections.HashPMap
|
||||
import kotlin.test.*
|
||||
|
||||
fun box(): String {
|
||||
var map = HashPMap.empty<String, Any>()!!
|
||||
|
||||
map = map.plus("lol", 42)!!
|
||||
map = map.plus("lol", 42)!!
|
||||
|
||||
assertEquals(1, map.size())
|
||||
assertTrue(map.containsKey("lol"))
|
||||
assertFalse(map.containsKey(""))
|
||||
assertEquals(42, map["lol"])
|
||||
assertEquals(null, map[""])
|
||||
|
||||
map = map.plus("", 0)!!
|
||||
map = map.plus("", 0)!!
|
||||
map = map.plus("lol", 42)!!
|
||||
map = map.plus("", 0)!!
|
||||
|
||||
assertEquals(2, map.size())
|
||||
assertTrue(map.containsKey("lol"))
|
||||
assertTrue(map.containsKey(""))
|
||||
assertEquals(42, map["lol"])
|
||||
assertEquals(0, map[""])
|
||||
|
||||
return "OK"
|
||||
}
|
||||
@@ -0,0 +1,24 @@
|
||||
import kotlin.reflect.jvm.internal.pcollections.HashPMap
|
||||
import kotlin.test.*
|
||||
|
||||
fun box(): String {
|
||||
var map = HashPMap.empty<String, Any>()!!
|
||||
|
||||
map = map.plus("lol", 42)!!
|
||||
|
||||
assertEquals(1, map.size())
|
||||
assertTrue(map.containsKey("lol"))
|
||||
assertFalse(map.containsKey(""))
|
||||
assertEquals(42, map["lol"])
|
||||
assertEquals(null, map[""])
|
||||
|
||||
map = map.plus("", 0)!!
|
||||
|
||||
assertEquals(2, map.size())
|
||||
assertTrue(map.containsKey("lol"))
|
||||
assertTrue(map.containsKey(""))
|
||||
assertEquals(42, map["lol"])
|
||||
assertEquals(0, map[""])
|
||||
|
||||
return "OK"
|
||||
}
|
||||
@@ -0,0 +1,23 @@
|
||||
import kotlin.reflect.jvm.internal.pcollections.HashPMap
|
||||
import kotlin.test.*
|
||||
|
||||
fun box(): String {
|
||||
var map = HashPMap.empty<String, Any>()!!
|
||||
|
||||
map = map.plus("lol", 42)!!
|
||||
map = map.minus("lol")!!
|
||||
|
||||
assertEquals(0, map.size())
|
||||
assertFalse(map.containsKey("lol"))
|
||||
assertEquals(null, map["lol"])
|
||||
|
||||
map = map.plus("abc", "a")!!
|
||||
map = map.minus("abc")!!
|
||||
map = map.plus("abc", "d")!!
|
||||
|
||||
assertEquals(1, map.size())
|
||||
assertTrue(map.containsKey("abc"))
|
||||
assertEquals("d", map["abc"])
|
||||
|
||||
return "OK"
|
||||
}
|
||||
+40
-1
@@ -31,7 +31,7 @@ import org.jetbrains.jet.codegen.generated.AbstractBlackBoxCodegenTest;
|
||||
/** This class is generated by {@link org.jetbrains.jet.generators.tests.TestsPackage}. DO NOT MODIFY MANUALLY */
|
||||
@SuppressWarnings("all")
|
||||
@TestMetadata("compiler/testData/codegen/boxWithStdlib")
|
||||
@InnerTestClasses({BlackBoxWithStdlibCodegenTestGenerated.Annotations.class, BlackBoxWithStdlibCodegenTestGenerated.Arrays.class, BlackBoxWithStdlibCodegenTestGenerated.CallableReference.class, BlackBoxWithStdlibCodegenTestGenerated.Casts.class, BlackBoxWithStdlibCodegenTestGenerated.DataClasses.class, BlackBoxWithStdlibCodegenTestGenerated.Evaluate.class, BlackBoxWithStdlibCodegenTestGenerated.FullJdk.class, BlackBoxWithStdlibCodegenTestGenerated.JdkAnnotations.class, BlackBoxWithStdlibCodegenTestGenerated.PlatformNames.class, BlackBoxWithStdlibCodegenTestGenerated.Ranges.class, BlackBoxWithStdlibCodegenTestGenerated.Reflection.class, BlackBoxWithStdlibCodegenTestGenerated.Regressions.class, BlackBoxWithStdlibCodegenTestGenerated.Strings.class, BlackBoxWithStdlibCodegenTestGenerated.ToArray.class, BlackBoxWithStdlibCodegenTestGenerated.Vararg.class, BlackBoxWithStdlibCodegenTestGenerated.When.class})
|
||||
@InnerTestClasses({BlackBoxWithStdlibCodegenTestGenerated.Annotations.class, BlackBoxWithStdlibCodegenTestGenerated.Arrays.class, BlackBoxWithStdlibCodegenTestGenerated.CallableReference.class, BlackBoxWithStdlibCodegenTestGenerated.Casts.class, BlackBoxWithStdlibCodegenTestGenerated.DataClasses.class, BlackBoxWithStdlibCodegenTestGenerated.Evaluate.class, BlackBoxWithStdlibCodegenTestGenerated.FullJdk.class, BlackBoxWithStdlibCodegenTestGenerated.HashPMap.class, BlackBoxWithStdlibCodegenTestGenerated.JdkAnnotations.class, BlackBoxWithStdlibCodegenTestGenerated.PlatformNames.class, BlackBoxWithStdlibCodegenTestGenerated.Ranges.class, BlackBoxWithStdlibCodegenTestGenerated.Reflection.class, BlackBoxWithStdlibCodegenTestGenerated.Regressions.class, BlackBoxWithStdlibCodegenTestGenerated.Strings.class, BlackBoxWithStdlibCodegenTestGenerated.ToArray.class, BlackBoxWithStdlibCodegenTestGenerated.Vararg.class, BlackBoxWithStdlibCodegenTestGenerated.When.class})
|
||||
public class BlackBoxWithStdlibCodegenTestGenerated extends AbstractBlackBoxCodegenTest {
|
||||
public void testAllFilesPresentInBoxWithStdlib() throws Exception {
|
||||
JetTestUtils.assertAllTestsPresentByMetadata(this.getClass(), "org.jetbrains.jet.generators.tests.TestsPackage", new File("compiler/testData/codegen/boxWithStdlib"), Pattern.compile("^(.+)\\.kt$"), true);
|
||||
@@ -954,6 +954,44 @@ public class BlackBoxWithStdlibCodegenTestGenerated extends AbstractBlackBoxCode
|
||||
|
||||
}
|
||||
|
||||
@TestMetadata("compiler/testData/codegen/boxWithStdlib/hashPMap")
|
||||
public static class HashPMap extends AbstractBlackBoxCodegenTest {
|
||||
public void testAllFilesPresentInHashPMap() throws Exception {
|
||||
JetTestUtils.assertAllTestsPresentByMetadata(this.getClass(), "org.jetbrains.jet.generators.tests.TestsPackage", new File("compiler/testData/codegen/boxWithStdlib/hashPMap"), Pattern.compile("^(.+)\\.kt$"), true);
|
||||
}
|
||||
|
||||
@TestMetadata("empty.kt")
|
||||
public void testEmpty() throws Exception {
|
||||
doTestWithStdlib("compiler/testData/codegen/boxWithStdlib/hashPMap/empty.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("manyNumbers.kt")
|
||||
public void testManyNumbers() throws Exception {
|
||||
doTestWithStdlib("compiler/testData/codegen/boxWithStdlib/hashPMap/manyNumbers.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("rewriteWithDifferent.kt")
|
||||
public void testRewriteWithDifferent() throws Exception {
|
||||
doTestWithStdlib("compiler/testData/codegen/boxWithStdlib/hashPMap/rewriteWithDifferent.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("rewriteWithEqual.kt")
|
||||
public void testRewriteWithEqual() throws Exception {
|
||||
doTestWithStdlib("compiler/testData/codegen/boxWithStdlib/hashPMap/rewriteWithEqual.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("simplePlusGet.kt")
|
||||
public void testSimplePlusGet() throws Exception {
|
||||
doTestWithStdlib("compiler/testData/codegen/boxWithStdlib/hashPMap/simplePlusGet.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("simplePlusMinus.kt")
|
||||
public void testSimplePlusMinus() throws Exception {
|
||||
doTestWithStdlib("compiler/testData/codegen/boxWithStdlib/hashPMap/simplePlusMinus.kt");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@TestMetadata("compiler/testData/codegen/boxWithStdlib/jdkAnnotations")
|
||||
public static class JdkAnnotations extends AbstractBlackBoxCodegenTest {
|
||||
public void testAllFilesPresentInJdkAnnotations() throws Exception {
|
||||
@@ -1704,6 +1742,7 @@ public class BlackBoxWithStdlibCodegenTestGenerated extends AbstractBlackBoxCode
|
||||
suite.addTest(DataClasses.innerSuite());
|
||||
suite.addTestSuite(Evaluate.class);
|
||||
suite.addTestSuite(FullJdk.class);
|
||||
suite.addTestSuite(HashPMap.class);
|
||||
suite.addTestSuite(JdkAnnotations.class);
|
||||
suite.addTestSuite(PlatformNames.class);
|
||||
suite.addTest(Ranges.innerSuite());
|
||||
|
||||
Reference in New Issue
Block a user