File tree Expand file tree Collapse file tree
kotlin/xyz/javecs/tools/text2expr
test/kotlin/xyz/javecs/tools/text2expr/test/kotlin/speed Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -16,7 +16,7 @@ plugins {
1616}
1717
1818group ' xyz.javecs.tools'
19- version ' 0.0.9 '
19+ version ' 0.0.10 '
2020
2121apply plugin : ' kotlin'
2222apply plugin : ' antlr'
Original file line number Diff line number Diff 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 }
Original file line number Diff line number Diff line change 1+ SF:時速
2+ x=P2:数
3+ SF:キロメートル|キロ|"km"
4+ y=P2:数
5+ SF:秒間
6+ SF:メートル|"m"
7+
8+ (x * 1000 / 3600) * y
Original file line number Diff line number Diff line change 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+ }
You can’t perform that action at this time.
0 commit comments