Skip to content

Commit

Permalink
Handle long values for double type
Browse files Browse the repository at this point in the history
  • Loading branch information
manojlds committed Dec 10, 2019
1 parent 8540820 commit f1ea98d
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,10 @@ data class Parameter(val name: String, val type: ParameterType, val possibleValu
}

fun valueFrom(facts: Map<String, Any>): Any {
return type.type.javaObjectType.cast(facts[name])
val factValue = facts[name]
return when {
factValue is Long && type == ParameterType.DoubleType -> factValue.toDouble()
else -> type.type.javaObjectType.cast(factValue)
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -96,21 +96,21 @@ class ThePillProcedureLeafEntityTest {
"" +
"CREATE (tree:Tree { name: 'neo' })" +
"CREATE (pill: Decision { name: 'Red Pill Or Blue Pill', question: 'Red Pill Or Blue Pill'," +
"parameters:'[{\"name\": \"param1\", \"type\": \"string\"}, {\"name\": \"param2\", \"type\": \"integer\"}, {\"name\": \"param3\", \"type\": \"float\"}]', choice: 'result = {relationship: \"COLOR\", properties: {\"parameter\": param1 + param2 + param3}};' })" +
"parameters:'[{\"name\": \"param1\", \"type\": \"string\"}, {\"name\": \"param2\", \"type\": \"integer\"}, {\"name\": \"param3\", \"type\": \"float\"}, {\"name\": \"param4\", \"type\": \"double\"}]', choice: 'result = {relationship: \"COLOR\", properties: {\"parameter\": param1 + param2 + param3 + param4}};' })" +
"CREATE (red:Leaf { value: 'knowledge' })" +
"CREATE (blue:Leaf { value: 'ignorance' })" +
"CREATE (tree)-[:HAS]->(pill)" +
"CREATE (pill)-[:COLOR {parameter: \"param123\"}]->(red)" +
"CREATE (pill)-[:COLOR {parameter: \"param321\"}]->(blue)"
"CREATE (pill)-[:COLOR {parameter: \"param1234\"}]->(red)" +
"CREATE (pill)-[:COLOR {parameter: \"param4321\"}]->(blue)"

)

val resultFromTree = session.run("CALL com.stacktoheap.thepill.make_decision('neo', {param1: 'param1', param2: 2, param3: 3.0}) yield path return last(nodes(path))")
val resultFromTree = session.run("CALL com.stacktoheap.thepill.make_decision('neo', {param1: 'param1', param2: 2, param3: 3.0, param4: 4}) yield path return last(nodes(path))")
.single().get(0) as NodeValue

assertTrue(resultFromTree.get("value").asString() == "knowledge")

val resultFromDecision = session.run("CALL com.stacktoheap.thepill.make_decision('Red Pill Or Blue Pill', {param1: 'param1', param2: 2, param3: 3.0}) yield path return last(nodes(path))")
val resultFromDecision = session.run("CALL com.stacktoheap.thepill.make_decision('Red Pill Or Blue Pill', {param1: 'param1', param2: 2, param3: 3.0, param4: 4}) yield path return last(nodes(path))")
.single().get(0) as NodeValue

assertTrue(resultFromDecision.get("value").asString() == "knowledge")
Expand Down

0 comments on commit f1ea98d

Please sign in to comment.