Skip to content
This repository was archived by the owner on Jan 20, 2023. It is now read-only.

Commit a3204bd

Browse files
authored
Merge pull request #16 from k163377/fix_codes
Fixes.
2 parents 12e6e29 + c3a262f commit a3204bd

File tree

6 files changed

+86
-13
lines changed

6 files changed

+86
-13
lines changed

.idea/codeStyles/Project.xml

+17-3
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/codeStyles/codeStyleConfig.xml

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/misc.xml

+3
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

build.gradle.kts

+2-2
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ plugins {
88
}
99

1010
group = "com.mapk"
11-
version = "0.1.0"
11+
version = "0.1.2"
1212

1313
repositories {
1414
mavenCentral()
@@ -24,7 +24,7 @@ dependencies {
2424
}
2525
testImplementation("io.mockk:mockk:1.10.3-jdk8")
2626

27-
implementation(group = "org.openjdk.jmh", name = "jmh-core", version = "1.26")
27+
jmhImplementation(group = "org.openjdk.jmh", name = "jmh-core", version = "1.26")
2828
}
2929

3030
tasks {

src/main/kotlin/com/mapk/fastkfunction/argumentbucket/ArgumentBucket.kt

+4-7
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
package com.mapk.fastkfunction.argumentbucket
22

3-
import java.lang.UnsupportedOperationException
43
import kotlin.reflect.KParameter
54

65
class ArgumentBucket(
@@ -62,13 +61,14 @@ class ArgumentBucket(
6261
}
6362

6463
override val entries: Set<Map.Entry<KParameter, Any?>>
65-
get() = keys.fold(HashSet()) { acc, cur ->
64+
get() = keyList.fold(HashSet()) { acc, cur ->
6665
acc.apply { if (initializationStatuses[cur.index]) add(Entry(cur, valueArray[cur.index])) }
6766
}
6867
override val keys: Set<KParameter>
69-
get() = keys.fold(HashSet()) { acc, cur ->
68+
get() = keyList.fold(HashSet()) { acc, cur ->
7069
acc.apply { if (initializationStatuses[cur.index]) add(cur) }
7170
}
71+
override val size: Int get() = initializationStatuses.count { it }
7272
override val values: Collection<Any?>
7373
get() = valueArray.filterIndexed { idx, _ -> initializationStatuses[idx] }
7474

@@ -82,8 +82,5 @@ class ArgumentBucket(
8282
override fun get(key: KParameter): Any? = valueArray[key.index]
8383
operator fun get(index: Int): Any? = valueArray[index]
8484

85-
// サイズ系の処理はVALUEパラメータ以外を考慮した際の整合性を考えることが難しく、使う場面も無いためUnsupported
86-
override val size: Int
87-
get() = throw UnsupportedOperationException()
88-
override fun isEmpty(): Boolean = throw UnsupportedOperationException()
85+
override fun isEmpty(): Boolean = size == 0
8986
}

src/test/kotlin/com/mapk/fastkfunction/argumentbucket/ArgumentBucketTest.kt

+59
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package com.mapk.fastkfunction.argumentbucket
22

33
import org.junit.jupiter.api.Assertions.assertEquals
4+
import org.junit.jupiter.api.Assertions.assertFalse
45
import org.junit.jupiter.api.Assertions.assertNull
56
import org.junit.jupiter.api.Assertions.assertTrue
67
import org.junit.jupiter.api.Nested
@@ -79,4 +80,62 @@ private class ArgumentBucketTest {
7980
}
8081
}
8182
}
83+
84+
@Test
85+
fun entriesTest() {
86+
assertTrue(bucket.entries.isEmpty())
87+
88+
bucket[0] = 0.toShort()
89+
bucket[1] = 1
90+
91+
val entries = bucket.entries.sortedBy { it.key.index }
92+
assertEquals(2, entries.size)
93+
entries.forEach {
94+
assertEquals(it.key.index, (it.value as Number).toInt())
95+
}
96+
}
97+
98+
@Test
99+
fun keysTest() {
100+
assertTrue(bucket.keys.isEmpty())
101+
102+
bucket[0] = 0.toShort()
103+
val result = bucket.keys
104+
105+
assertEquals(1, result.size)
106+
assertEquals(0, result.single().index)
107+
}
108+
109+
@Test
110+
fun valuesTest() {
111+
assertTrue(bucket.isEmpty())
112+
113+
bucket[0] = null
114+
bucket[1] = 100
115+
val result = bucket.values
116+
117+
assertTrue(result.contains(null))
118+
assertTrue(result.contains(100))
119+
}
120+
121+
@Test
122+
fun containsValueTest() {
123+
assertFalse(bucket.containsValue(null))
124+
assertFalse(bucket.containsValue(100))
125+
126+
bucket[0] = null
127+
bucket[1] = 100
128+
129+
assertTrue(bucket.containsValue(null))
130+
assertTrue(bucket.containsValue(100))
131+
}
132+
133+
@Test
134+
fun isEmptyTest() {
135+
assertTrue(bucket.isEmpty())
136+
137+
bucket[0] = 0.toShort()
138+
139+
assertFalse(bucket.isEmpty())
140+
}
82141
}

0 commit comments

Comments
 (0)