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

DMN 1.4 - 1145-feel-context-function #596

Merged
merged 2 commits into from
Oct 19, 2023

Conversation

StrayAlien
Copy link
Contributor

No description provided.

@opatrascoiu
Copy link
Contributor

opatrascoiu commented Jun 27, 2023

@StrayAlien Thank you again!

I would use xsd:decimal instead of xsd:double in the test files xsd:decimal as is a better mapping for the number type in FEEL.

I think we should add extra tests to check the type of the value returned by context(). For example:

    <itemDefinition name="exactContextType" label="ExactContextType" id="_exactContextType">
        <itemComponent name="a" id="_a">
            <typeRef>number</typeRef>
        </itemComponent>
        <itemComponent name="b" id="_b">
            <typeRef>number</typeRef>
        </itemComponent>
    </itemDefinition>

    <itemDefinition name="superContextType" label="SuperContextType" id="_superContextType">
        <itemComponent name="a" id="_a">
            <typeRef>number</typeRef>
        </itemComponent>
    </itemDefinition>

    <itemDefinition name="otherContextType" label="OtherContextType" id="_otherContextType">
        <itemComponent name="a" id="_a">
            <typeRef>number</typeRef>
        </itemComponent>
        <itemComponent name="b" id="_b">
            <typeRef>number</typeRef>
        </itemComponent>
        <itemComponent name="c" id="_c">
            <typeRef>number</typeRef>
        </itemComponent>
    </itemDefinition>

    <decision name="decision018" id="_decision018">
        <variable name="decision018" typeRef="exactContextType"/>
        <literalExpression>
            <text>context(entries: [{key:"a", value:1}, {key:"b", value:2}])</text>
        </literalExpression>
    </decision>

    <decision name="decision019" id="_decision019">
        <variable name="decision019" typeRef="superContextType"/>
        <literalExpression>
            <text>context(entries: [{key:"a", value:1}, {key:"b", value:2}])</text>
        </literalExpression>
    </decision>

    <decision name="decision020" id="_decision020">
        <variable name="decision020" typeRef="otherContextType"/>
        <literalExpression>
            <text>context(entries: [{key:"a", value:1}, {key:"b", value:2}])</text>
        </literalExpression>
    </decision>

with expected results:

    <testCase id="018">
        <description>Value of context() equivalentTo the decision typeRef</description>
        <resultNode name="decision018" type="decision">
                <expected>
                    <component name="a">
                        <value xsi:type="xsd:decimal">1</value>
                    </component>
                    <component name="b">
                        <value xsi:type="xsd:decimal">2</value>
                    </component>
                </expected>
        </resultNode>
    </testCase>

    <testCase id="019">
        <description>Value of context() conformsTo the decision typeRef</description>
        <resultNode name="decision019" type="decision">
                <expected>
                    <component name="a">
                        <value xsi:type="xsd:decimal">1</value>
                    </component>
                    <component name="b">
                        <value xsi:type="xsd:decimal">2</value>
                    </component>
                </expected>
        </resultNode>
    </testCase>

    <testCase id="020">
        <description>Value of context() does not conformsTo the decision typeRef</description>
        <resultNode name="decision020" type="decision">
                <expected>
                    <value xsi:nil="true"/>
                </expected>
        </resultNode>
    </testCase>


We should probably discuss the expected values, value produces by context() or coversion to expected type ( e.g. add only members in super type) :)

@StrayAlien
Copy link
Contributor Author

thanks @opatrascoiu - re 'double' oh yes, for sure. Apologies - that is an oversight. Good pickup. I'll amend.

Re the type checking - the context() function is not intrinsically typed, and we do have other tests for checking on context types, so my feeling here was just to prove it creates the desired contexts and leave the type checking to those other tests. Happy to discuss.

@StrayAlien
Copy link
Contributor Author

StrayAlien commented Jun 29, 2023

doubles change to decimal on this PR, and the others with the same thing. Thanks again - nice pickup @opatrascoiu .

@StrayAlien
Copy link
Contributor Author

Also, I see the TCK validation fails with Cannot find the declaration of element 'definitions'. .. not sure what is going on there ...

@opatrascoiu
Copy link
Contributor

@StrayAlien
I believe the context() functions are typed - just like all the other builtin functions. The tests in this PR cover only the inputs. We need tests to cover the outputs as well for integration with other parts of the model.

These functions are new, we need to add these tests either here, in this file, or somewhere else to have the coverage.

Is there an existing test case that you have in mind that can be enhanced ? Adding the tests here will align us with the localization principle.

@StrayAlien
Copy link
Contributor Author

StrayAlien commented Jul 4, 2023

Hi @opatrascoiu , thanks. The examples provided show type constraints at the decision/variable level, but (IMO) that is unrelated to asserting results of context function itself. The context() function just produces a context object based on inputs, so we can simply assert that it produces the output context we expect based on the inputs provided. No types are necessary to prove that context() is working as expected IMO. Types are orthogonal.

The test are asserting on an exact outcome. So, testing for the type of the outcome gains no value. If the exact expected outcome is not delivered then the type is moot.

I think we already have context types covered at the decision/variable level. Likely, also in the as-yet-ummerged PR for domain constraints. I'll have a dig to see if we have. If not, we can add context type checking to some type-specific tests (again, IMO).

@opatrascoiu
Copy link
Contributor

opatrascoiu commented Jul 12, 2023

@StrayAlien I am inclined to agree with you about the location. A good place is to have them in 0082-feel-coersion. Comments, thoughts?

Once we agree on the location, I'll create a PR.

@StrayAlien
Copy link
Contributor Author

Apols for late reply @opatrascoiu - we dp have a few tests fr context types here: https://github.com/dmn-tck/tck/blob/master/TestCases/compliance-level-3/0070-feel-instance-of/0070-feel-instance-of-test-01.xml#L1207. And there are also some more in the 'allow values' PR, butm yes, we're a bit light - expecially around whern they're associated with a decision variable I think.

Let's discuss tonight at the DMN meeting.

@SimonRinguette
Copy link
Contributor

I would argue that the test case 003 would not return null but the intention was to return only {a: 2}.

We can discuss that one!

@opatrascoiu
Copy link
Contributor

According to 10.3.2.6 Context,

In the syntax, keys can be either names or strings. Keys are mapped to strings in the semantic domain.These strings are distinct within a context.

Based on this I think the test is correct.

@SimonRinguette
Copy link
Contributor

@opatrascoiu All right, make sense to keep the test then.

@baldimir baldimir merged commit 49e6b97 into dmn-tck:master Oct 19, 2023
2 of 5 checks passed
opatrascoiu pushed a commit to opatrascoiu/tck that referenced this pull request Oct 30, 2023
* 1145-feel-context-function

* replace xsd:double with xsd:decimal
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants