jamsesso / json-logic-java

A pure Java implementation of JsonLogic without using the Nashorn JS engine
MIT License
97 stars 50 forks source link

Divide operator does not deliver expected result when applied on one value only #11

Closed patmonfort closed 5 years ago

patmonfort commented 5 years ago

Hello, Trying the following rule {"/":[8]} returns null on standard JSON logic (http://jsonlogic.com/play.html) but does return the value itself using the lib. (v1.0.2). Can you please check the 'evaluate' method of "MathExpression" and considering a special case for the '/' operator when the array of arguments contains one element? Or maybe this one is a fix to be provided in json logic 'official' js lib itself.

jamsesso commented 5 years ago

@patmonfort thanks for helping me find some inconsistencies between the Javascript implementation and this one - can you create a list of everything you find instead of creating one-off issues? I will fix them all as part of a single PR.

patmonfort commented 5 years ago

@jamsesso Hello, of course, please find the list below. The lib is very helpfull, thanks for this job. Let me know if you need additional information.

jamsesso commented 5 years ago

Thanks @patmonfort. I'll take a look at these issues. Your last point about conversion to Double is done by design. In Javascript there are no integers, so this library attempts to convert all Integer inputs to Doubles to mimmic that behaviour. Without it, other bugs pop up.

patmonfort commented 5 years ago

Hello @jamsesso , this work is very appreciated, thanks for this development. That's understood for the issue around number/interger/double. I'll check when updates are available, let me know if you think I could help.

jamsesso commented 5 years ago

@patmonfort I've updated the PR - can you verify?

patmonfort commented 5 years ago

@jamsesso hello, that's perfect, many thanks.