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

Publicapi coverage #252

Merged
merged 12 commits into from
Apr 26, 2017
Merged

Publicapi coverage #252

merged 12 commits into from
Apr 26, 2017

Conversation

rajsite
Copy link
Member

@rajsite rajsite commented Apr 25, 2017

  • Lots of JS tests for readJSON and writeJSON
  • Modified TDViaParser to support quoteInfNan to be symmetrical with TDViaFormatter
  • Added default print and printError behaviors (can still be overwritten with vireo.eggShell.setPrintFunction and vireo.eggShell.setPrintErrorFunction)

Copy link
Contributor

@spathiwa spathiwa left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Vireo side changes seem good.
I did not look closely at the JS tests, but I just want to say I think it's weird that all the Karma tests have explicit code (expect ...) to compare test results rather than a 'vtr' like file and generic results tester.

@rajsite
Copy link
Member Author

rajsite commented Apr 25, 2017

Yea that would be valuable if we want to validate more environments like C++, Python, LabVIEW, etc are consuming the EggShell_ReadJSON and EggShell_WriteJSON apis correctly.

Seems like each environment may still want a known in memory representation against ie a LabVIEW cluster, a C++ struct, etc.

Maybe there is a good approach that doesn't require encoding the result in per platform representation:

  1. call EggShell_ReadJSON put it through your platform JSON parser
  2. read the results file, put it through your platform JSON parser
  3. recursively compare every field and ensure equality

This means the JSON parser needs to create a dynamic structure that can be reflected on, couldn't use a static one like LV without VI scripting or creating the in memory representation of the tests (ruining the whole point of separating the results).

The Write JSON tests are also more involved. They currently read to validate the intial value. Write a new value. Read the new value to validate the new value. Then rewrite the old value and revalidate reading the old value. The Write JSON test is then repeated for different values compared to the original value (ie with larger arrays or smaller arrays).

I think you propose an interesting idea but need to experiment more with what would make a valuable generic tester for the api. Might want it to cover less (not having tests for different array write sizes) or maybe even have more tests.

Something to keep in mind for the future, especially if we want to test those APIs in more language environments.

@rajsite
Copy link
Member Author

rajsite commented Apr 25, 2017

Updated the tests to pass in PhatomJS 👍

@cglzaguilar
Copy link
Contributor

@sanmut do you have any comments on this changeset?

Copy link
Contributor

@sanmut sanmut left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good job. Extensive test coverage !!!
Ok to submit after addressing feedback.
Do you have work items created to track the open issues listed here?

@@ -84,13 +89,29 @@
return result;
}
};
},
toMatchIEEE754Number: function (util, customEqualityTesters) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is labeled function declaration allowed in 'strict' mode in all browser environments? Is there a different way to do this without labeled function declaration?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is not a function declaration, this is a function expression.

function declaration:

(function () {

    function mydeclaredFunction() {
    };

}());

function expression assigned to var:

(function () {

    var myFunctionExpression = function () {
    };

}()))
;

function expression assigned to property of object:

(function () {

    var myObj = {
        myFunctionExpression: function () {
        }
    };

}());

Is labeled function declaration allowed in 'strict' mode in all browser environments?

ECMAScript permits function statements in exactly two places: directly within the list of statements that make up a program, and directly within the list of statements that make up the contents of a function body

Is there a different way to do this without labeled function declaration?

This is not a function declaration / function statement. But I agree that if it was, we shouldn't use that form.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

oh cool, thanks for the explanation.

expect(viaAbsolutePath).toBeNonEmptyString();
// Jasmine Matchers library is not always ready in beforeAll so use jasmine core functions
expect(typeof viaAbsolutePath).toBe('string');
expect(viaAbsolutePath).not.toBe('');
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is doing toBeNonEmptyString() preferred way?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What is your concern?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In our JS tests, we are using toBeNonEmptyString and toBeEmptyString and I thought that was the convention we wanted to follow !!??

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We want to use the most precise test we can. Some possibilities for this check from least specific to most specific:
isDefined
isString
isNonEmptyString
toMatch(/regexp/)
toEqual
toBe

In places where we can validate the exact string like the statusText is "OK" for HTTP that is as specific as we can get.
The cookies we know a subset match the cookie string.
The paths can be anything besides a non-empty string. We could maybe use (/.via/i) or something but that's unnecessarily strict.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh. I misunderstood.

If you read the comment it says jasmine matchers are not available yet. So we can't use toBeNonEmptyString in this file

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That is a bug in the jasmine matchers library that provides all those extra function on top of jasmine's standard matchers. So far it only effects utility files like this, it has not been a problem in the test suites yet.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ah, I missed the comment just above :-( . never mind.

@@ -0,0 +1,90 @@
// Autogenerated Vireo assembly file
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are you planning to check the GVI test also in after this?

Copy link
Member Author

@rajsite rajsite Apr 26, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Leftover comment, this was a heavily hand modified file. I can remove the comment

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My question was not about that. I was wondering whether you were planning to checkin GVI tests along with the other existing GVI tests after this goes in on the Vireo side?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Carlos has done that as a separate task for the user story

var vireo;

var testsArrayDemoViaUrl = fixtures.convertToAbsoluteFromViaTestsDir('ArrayDemo.via');
var publicApiArrayTypesOptimizedViaUrl = fixtures.convertToAbsoluteFromFixturesDir('publicapi/ArrayTypesOptimized.via');
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not used in any test in this file. remove?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

it('Double', function () {
var actualJSON = vireo.eggShell.readJSON(viName, 'dataItem_NumericDouble');
var actual = JSON.parse(actualJSON);
expect(actual).toBe(123.456);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like this type of checking prone to failures since we are expecting the exact value and not doing something equivalent to an epsilon comparison (http://www.ni.com/white-paper/7612/en/ ). Am I missing something?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This isn't the result of a mathematical operation. We are writing an IEEE754 value to memory and reading it back. We should expect exact representation serializing IEEE754 values in and out.

compare: function (actual, expected) {
var result = {};
if (typeof actual === 'number' && typeof expected === 'number') {
result.pass = Object.is(actual, expected);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does "Object.is" expect the exact same value for floating point numbers? If so, we should use that only for special floating point numbers (such as NaN, Inf, +0, etc) and then use some epsilon comparison for regular floating point numbers. I wonder if we can use toBeCloseTo matcher in Jasmine?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These tests are validating exact representations of values can be serialized and deserialized from Vireo memory. We should not be using epsilons for comparisons during these tests.

@rajsite
Copy link
Member Author

rajsite commented Apr 26, 2017

Do you have work items created to track the open issues listed here?

You can see above that issue #254 was created to track Craig's suggestion. Did any others need to be made?

@rajsite rajsite requested a review from sanmut April 26, 2017 19:37
@rajsite
Copy link
Member Author

rajsite commented Apr 26, 2017

There was a lot of discussion so asking for re-review from @sanmut to make sure all concerns were addressed

@rajsite rajsite merged commit d8ab19d into ni:incoming Apr 26, 2017
@rajsite rajsite deleted the publicapi-coverage branch April 26, 2017 21:00
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