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

Commit

Permalink
Merge pull request #16 from k163377/fix_codes
Browse files Browse the repository at this point in the history
Fixes.
  • Loading branch information
k163377 authored Jan 2, 2021
2 parents 12e6e29 + c3a262f commit a3204bd
Show file tree
Hide file tree
Showing 6 changed files with 86 additions and 13 deletions.
20 changes: 17 additions & 3 deletions .idea/codeStyles/Project.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion .idea/codeStyles/codeStyleConfig.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions .idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ plugins {
}

group = "com.mapk"
version = "0.1.0"
version = "0.1.2"

repositories {
mavenCentral()
Expand All @@ -24,7 +24,7 @@ dependencies {
}
testImplementation("io.mockk:mockk:1.10.3-jdk8")

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

tasks {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package com.mapk.fastkfunction.argumentbucket

import java.lang.UnsupportedOperationException
import kotlin.reflect.KParameter

class ArgumentBucket(
Expand Down Expand Up @@ -62,13 +61,14 @@ class ArgumentBucket(
}

override val entries: Set<Map.Entry<KParameter, Any?>>
get() = keys.fold(HashSet()) { acc, cur ->
get() = keyList.fold(HashSet()) { acc, cur ->
acc.apply { if (initializationStatuses[cur.index]) add(Entry(cur, valueArray[cur.index])) }
}
override val keys: Set<KParameter>
get() = keys.fold(HashSet()) { acc, cur ->
get() = keyList.fold(HashSet()) { acc, cur ->
acc.apply { if (initializationStatuses[cur.index]) add(cur) }
}
override val size: Int get() = initializationStatuses.count { it }
override val values: Collection<Any?>
get() = valueArray.filterIndexed { idx, _ -> initializationStatuses[idx] }

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

// サイズ系の処理はVALUEパラメータ以外を考慮した際の整合性を考えることが難しく、使う場面も無いためUnsupported
override val size: Int
get() = throw UnsupportedOperationException()
override fun isEmpty(): Boolean = throw UnsupportedOperationException()
override fun isEmpty(): Boolean = size == 0
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.mapk.fastkfunction.argumentbucket

import org.junit.jupiter.api.Assertions.assertEquals
import org.junit.jupiter.api.Assertions.assertFalse
import org.junit.jupiter.api.Assertions.assertNull
import org.junit.jupiter.api.Assertions.assertTrue
import org.junit.jupiter.api.Nested
Expand Down Expand Up @@ -79,4 +80,62 @@ private class ArgumentBucketTest {
}
}
}

@Test
fun entriesTest() {
assertTrue(bucket.entries.isEmpty())

bucket[0] = 0.toShort()
bucket[1] = 1

val entries = bucket.entries.sortedBy { it.key.index }
assertEquals(2, entries.size)
entries.forEach {
assertEquals(it.key.index, (it.value as Number).toInt())
}
}

@Test
fun keysTest() {
assertTrue(bucket.keys.isEmpty())

bucket[0] = 0.toShort()
val result = bucket.keys

assertEquals(1, result.size)
assertEquals(0, result.single().index)
}

@Test
fun valuesTest() {
assertTrue(bucket.isEmpty())

bucket[0] = null
bucket[1] = 100
val result = bucket.values

assertTrue(result.contains(null))
assertTrue(result.contains(100))
}

@Test
fun containsValueTest() {
assertFalse(bucket.containsValue(null))
assertFalse(bucket.containsValue(100))

bucket[0] = null
bucket[1] = 100

assertTrue(bucket.containsValue(null))
assertTrue(bucket.containsValue(100))
}

@Test
fun isEmptyTest() {
assertTrue(bucket.isEmpty())

bucket[0] = 0.toShort()

assertFalse(bucket.isEmpty())
}
}

0 comments on commit a3204bd

Please sign in to comment.