Skip to content

Commit cc5e4e8

Browse files
authored
Merge pull request #28 from javecs/feature/speed
時速を秒間の速度に変換しました。
2 parents 3763ca5 + 85f27a8 commit cc5e4e8

4 files changed

Lines changed: 28 additions & 7 deletions

File tree

build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ plugins {
1616
}
1717

1818
group 'xyz.javecs.tools'
19-
version '0.0.9'
19+
version '0.0.10'
2020

2121
apply plugin: 'kotlin'
2222
apply plugin: 'antlr'

src/main/kotlin/xyz/javecs/tools/text2expr/Text2Expr.kt

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,16 +11,14 @@ class Text2Expr(rulePath: String = "rules") {
1111
private val calc = Calculator()
1212

1313
init {
14-
resources(rulePath).forEach{ rules.add(RuleBuilder(read(it))) }
14+
resources(rulePath).forEach { rules.add(RuleBuilder(read(it))) }
1515
}
1616

1717
fun eval(text: String): String {
18-
for (rule in rules) {
18+
rules.forEach {
1919
try {
20-
val evaluation = rule.eval(text)
21-
if (evaluation.value != Double.NaN) {
22-
return evaluation.value.toString()
23-
}
20+
val evaluation = it.eval(text)
21+
if (evaluation.value != Double.NaN) return evaluation.value.toString()
2422
} catch (e: Exception) {
2523
}
2624
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
SF:時速
2+
x=P2:数
3+
SF:キロメートル|キロ|"km"
4+
y=P2:数
5+
SF:秒間
6+
SF:メートル|"m"
7+
8+
(x * 1000 / 3600) * y
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
package xyz.javecs.tools.text2expr.test.kotlin.unit
2+
3+
import org.junit.Test
4+
import xyz.javecs.tools.text2expr.Text2Expr
5+
import kotlin.test.assertEquals
6+
7+
class SpeedTest {
8+
9+
val text2Expr = Text2Expr()
10+
11+
@Test fun kilometerPerHourToMeterPerSecond() {
12+
assertEquals("30.555555555555557", text2Expr.eval("時速110キロの車は1秒間に何メートル進みますか?"))
13+
}
14+
15+
}

0 commit comments

Comments
 (0)