telefonicaid / iotagent-node-lib

Module to enable IoT Agent developers to build custom agents for their devices that can easily connect to NGSI Context Brokers
https://iotagent-node-lib.rtfd.io/
GNU Affero General Public License v3.0
60 stars 85 forks source link

Add Null expression tests #1471

Closed mapedraza closed 11 months ago

mapedraza commented 11 months ago

https://github.com/telefonicaid/iotagent-node-lib/issues/1440#issuecomment-1736983813

When posting a measure v with value Null to a group with the following attributes:

Expression

            active: [
                {
                    name: 'a',
                    type: 'Number',
                    expression: 'v'
                },
                {
                    name: 'b',
                    type: 'Number',
                    expression: 'v*3'
                },
                {
                    name: 'c',
                    type: 'Boolean',
                    expression: 'v==null'
                },
                {
                    name: 'd',
                    type: 'Text',
                    expression: "v?'no soy null':'soy null'"
                },
                {
                    name: 'e',
                    type: 'Text',
                    expression: "v==null?'soy null':'no soy null'"
                },
                {
                    name: 'f',
                    type: 'Text',
                    expression: "(v*3)==null?'soy null':'no soy null'"
                },
                {
                    name: 'g',
                    type: 'Boolean',
                    expression: 'v == undefined'
                }
            ]

Expectations

                    v: {
                        value: null,
                        type: 'Number'
                    },
                    b: {
                        value: 0,
                        type: 'Number'
                    },
                    c: {
                        value: true,
                        type: 'Boolean'
                    },
                    d: {
                        value: 'soy null',
                        type: 'Text'
                    },
                    e: {
                        value: 'soy null',
                        type: 'Text'
                    },
                    f: {
                        value: 'no soy null',
                        type: 'Text'
                    },
                    g: {
                        value: true,
                        type: 'Boolean'
                    }
mapedraza commented 11 months ago

Pending to validate if expectations are the expected

mapedraza commented 11 months ago

Added more cases after discussing with @mrutid and some other minor fixes

mapedraza commented 11 months ago

Conclusions:

AlvaroVega commented 11 months ago
  • For Null values, is always failing (treating Null as 0)
  • case f ((v*3)==Null?'soy null':'no soy null') is always failing

Then these tests should fails in that expected values? Currently are passing. I mean these tests should check expected values in each case.

mapedraza commented 11 months ago
  • For Null values, is always failing (treating Null as 0)
  • case f ((v*3)==Null?'soy null':'no soy null') is always failing

Then these tests should fails in that expected values? Currently are passing. I mean these tests should check expected values in each case.

Right now, tests are set with the real behaviour. This need to be fixed according the real expected value in a subsequent PR

mapedraza commented 11 months ago

overpassed by https://github.com/telefonicaid/iotagent-node-lib/pull/1474