Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

"at least one operator should not be static" not triggered for 2 static arrays #17

Open
matthiaskrgr opened this issue Sep 5, 2019 · 7 comments
Labels
bug Something isn't working OV-lang concerns the openVALIDATION language

Comments

@matthiaskrgr
Copy link
Member

Usually a rule like 1 has to be 1 triggers an error on the playground "at least one operator should not be static" however this is not the case for two equal arrays:
The validation rule 0,0 has to be 0,0 generates the code

huml.appendRule("",
    new String[]{  },
    "0,0 has to be 0,0",
    ( model) -> huml.NONE_OF("0","0", "0","0"),
    false
)

Is this a bug?

@matthiaskrgr matthiaskrgr added question Further information is requested OV-lang concerns the openVALIDATION language labels Sep 5, 2019
@jages
Copy link
Contributor

jages commented Sep 5, 2019

good catch. The generated Code isn't actually correct either, as huml.NONE_OF(T left, T... right) will now treat one of the left arrays members as members of the right array.

@matthiaskrgr matthiaskrgr removed the question Further information is requested label Sep 5, 2019
@jages jages added the bug Something isn't working label Sep 5, 2019
@lionelpa
Copy link
Contributor

Another question would be how equality of Arrays should be handled in general.
Should we even allow validating equality of Arrays? And if so, do we consider the order of the elements?
E.g. is 1,2,3 equal to 3,2,1?

@matthiaskrgr
Copy link
Member Author

I would say two arrays are equal if they have the same length and the same elements in the same order.

@lionelpa
Copy link
Contributor

Ofc, as a programmer, it is easy to decide when two arrays are equal. However the user of our software may not be a programmer. Maybe for him/her arrays are simply lists and as long as they contain the same items, theyre the same.

I think we have to keep in mind here, who will eventually be writing the rules. A possible solution would be more expressive, arrays specific operators like "same order" and "same content"

@jages
Copy link
Contributor

jages commented Sep 24, 2019

Agreeing with @matthiaskrgr here. The functionality should work as similar as possible to a standart library. i tend to lean more towards the java approch of checking the arrays contents, than the c# approch of checking for pointer equality.

see references:
java Arrays.Equals
csharp Object.Equals as implemented in ArrayList

@jages
Copy link
Contributor

jages commented Jan 31, 2020

@lionelpa this is still an issue. candidate for 0.0.5 ?

@thecodemonkey
Copy link
Contributor

This example confuses me somewhat. I see several problems at this point.

  1. currently it is the case that both the "1 has to be 1" and "1.0 has to be 1.0" throw a corresponding error. So it works as desired.

  2. 1.0 is currently recognized as a decimal number while 1,0 is recognized as an array of strings. This is not quite correct. We will have to see how to deal with this in the future.

  3. speaking of comparing arrays. Then this is not about comparing the individual array items. It is still about comparing static or non-static values within a condition. That means even if the two arrays Static are usually entered and have different items, they are still 2 static arrays. One of them must be defined by at least one variable or attribute of the schema, otherwise the rule will always return the same result. And that would be wrong behaviour.


First we have to make sure that we always throw a corresponding error if a condition contains 2 static elements. No matter what type they are.

Then we have to take care in a separate issue that the numbers 1,1 are also recognized as decimal numbers.

And then we have to see, if we want to compare 2 arrays with each other, that we provide a function for that. And if then we want to compare the contents of the arrays. But at this point there are many different comparison variations.

In any case we should treat the individual points in separate issues.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working OV-lang concerns the openVALIDATION language
Projects
None yet
Development

No branches or pull requests

4 participants